Prototype wrapup #27

Last week I posted the first half of my prototypes for Real life vs Internet, and this is the second half. Most of the fiddly part was last week, this week was mainly minor adjustments and some utility stuff as the project went on. The notable exception is the final web interface, which ended up pretty substantial bit of work. Although the individual parts are here and in the last prototype wrapup, you can also find the whole thing in its own repo.

Monday

I eventually realised that it was way more fun watching the display update in real time, but to do that I needed to move to websockets. This was a rewrite of the code for the ESP chip handling the network communication for the Arduino. I was initially devastated to realise that NodeMCU doesn't support websockets, until I remembered that I could just use, y'know, regular sockets. This was actually much neater than the previous code, and I felt like Lua kinda came into its own in this part. Handling reconnections and all the messages flying around from Arduino/C++ code probably would have been a bit more cumbersome.

Tuesday

This was the final version of the client and server code. A lot of different stuff went into this, including websocket support rather than polling, a pretty graphical cooldown on the button, and a sweet 7-segment font. The one thing that's kind of unfortunate is that because it evolved from polling to websocket based code, it ended up a bit spaghetti-ish. By the end I was dealing with 5 different kinds of connection: database, polling web clients, websocket clients, the raw socket for the display, and the polling for the display (still left as a backup). Would have been nice to find a way to neaten that all up, but that's weekend projects for you.

Thursday

This last bit was pretty simple. At the end I wanted to pull the raw data for each hour out of redis before I took the server down, so I figured a CSV file would be a good option. I threw together a little Coffeescript thing to generate it, and committed the CSV data as well in case that's useful for some reason.