Using ESP8266, NodeMCU and MQTT to create a wirelessly connected 'installation' - part 1

Following up on my last post I'm now neck deep in building an 'installation' where most the components connect over Wifi using ESP-01 ESP8266 modules.

Kicking off the project I've been doing the usual thing of building the first steps from an unapologetic cut & paste of 'stuff found on the Internet'. There seems to be a bit of gulf between the 'hello world' examples and people wrestling with complicated issues, but that's often the case with project examples.

So I thought it might be worth putting something back and actually documenting everything I'm doing, which will cover some of that middle ground.

The installation is going to be about 25 'things' that need to be 'orchestrated' to work together. This is happening over quite a large, remote outdoor area so this is being engineered from scratch to be self-sufficient in every way. Including power.

So far here's where I am on the planning front.

  • Wifi - This will be four 'nodes' each with a dedicated firewall, 3G modem, Wifi AP capable of mesh networking and most likely a Raspberry Pi to do the 'orchestration'. Yes you could squeeze all this out of the Pi but I want to compartmentalise the components. There may be Yagi antennas to increase range.
  • Networking - Each 'node' will be connected to the others over the Wifi mesh and run OSPF to keep track of routing. There is also Internet access via the 3G. This 3G provides a backup connection for the Wifi over a hub & spoke VPN. I work in this field and have some kit in a Data Centre to connect back to. This stuff is my bread and butter so it's already tested and working, yay!
  • Power - The 'nodes' will use 12V lead-acid deep cycle batteries. The event only lasts 4-6 hours and a lot of the kit I've scrounged will run straight off the 12-13V these deliver in practice. The 'things' will be powered either by 3x AA or 1x 18650 battery depending on if they're static or carried.
  • Things - These are going to be driven by an Arduino/ESP8266 combo. The Arduino Pro Minis will do the procedural, timing sensitive stuff like drive I2C displays, talk to peripherals over SPI and so on. The ESP-01 will run Lua and act as a gateway to the Wifi and MQTT. Communication between the two will be over serial with a bit of simple message passing. In principle I could have bought a bigger ESP8266 dev board and used that. However this decision is still about compartmentalisation. The Arduino environment has a very mature set of libraries for talking to stuff, but is bad at the networking. Lua/NodeMCU simply doesn't have the libraries for the modules I'm using but seems to have decent networking support.
  • Communication with 'things' - I have settled on MQTT because it's lightweight and seemingly well supported in Lua/NodeMCU. This means I don't have to roll my own networking protocol like I did last year. I may be able to 'gateway' the 868Mhz radio kit I built last year into MQTT but that's not a job for now.
  • Orchestration of the 'things'. This will be done with some scripts on the Raspberry Pi at each node. For an MQTT broker I'll be using Mosquitto, probably with Python. The hand carried 'things' will have a bit of intelligence so can wander out of Wifi range and then update the nearest Pi when they get Wifi again. I've already tested some basic use of Mosquitto from NodeMCU.
  • Enclosures - There will be 3D printed enclosures for all the 'things'. Not the cheapest or fastest way to do it but this kind of exercise is why I bought my printer. The enclosure for one thing is pretty much finalised and I've done work on another.
  • Interaction - As well directly interacting with the installation, some people will be able to control it. For that I've acquired some old XP-era Pentium-M laptops (pictured) I am turning into web kiosks with Puppy Linux. This avoids having to leave a nice laptop sitting under a gazebo in the woods. Two of them are weird HP/Compaq TC1100 Windows Slate PCs which makes them quite a nice unusual looking thing to interact with. The batteries are obviously ruined so I will need to come up with a way to power them from 12V. I've got one inverter and one 12V powered laptop PSU, just need to find a third.
  • Monitoring - As well as controlling some components, ideally some people will be able to watch other areas over 'CCTV' using the supplied laptops. Thanks to the generosity of a friend I've pulled together five identical old IP cameras that will go straight on the Wifi.
Somehow or other I've got to make all this happen and write a web interface to it. Thankfully I've started early and have a handle on a lot of it. There's still a mountain to climb though.