Self Discovering IoT System

I’ve been working for a couple years now to automate my RV using a combination of Photon micro-controllers, an iOS app, and an Alexa skill. This has been fairly easy to do, due mostly to the ease of using the API. Over the next year, in addition to adding additional functionality and more Photons, I hope to add Apple TV and Watch apps. This got me to thinking about how to make the system easier to configure and extend.

Since I’ve written all the software pieces myself (iOS app, Alexa skill, Particle sketches), up until now I’ve taken the expedient route of just hard coding the names of each controller into both of the apps. With only a single iOS app and Alexa smart home skill, this meant updating those two programs every time I added a new Photon, or extended one of the existing Photons. Not a big deal, albeit somewhat inconvenient.

However, recently I created an additional iOS app to allow using older iPhones to be mounted to the wall and used as control panels. Hard coding the names of the controllers into the apps means that I have to manually update each device whenever there is a micro-controller change. Now this is becoming a much bigger inconvenience.

So I’m in the process of making each micro-controller self registering with the system:

  1. Each Photon will broadcast periodic “I’m alive” messages on the pub/sub network. This messages will include the Photon’s name. This name can be used to address it using the API.
  2. A designated ‘master controller’ Photon will monitor these messages, collect a list of all the names, and publish a comma separated list of names via a ‘controllers’ variable accessible via the API.
  3. Each application will read the ‘controllers’ variable get the names of all Photons, instead of having a hard coded list in its program.
  4. The master controller will also send out a ‘system updated’ event whenever it updates its list, so the apps know when to refresh their device list.
  5. Each Photon will similarly publish a list of each of the devices it implements in a ‘devices’ variable, exposed by the API. This list will include the name and type of device (light, fan, etc).
  6. All applications will read the list of controllers from the master controller, then access the list of devices from each of those controllers.

So now instead of needing to reprogram each app whenever I add a new controller, I just need to expose the data about that controller as described above, and all the applications pick it up as soon as it powers on and sends its “I’m Alive” message.

I’m in the process of posting all this code to Github, so keep an eye out there for updates.