Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Godfather
#31994 Hi guy's thought I'd throw my contribution in. It's been 35 years since I first learnt to program in machine code, so be gentle although I'd welcome any comments.

The attachemnt builds on the great work done by John Lassen for the easy web config sketch and the work by forum community member Kaz (sorry Kaz I don't know your full name!) on MQTT.

It's main purpose was a to brush off some old cob-webs and get the brain working again, other than that it turns on a device or turns off a device. I wanted to do the initial Network and MQTT setup via a web interface then issue commands from an MQTT client. Hopefully some day (come on Kaz...Lol!) there will be an Android/IOS app whereby you can subscribe to any topic, send any message and more importantly process the feedback so you know your instructions have been carried out.

Eventually I will interface it to my commercial coffee machine with some heavy duty relays as I keep blowing up the current retail offerings! (don't want to mention any names here as I might get (WE#$@#$MO into trouble!)

I've tested it on ESP12E and please note it uses PuSubClient V1.9 it won't work with V2.0.

It's probably best to configure and write the MQTT broker then NTP settings in the web interface before following John's initial instructions on configuring the network side, that way it will startup clean.

Follow the comments in the sketch to see how the various timer operations interact.

Once you have configured your MQTT client to subscribe to "feedback" topic you can publish messages on "LED" topic.

The messages are (must be correctly formatted including colon's, spaces and case):
on: (will bypass timer and turn on device)
off: (will bypass timer and turn off device)
time: (will return the time to the feedback topic)
auto turn on: e.g. auto turn on: enable or disable (will enable/disable the device on timer)
auto turn off: e.g.auto turn off: enable or disable (will enable/disable the device off timer)
on time: - e.g. on time: 07:15 (will set the timer to turn on the device at 07:15)
off time: - e.g. off time: 10:15 (will set the time to turn off the device at 10:15)
status: (will return the timer parameters to the feedback topic.)

One other note: to turn off the device assuming it has been turned on via the auto timer and the auto off time has not been reached as yet. Issue auto turn off: disable message or do the same thing via the web interface. This will turn off the
device , you will not be able to turn it back on again via auto turn off: enable to resume timer functions, however you can do so manually via the web interface bypass command or on: message. Hope this makes sense? I had a tough time getting my head around on how to make a momentary active switch in software and still think I haven't got it right!
You do not have the required permissions to view the files attached to this post.
User avatar
By Godfather
#32062 Just found an error in my initial posted doco.

Once you have configured your MQTT client to subscribe to "feedback" topic you can publish messages on "LED" topic.

should be

Once you have configured your MQTT client to subscribe to "feedback" topic you can publish messages on "device" topic.

sorry for the inconvenience.

Should also mention that I was using v1.0 of the NODEMCU dev board.