Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By biobier
#22033 Hi,

also I would like to contribute to this community.
My friend (hardware) and me (coding) have build a WiFi switch for a light (or any 230V device).
Without WiFi connection it will provide an AP with config page. There the IOT mode can be set to control via Web Interface (URL get) or to MQTT with settings.

The final board is not ready yet but the code works very reliable. (Made sure that button works at anytime).
The code used parts from this forum and GitHub (Sorry if I missed a credit, just let me know and I'll add it).
More infos on the Gitpage:
https://github.com/biohazardxxx/ESP_WiFiSwitch

Even the code is quite specific, some parts might be reusable for other projects.
Features are:
    MQTT late bind (since we only know the server after it was setup)
    Button software debounce
    MQTT receive
    MQTT publish
    Ticker for button handling
    Button control to switch , restart and reset (clear eeprom)
    WebServer with config
    EEPROM store and read
Last edited by biobier on Tue Jul 14, 2015 1:28 am, edited 2 times in total.
User avatar
By gambituk
#22062 Hey, this looks great (looking at the code), i am guessing this is designed for something like esp-12? i haven't got one to test this on at the moment but i am gonna have to steal some of the code for checking if mqtt is still connected and reestablishing the connection, and maybe more. I really believe that adding examples like this really make the difference in speeding up development of these boards.

Would be great to see some pics and even better to see a video of it in action!

keep up the good work!

Gambituk
User avatar
By biobier
#22085
gambituk wrote: ...i am guessing this is designed for something like esp-12?


We use an ESP-03 since it is SMD style but even the ESP-01 would work, since only two GPIO's are needed. GPIO0 for the button (+boot mode) and any other to switch a triac. (the triac is essential to determine the current state of the light, but maybe it could have been hold in a global var when using a relay)
I'll try to make a short video next days.

danbicks wrote:Why did you not use the lmroy PubSubClient library?

First time I hear about it. I use the vicatcu version since it allows late binding of broker,port, etc (Needed since this settings are read from EEPROM during runtime). It looks like this is not possible with lmroy's version.