8 communication - patience4711/SONOFF-SENSOR GitHub Wiki
communication
We can talk in different ways to the sonoff; via an API (http request), via mosquitto, via the webinterface or via the button. If we connect a touch senor we have one way more.
API
if we issue a command like <ip_of_sonoff/get.Homepagedata> we get a json like {"name":"SONOFF-9828677","state":"0","rm":0,"sensor":"BME280","readings":"26.9 / 50.4 / 1022.9","unit":"℃ / % /hPa"} if we issue <ip_of_sonoff/SWITCH=ON the switch goes on.
mosquitto
If we publish to the intopic {"idx":123,"nvalue":1} this is a switch on command, the switch goes on. When mosquitto is active, sensor readings in a json format are published as well as the state of the switch. Readings will be a json like: {"idx":919,"nvalue":0,"svalue":"26.7;49.2;1;1023.0;1;"} (temperature humidity pressure) A switch update is {"idx":123,"nvalue":1}