Saturday, 27 October 2018

Voice-controlled ESP8266 IoT AC Mains Power Extension Part 3 of 3

230Vac Fluorescent battery-backed lantern  
I have had this lantern for over 20 years. It is obsolete- dual 230Vac fluorescent lamps running from a 6V 7Ah lead-acid battery. Yet it has never failed - I replaced the battery many times but the lamps never blew. It is always plugged, in float-charging the battery and when the mains power goes the lamps automatically comes on.

It would be nice to have a bit of extra light sometimes during normal conditions, so why not mount it on the ESP8266 IoT Extension? And it would even be nicer if I could control it by voice command.

I do not have Google Home or Amazon Echo yet, but my Android smartphone does have Google Assistant which will capture my voice commands. I just need to forward the command words to the ESP8266 IoT device.

Robosapien has a great writeup on using the ESP8266 with Google Assistant, IFTTT and Adafruit IO. I really wish I could improve on it, but I believe Robosapien has had the last word on the subject. I simply followed all the steps and replaced his hardware with my ESP8266 IoT AC Mains Power Extension.

The process just took half a day, and I now have a voice controlled 20-year old lantern!

Update (2018-11-27): after running the IoT lantern a few days, I noticed a new WiFi access point with an extremely strong signal:

iwlist wlan0 scan
          Cell 04 - Address: xx:xx:xx:xx:xx:xx
                    Frequency:2.457 GHz (Channel 10)
                    Quality=70/70  Signal level=-34 dBm
                    Encryption key:off
                    Bit Rates:5.5 Mb/s; 11 Mb/s; 1 Mb/s; 2 Mb/s; 6 Mb/s
                              12 Mb/s; 24 Mb/s; 48 Mb/s
                    Bit Rates:54 Mb/s; 9 Mb/s; 18 Mb/s; 36 Mb/s
                    Extra: Last beacon: 4442ms ago
                    IE: Unknown: 000A4553505F314343363044
                    IE: Unknown: 01088B9682840C183060
                    IE: Unknown: 03010A
                    IE: Unknown: 0706534720010D14
                    IE: Unknown: 32046C122448
                    IE: Unknown: DD0918FE34030100000000

A signal level of -34dBm was stronger than my own access point! In fact I can detect and log into it two houses down, some 150m away through 2 concrete walls.

It turned out to come from the lantern code, and while it does not interfere with its operation, it is also a security risk as it is an open Access Point. As usual the Internet provided an answer; there is a bug in the ESP8266 Arduino library. There is a workaround: you just need to insert WiFi.mode(WIFI_STA) after calling WiFi.begin().

My setup code now looks like:

void setup() {

  pinMode(0, OUTPUT); // 2018-10-26 set gpio to o/p

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");

  WiFi.mode(WIFI_STA); // 2018-11-27 remove rogue AP
  while (WiFi.status() != WL_CONNECTED) {

  Serial.println("WiFi connected");
  Serial.println("IP address: ");

  // Setup MQTT subscription for onoff feed.

Lantern with IoT Power Extension
Now the logic is reversed for the lantern as it comes on when there is no mains power. This I did by entering a data '0' when the IFTTT trigger is on.

Note reversed (data zero) logic
Google Assistant, IFTTT and Adafruit IO all worked first time. Here is a youtube video of it:

Youtube video
There you have it, a voice-controlled IoT lantern. It is not ideal and much work needs to be done on it, but it still works as before without the Internet, and in the spirit of DevOps, just put it out there as fast as we can ...  Happy Trails.

No comments:

Post a Comment