Feature #610

Implement lightsw IoT device

Added by Hammel 5 months ago. Updated about 1 month ago.

Status:In ProgressStart date:04 Mar 2018
Priority:ImmediateDue date:
Assignee:Hammel% Done:

70%

Category:-
Target version:Iron Man - 002 - MVP
Severity:04 - Low

Description

This is code for the ESP8266 to act as a lightsw. It is an extension of the generic ESP8266 code I'd worked on previously, but redesigned to adhere to the defined protocols for Ironman.


Related issues

Related to Monitor - Feature #625: Ad support for returning a device list to imrest New 08 May 2018
Related to Monitor - Bug #639: iot.c code is all wrong Closed 11 Jul 2018

Associated revisions

Revision cc40ec26
Added by Hammel 5 months ago

RM #610: Initial import of the lightsw code. It compiles but hasn't been tested.

Revision 28a4a5c5
Added by Hammel about 1 month ago

RM #610: Integrate initial config pin handling into Setup().

Revision fb5d1373
Added by Hammel about 1 month ago

RM #610: First working version with both Config Mode for WiFi and Relay On/Off capabilities.

Revision 8a68c16f
Added by Hammel about 1 month ago

RM #610: Add support for building with serial console support or with blue LED support using SERIAL environment variable. Added support for switching to Pair Mode after power up using same button as Config Mode button.

Revision a04643b0
Added by Hammel about 1 month ago

RM #610: Messy code, but it actually does the right thing on all modes: configure mode only saves config, then operational mode uses it to connect again.

Revision 2ff22236
Added by Hammel about 1 month ago

RM #610: Remove NOWM define. Add trailing / to ESP_ROOT because it's a symlink and the "find" in makeEspArduino fails without it. This fixes builds with the latest makeEspArduino so we can use the latest instead of that very old commit ID.

Revision af6f2445
Added by Hammel about 1 month ago

RM #610: Add patch for broken aJson library when compiled against arduino 2.4.1 with makeEspArduino 4.13.0.

Revision 51ee75fd
Added by Hammel about 1 month ago

RM #638, RM #610: Updated Makefile to work with latest (4.13.0) version of makeEspArduino, and thus with 2.4.1 Arduino core.

Revision 7d332357
Added by Hammel about 1 month ago

RM #638, RM #610: Completed support for setting and saving WiFi credentials, then re-using after reset or power cycle.
Remove credentials handling - WiFiManager now handles it properly since upgrading Arduino core and makeEspArduino.
Remove cruft code used for original testing.
Added blink patterns for ConfigMode, OperationalMode, Connecting, Connected and Pairing.

Revision 9412dd1d
Added by Hammel about 1 month ago

RM #610: Just to verify SPIFFS is now working with latest Arduino distribution and makeEspArduino, added SPIFFS read and
write routines. These were tested inline first, to make sure SPIFFS really worked (it did) and then moved to generic
functions for later use.

Revision 0d84cfd8
Added by Hammel about 1 month ago

RM #610: Code cleanup, mostly related to setting up pair mode and registration so they work properly for multicasting to monitor. Added SPIFFS code to load registration credentials at setup() time, if available. Cleanup moving between modes in loop().

Revision 3d967a76
Added by Hammel about 1 month ago

RM #610: Completed updates to allow imlightsw to perform pairing with monitor. Cleaned up code related to timer handling. Fixed URL used for registering with imrest REST API.

Revision 6a8d019c
Added by Hammel about 1 month ago

RM #610: Cleaned up IoT code to reflect moving all handling to the imrest server, leaving only bare minimal mulitcast discovery responses.

Revision 19e4ea98
Added by Hammel about 1 month ago

RM #610: Fix IoT registration handling, including handling the case where imgpio is not found (which happens on workstation testing environment).

Revision c3d61a8b
Added by Hammel 20 days ago

RM #610: Add support for faking imgpio when testing on the desktop.

Revision 7dfccb6e
Added by Hammel 20 days ago

RM #610, RM #641: Add Base64 library to build. Add configurable device type and description to build.

