I finally got code to work for the pushbutton/toggle switch. My problem now is that I can not make the sketch connect to my MQTT server. The system is complete on NodeRed and the dashboard involving two flashed sonoff switches.
But I am making some mistake in the “void reconnect” function. The switch runs the led just like I want it to but I can not get the MQTT server to connect.
The button code and the flow are pastebin:
I have looked over this so much but I just can not come up with the solution. The primary reason is that I don’t have enough basic skills to understand the errors. I was able to get the dashboard to function from the internet and my phone but I can’t make the MQTT connect.
The basic mqtt_esp8266 sketch work great but there something about the topics that have me stumped. The current topics that may be in the flow have been changed around so many times that I have lost track of them. My basic idea was to be able to use a handheld remote to turn a sonoff on with one click and off with another. That part of the sketch works as I want it..
Just do double-check:
- Do you see any error in your Arduino IDE serial monitor? Does it print any message? Please post what you see
- Remove line 94 and 95: https://pastebin.com/sNGAU4JG Your ESP8266 cannot be subscribed to the same topic that is publishing the messages. Otherwise, it publishes a message and receives it causing a loop