Showing posts with label NodeMCU. Show all posts
Showing posts with label NodeMCU. Show all posts

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

It's been a while since an update. We had been due to play the game I was building for at the end of June but we've had to postpone.

My friend Mik, who is the driving force behind the game, became very ill and while we could have finished off the work and played it didn't seem right.

Nonetheless I've now got ten Wifi connected RFID readers that talk MQTT and emulate the sort of thing you see on security doors. Blinkenlight, buzzers etc.

They're a bit chunky but then they're hand built from hobbyist modules and have a 3xAA batteries in to drive them. So chunk was kind of unavoidable.

Also I've built a faux CCTV system with some Wifi IP cameras and a 'portal' that uses the same RFID cards to log you in. The portal is a single page full of JavaScript which links to the various cameras and either shows or hides them based on which card you present. So it's not really secure but it's for a game after all.

The setup uses a cheap eBay USB card reader and these just emulate a keyboard. When you present a card it sends the card ID and presses enter. A little bit of JavaScript to capture this and it looks like magic.

Implementing this all in JavaScript worked way more easily than I expected and I'm really looking forward to using this in a game.

We were throwing away two prehistoric Compaq TC1100 Wintel slate PCs from work and I managed to grab them. With Ubuntu Mate installed they work just great, even the horrible stylus is functional. What's great about them is it stops me building a 'high tech terminal' prop as they look like one without really looking exactly like a conventional laptop.

The whole thing isn't 100% finished, I'd been burning the midnight oil a bit and when it got postponed I stopped. Once we've got a new date for the game I'll get back on the horse.

In the meantime though I presented at the London Arduino Meetup about some of my previous work.

There's a video of my full presentation here, but DON'T WATCH THIS IF YOU PLAN TO PLAY THE NEXT WAYWARD SONS GAME AS THERE ARE MASSIVE SPOILERS IN THE Q&A.

Presentation Spoiler: I say 'um' too much.

There are also some nice photos on the organiser's flickr feed.

Now I'm freed up to work on other things, we've got the season of Lasertag LARP ahead and I seem to have managed to break/kill several of my 'tag weapons. I think I'll be fixing these this weekend.

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

Producing lots of the same thing has been this week's task.

I spent a load of time messing around designing a 3D printed enclosure but kind of ended up with a box when my more ambitious design didn't really work. Still there are little pegs and clips to hold the modules loosely, which I've then fixed in place with some hot glue.

What I've got in each unit is a ESP-01 Wifi module, Arduino Pro Mini, MFRC522 RFID reader/writer, LDO regulator, Piezo sounder and a couple of big bright 10mm LEDs.

All of this is tested and working together with proof of concept code. Tomorrow I solder up the wiring looms.

Once I've done these ten, I've got another batch of similar, but slightly different stuff to design an enclosure for and assemble. I've learned a bunch of lessons while making this enclosure so it should take me much less time.

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.

Sometimes it pays to be late to the party

About this time last year this development board made a big noise in the tinkerer scene.

The tiny little ESP8266 based ESP-01 gives you a microcontroller with decent Wifi support for very little money. I've just ordered some from China for £2.28 each.

It started out as a serially connected faux modem driven with AT commands intended to slave off other devices and get them on Wifi. With the SDK and a pile of useful info publicly available from the chip manufacturer soon there was alternative firmware floating around that let you actually use it in its own right to do things.

This variant of the board only has two GPIO pins you can use but the chip itself has loads more and there are now a whole slew of boards around that expose more these, notably NodeMCU.

Anyway I bought five of these almost a year ago and chucked them in a storage box, mostly because the pinout is breadboard-unfriendly and I was busy with other things.

Now I'm in the position where I'm building some props that ideally need to interact with people via Wifi and a browser so I hunted round for these and started to have a look.

First thing to do was update them and by pure accident I put the NodeMCU firmware on, rather than the AT firmware. I've previously stayed away from nodeMCU because I didn't want to learn yet another programming language. This mistake was quite fortuitous though as reading around the subject it seems NodeMCU has some really nice features and is powerful enough to allow me to offload the user interface stuff I need to the ESP-01.

The Lua programming language is interpreted and seems to have a few foibles but as implemented on the ESP8266 looks really useful and comes with great stuff like read/write access to a basic persistent filesystem in the flash memory of the device. This is where the Lua programs are stored and it always runs 'init.lua' on startup but you can have more than one .lua file on there and call them later if you wish. OK you've only about 64KB to play with but it gives you a place to store things too and this will probably be just right for my application. You can even upload files to it from a PC with some community contributed applications.

Should you be so minded it can run a minimal but conventional web server that serves files and at a push does basic CGI scripts with Lua. Although this is very much pushing the bounds of what it was designed for. I probably won't go this far but I can see myself embedding a basic server that responds to AJAX requests from another page.

I'm definitely late to this party but when the ESP8266 boards first came out they were a bit limited and seen as 'quirky'. Now after a year of community development this is really interesting stuff and I can see myself using it a lot this year.