New toy: ESP8266

I’ve long had both our solar inverters on the network (it’s not really fair to say they’re on the internet anymore, I took care of that), so I can monitor them. The growatt one has no ethernet or wifi connectivity, it only has a DE-9 serial port that I poll from a PC Engines APU with a shitty python script. The problem with that is that the APU that does it is also my time server, and the ~2M of serial cable doesn’t quite reach a convenient location for both.

So I came up with the idea of using an ESP8266 (in retrospect I should have gone with the ESP32, but the former was what they had locally) to poll it, and just dump everything directly to collectd. I figured I may be able to have just a teeny tiny board hanging out the bottom of it, with a power connector and nothing else. Plus it’s a good excuse to get back into microcontroller development!

So I bought a “keyestudio” KS5014 board, for a princely A$60-odd because it was all they had locally and I’m impatient. It turns out this board’s actually kind-of a piece of shit… it’s an ESP8266 and some sort of AtMega AVR in one, but I had numerous issues with it. First of all, you have to throw multiple tiny DIP switches (small enough that you need a ballpoint pen to do it) to program it, and throw them back to run your code. Second, the documentation’s dreadful. Third, the “alternate” UART pins aren’t connected, despite it having nearly sixty pins exposed from both microcontrollers. Finally, I had dreadful trouble getting it to reliably connect to wifi, I was thinking that there was something wrong with my code, but it turns out that after following a discussion thread with a different board, reducing the maximum transmit power for the wifi actually makes it rock-solid. Darius on IRC theorized that maybe the power supply circuit sucks and can’t maintain power when it’s cranked? No idea.

Anyway, after some fucking around, I got it all working. I swiped someone else’s collectd protocol code (that I’ll probably clean up, maybe rewrite, not sure yet), pieced together a bunch of example code, and then on the APU I wrote some C code to decode the inverter protocol, along with a ring buffer so that I can have one loop reading from the serial port and another consuming the buffer so that I hopefully don’t drop any packets.

I’m reasonably confident it works - I had it hooked up to my laptop and used socat to pipe the serial data across from the APU and it functions perfectly, but I don’t have a spare DB-9 plug to connect it up and test it. I’ll probably order one, a MAX3232, and some components to feed it all, and might even get crazy and get a PCB made for it, not sure yet.

I also ordered some nodemcu boards, which work a lot better than the Jaycar special, and for about 1/10th of the price!

Horsham, VIC, Australia fwaggle



Filed under:


Horsham, VIC, Australia

Navigation: Older Entry Newer Entry