Revision 3e50514b
Added by Hammel 1 day ago

RM #610: Change configModeCallback to saveModeCallback which is called on completed attempts of connecting to AP.
Reset WiFi settings if in config mode before starting WiFiManager UI.
Cleanup messaging when using WiFiManager UI based on review of the manager code and how it actually operates.

History

#1 Updated by Hammel 5 months ago

  • % Done changed from 0 to 30

#2 Updated by Hammel 5 months ago

First pass is pushed. It compiles but isn't tested. And there are no stubs yet for actually controlling the light switch. This is just a communications implementation.

#3 Updated by Hammel 5 months ago

  • Project changed from Iron Man to Sensors
  • Category deleted (Device Node)

#4 Updated by Hammel 5 months ago

  • Severity changed from 01 - Critical to 04 - Low

#5 Updated by Hammel about 1 month ago

First, getting back to working with the ESP-01 took a while. My layout on the breadboard was klunky so I reworked it and things stopped working. It took quite a bit of time before I found the problem.

If you power the ESP-01 from it's own 3.3v source, then the FTDI board used to program it must have the same ground. If not then any attempt to program gets stuck while the PC tries to connect to the ESP-01 bootloader. I'll post some pics for this setup later.

After fixing that I can upload and run the old esp8266 sample code I had. It will boot into the WifiManager hot spot for configuring the board using 192.168.4.1 and the AP "imiot". However, the lightsw code, which was based on that, doesn't work.

Now I need to run meld to compare the two modules and see why the new code isn't booting into the wifi manager.

Also: If I use the Arduino IDE, I have it pointing at 1.6.7. I should update this to the 1.8.4 version, using "latest" as a symlink and pointing ~/bin/arduino to that. See also: https://github.com/esp8266/Arduino.

#6 Updated by Hammel about 1 month ago

There is a prime example, nearly identical to what I'm trying to do, on this website:
https://www.forward.com.au/pfod/ESP8266/GPIOpins/ESP8266_01_pin_magic.html

The section on Driving a Relay and Reading a Push Button using GPIO0 / GPIO2 is what I need to implement.

FYI: my current code for imlightsw wasn't working because of my incorrect use of GPIOs. The example code above should fix this (along with some hardware mods to the breadboard).

There's also this article, which is probably a little closer: http://acoptex.com/project/304/basics-project-021e-esp8266-esp-01-wi-fi-module-5v-relay-modules-webserver-at-acoptexcom/

#7 Updated by Hammel about 1 month ago

  • % Done changed from 30 to 40

Whoopeeeeee!! The first working version of imlightsw is now committed and pushed. The working version has a Config Mode switch that allows me to place the ESP-01 in Wifi AP Configuration mode at power up. If the switch is disabled then we enter Operational Mode. In Operational Mode the Relay switch is toggled on and off every three seconds.

I'll post a pic of this later just to show the Relay LED on.

Now it's on to cleaning up the code so inbound messages can control the state of the relay.

#8 Updated by Hammel about 1 month ago

Added support for building with either serial console or blue LED using SERIAL environment variable.
Added support for switching to Pair Mode after power on using same button as Config Mode.

Now it's ready to integrate the comm protocols.
  • First I need to verify the web server is setup properly and I can reach it.
  • Then I need to implement/verify the REST API for the device.
  • Then I need to integrate AES encryption for decoding commands and encoding responses.

The first two shouldn't take long, though implementing a command to enable/disable the device has to be tested from the monitor.

The last one may need some fiddling to get right. Hopefully the Arduino AES library support 128 bit encryption which is what the monitor is using.

#9 Updated by Hammel about 1 month ago

  • % Done changed from 40 to 50

The web server in imlightsw is working now. The IoT sends a multicast message that the monitor responds to by going to the IoT web server, passing a UUID. The IoT device then contacts imrest to register with that UUID.

At that point the test stops because it was run on my desktop and there is no imgpio available. I can fake this if needed to complete registration testing.

Next up is AES message passing.

#10 Updated by Hammel about 1 month ago

  • % Done changed from 50 to 70

Also available in: Atom PDF