Having an issue with node-red (im pretty sure), if you could help me that would be most aprechiated because its doing my head in.
So, esp32 has values stored in it, default value (value of 10), it subcribes to a topic, i can change the value from the dashboard (value of 5), the value is sent to the device and saved on a local SD card, ok all good so far, i send another value to the esp32 (value of 2), it stores it and saves it to the card, as expected. A serial monitor shows what the esp32 has recieved and done with the information, all done as expected.
I then reboot the esp32, outputs the stored data to the serial monitor on boot(for debugging), last sent value is present and correct (value of 2). The esp32 then subcribes again (due to sudden reboot). I then recieve a message from node-red, the first value i ever sent to it (value of 5)......the esp32 then stores that message as it was programed to do.
The issue is i cannot get node-red to stop sending the first (5 in this example) retained value (or any for that matter) when the device subscribes.
Using node-red 2.1.1 and its built in mqtt on a raspberry pi4. I must also note that the esp32 sends/recieves on different topics, if they were the same it just gets stuck in a odd loop, continously sending information back and forth as fast as it can, when it shouldn't (well not that i could see why).
All i really want it to do is send a new number to the esp32 to store on the card, then the esp32 sends back the stored value as a confirmation and displays it on the dashboard. On first boot i will eventually want to send all the values stored on the SD card to node-red.
below is the esp32 serial monitor output after a reboot.
Config.txt:
baltarget = 2 //this is what was sent previously & stored
Wifi.txt:
ssid = *************
password = ***************
Connecting to *************
.........
WiFi connected - ESP IP address: 192.168.100.11 //connected ok
subscribed to all
recieved message on topic BMSM/Rbaltarget //imediatley recieves message
baltarget changed to = 5 //old unwanted value
Done writing to Config.txt //arduino as expected stores value
And my node-red configuration:
[{"id":"bb719087.aa90d8","type":"mqtt in","z":"51c8672.3c7f018","name":"","topic":"BMSM/RbaltargetIN","qos":"0","datatype":"auto","broker":"c531823d.2c0e98","nl":false,"rap":false,"inputs":0,"x":170,"y":2860,"wires":[["2fb69685.2c777a"]]},{"id":"2fb69685.2c777a","type":"ui_text","z":"51c8672.3c7f018","group":"ad172d99.661848","order":3,"width":2,"height":1,"name":"output bal target","label":"","format":"{{msg.payload}}","layout":"row-spread","x":360,"y":2860,"wires":[]},{"id":"7b454bb3.fb6d14","type":"ui_text_input","z":"51c8672.3c7f018","name":"Bal Target input number","label":"","tooltip":"Balance Target (mV) (0-50mV)","group":"ad172d99.661848","order":2,"width":4,"height":1,"passthru":true,"mode":"number","delay":"0","topic":"","x":390,"y":2900,"wires":[["712af693.011ae8"]]},{"id":"bc513f9c.f57af8","type":"ui_text","z":"51c8672.3c7f018","group":"ad172d99.661848","order":1,"width":0,"height":0,"name":"Bal Target (mV) Text","label":"Bal Target (mV)","format":"","layout":"col-center","x":570,"y":2860,"wires":[]},{"id":"712af693.011ae8","type":"range","z":"51c8672.3c7f018","minin":"1","maxin":"50","minout":"1","maxout":"50","action":"clamp","round":false,"property":"payload","name":"","x":570,"y":2900,"wires":[["98b188c.60d5e78"]]},{"id":"98b188c.60d5e78","type":"mqtt out","z":"51c8672.3c7f018","name":"","topic":"BMSM/Rbaltarget","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"c531823d.2c0e98","x":790,"y":2880,"wires":[]},{"id":"c531823d.2c0e98","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"120","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"sessionExpiry":"0"},{"id":"ad172d99.661848","type":"ui_group","name":"Configuration","tab":"d91a31ea.18f87","order":4,"disp":true,"width":"6","collapse":true},{"id":"d91a31ea.18f87","type":"ui_tab","name":"BMS","icon":"battery_charging_50","order":6,"disabled":false,"hidden":false}]
I really cant see why it would be sending an old value.
I hope someone can make sense of this as changing the nodes configurations (like retain flag) dont seem to do anything.