ESP8266 based MQTT gateway for DIY Kyoto Wattson
DIY Kyoto Wattson is a wireless three phase Electricity monitor that came to the market about 2010. The manufacturer did not provide other software than "Holmes" for Windows. I reverse engineered the serial protocol in 2011 by eavesdropping the serial traffic from the USB. Then I wrote a Linux daemon for it. The daemon worked well all these years but I got an idea that it should use just ESP8266 and MQTT. The graph could be drawn by Grafana.
The device has a Mini-USB connector and looks as a generic USB serial port with 19200 8N1 to the computer. I thought that the ESP could be connected directly to the serial line of the device "after" the USB circuit. That was a quite easy hack. See Hardware.md.
The sketch sends the current power consumption with MQTT every 3 seconds. It also keeps it internal clock in UTC with NTP. The MQTT packet is a JSON like this example:
{"type":8,"p"=1234000}
The type=8 comes for my "standard" that is explained at ESP32 BLE2MQTT docs and parameter p is power in milliwatts.
It will add the device's serial number at the end of the topic. Eg. if the topic base is set as wattson and the serial number is s123456, the MQTT topic will be wattson/s123456
There you can find also an example how to configure Mosquitto, InfluxDB and Telegraf.
You will need also the Arduino ESP8266 filesystem uploader and upload the html and css files in data directory to SPIFFS.
This contains a quite similar portal as many other of my ESP sketches. If the GPIO14 is grounded, the ESP
switches to the portal mode. Connect to WiFi ESP8266 Wattson, accept that there's no internet
connection and take your browser to http://192.168.4.1/
The portal mode has a timeout. The unit will reboot after 2 minutes of inactivity. There's almost no sanity checks for the data sent from the forms. This is not a public web service and if you want to mess up your board or try to make a denial of service using eg. buffer overflows, feel free to do so.