Sofar HYD6000-ES Inverter RS485 data logger

As noted in an earlier blog entry, a friend of mine has acquired a Sofar HYD6000-ES inverter as part of a mighty 8kW PV array. He is currently using the dodgy Solarman cloud software to monitor it, using the pretty standard LSW-3 wireless stick that actually uses RS485 under the covers, and sending data to the fixed address stashed within. However, it doesn't appear to be monitoring the batteries at all, so in an effort to enable this, I've been looking at alternatives.

This helpful Github site has a great description of an RS485-attached device, based on an ESP8266. This sends regular data updates out on MQTT over the local WiFi, accessing the inverter's internal registers via ModBus. I've purchased the components, and am starting to mess with software, using the Arduino IDE configured for ESP8266 Wemos D1 mini.

I have the basic Sofar2MQTT sketch running, although since I lack the RS485 adaptor at this point I don't know if that works. At least the sketch runs! I have yet to attach the OLED display, but that will happen shortly. One of the drawbacks is that this sketch has a hard-coded set of WiFi and MQTT parameters, and I was interested in making this more easily configurable. Hence...

I've found a library WiFiManager, which is a wrapper around the standard WiFiClient class. This checks internal storage for saved SSID/pwd values, and if there are none, it launches the Access Point, and puts up a web page allowing them to be entered. You connect to the AP, enter the values you want, and then it reconfigures itself as a STA, using the values, and stores them in NVS. Great! However, I've been using a WiFiManager + MQTT example, as a base for finding out how this works and testing it. I got it running, but it's taken a while! 

  • It saves the MQTT parameters separately in the FS interface to the NVRam, in JSON format
  • It used ArduinoJson 5, which is now not compatible, so I had to modify it to use v6
  • Doing that completely broke the MQTTClient configuration, because accessing the JSON document in v6 didn't play with the strcpy operation used to retrieve the values
    • This was partly because the author had used #define to specify the default values for SSID etc, probably copied from somewhere, and this meant that there wasn't any actual storage for dynamically configured set of values! 
    • So I got lots of errors...
    • Which I fixed!
  • Then it got confused about when the new/configured values should be set up before being loaded into the MQTTClient...
  • Which meant I completely reordered the code, so that WifiManager's "had to set the new config" callback set a flag which I used to decide if I was loading previous values or retrieving and storing new values
And now it works! I just have to work this into the dratted Sofar2MQTT sketch, if I can be arsed! There is come confusion in my mind about where the WiFiClient gets initialised in the WiFiManager case, it's not explicitly done, but just magically works. Hmm.

p.s. Looking at the original WiFiManager examples, it appears that the "+MQTT" code was largely taken from there, with the MQTT added. Hey ho.

UPDATE

Trying to get the 64x48 OLED screen working - the original Adafruit interface is supposed to handle 128xN, and the screen is showing a weird slipped wrong aspect ratio kind of effort. Will I have to hack into the Adafruit SSD1306 interface code?! There is an old version that someone has modified for 64x48, but it's the old style interface. Sigh.

Comments

Popular posts from this blog

Replacing Coffee Machine Pump (Dualit Espressivo)

Multiple SHT30 sensors on a single I2C bus with Sonoff-Tasmota

NodeMCU + Tasmota code + SHT30