Hi @glyn.hudson
I had an Eureka moment.
Whenever I lose the MQTT connection the MQTT server has reverted to 192.168.1.22.
I suddenly realised that is the emoncms url. So how the hell did the esp know that url?
I think the answer is demand shaper.
This is when I first setup the ESP
Config is:-
{“espflash”:1048576,“version”:“3.1.1”,“node_description”:“Sonoff Smartplug”,“node_type”:“smartplug”,“ssid”:“studiomesh”,“pass”:"_DUMMY_PASSWORD",“www_username”:"",“www_password”:"",“hostname”:“smartplug6590”,“emoncms_server”:"",“emoncms_path”:"",“emoncms_node”:"",“emoncms_apikey”:"",“emoncms_fingerprint”:"",“mqtt_server”:“192.168.1.28”,“mqtt_port”:2082,“mqtt_topic”:"",“mqtt_user”:“bpa”,“mqtt_pass”:"_DUMMY_PASSWORD",“mqtt_feed_prefix”:"",“timer_start1”:65535,“timer_stop1”:65535,“timer_start2”:65535,“timer_stop2”:65535,“time_offset”:65535,“voltage_output”:65535,“ctrl_mode”:“Off”,“flags”:2,“emoncms_enabled”:false,“mqtt_enabled”:true,“ctrl_update”:false,“ctrl_state”:false}
I go into emoncms and go to demandshaper.
I get this
I click Allow.
I think at this point the ESP loses the MQTT connection. I managed to capture it in the log:-
GET http://192.168.1.90/lastvalues
GET http://192.168.1.90/status
GET http://192.168.1.90/lastvalues
GET http://192.168.1.90/status
GET http://192.168.1.90/lastvalues
GET http://192.168.1.90/status
GET http://192.168.1.90/lastvalues
Received 12 bytes from 192.168.1.22, port 42090
UDP packet contents: emonpi.local
mqtt_server changed
MQTT Server Updated
Fetching MQTT Auth
192.168.1.22
Connecting to http://192.168.1.22:80/emoncms/device/auth/request.json
Authentication request registered for IP 192.168.1.90
Disconnecting MQTT
MQTT Connecting to…192.168.1.22
MQTT failed: -2
GET http://192.168.1.90/status
GET http://192.168.1.90/lastvalues
Free memory 23608 - diff 4048 8800
GET http://192.168.1.90/status
GET http://192.168.1.90/lastvalues
Clearly the UDP packet is changing something.
Now I don’t know if the problem is the demandshaper message contains something it shouldn’t or that the ESP is reacting to the message in a way it shouldn’t.
When I go back to the ESP I see this:-
And config now shows this:-
{“espflash”:1048576,“version”:“3.1.1”,“node_description”:“Sonoff Smartplug”,“node_type”:“smartplug”,“ssid”:“studiomesh”,“pass”:"_DUMMY_PASSWORD",“www_username”:"",“www_password”:"",“hostname”:“smartplug6590”,“emoncms_server”:"",“emoncms_path”:"",“emoncms_node”:"",“emoncms_apikey”:"",“emoncms_fingerprint”:"",“mqtt_server”:“192.168.1.22”,“mqtt_port”:2082,“mqtt_topic”:“emon/SPtest”,“mqtt_user”:“bpa”,“mqtt_pass”:"_DUMMY_PASSWORD",“mqtt_feed_prefix”:“studio2studio2”,“timer_start1”:65535,“timer_stop1”:65535,“timer_start2”:65535,“timer_stop2”:65535,“time_offset”:65535,“voltage_output”:65535,“ctrl_mode”:“Off”,“flags”:2,“emoncms_enabled”:false,“mqtt_enabled”:true,“ctrl_update”:false,“ctrl_state”:false}
The only way you can replicate this is to set up an instance of Emoncms on one pi with a mosquitto server on another pi in the same way I have.