Some time ago an opportunity knocked on my door. A friend needs a device that would read a card, send the id to the server and react to response.
Today we will work on code and create a class and a handler for the RC522 module.
Module and handler added to NodeMCU boilerplate @ GitHub
In parameters.lua we may set only one access point and a password. But lately, I’m testing my devices in different areas, different APs. Changing passwords all the time is stupid so we need to improve this.
We will allow the table of credentials and boilerplate will iterate over them to get the connection.
Not so long ago I ordered a sound detector based on LM393. Today I thought that maybe it is time to use it. How? Maybe we can do a light-clap module.
With each clap relay will change its state. It is not complicated and may be a good fun 🙂 Naturally, we will use NodeMCU and LUA.
Our third and fourth data are temperature and humidity. We will use a DHT11 sensor with the NodeMCU.
Get module and NodeMCU boilerplate from GitHub
We have a nice node that detects light, it works in toilet @ my work 🙂 It does it jobs almost perfectly. There is still a hack for it – leave a light on when leaving the toilet. I have an idea to fix this but first, let’s reforge a lousy code into a module and a handler. After refactor we may safely add it to the NodeMCU boilerplate.
This is going to be our second data node for display. It will show area lightness and with conjunction with a time, we can tell if an artificial light is on or off.
NodeMCU boilerplate @ GitHub
We have LCDs and we should have a data that can be displayed on them, we need data sources. So in parallel with displaying, let’s work on some sensor nodes.
First will be a motion detector, we gonna use a module with easy to remember name: PIR HC-SR501 🙂.
There are a few variants of it. But the main difference is an ability to use jumpers to change mode. My version can’t do that 😦
As a brain for sensor we will use the NodeMCUv3 board and as a language the LUA.
Module added to NodeMCU boilerplate @ GitHub
A long time ago we created a NodeMCU Node with two channel relay. It was working but it’s code bases on old boilerplate. I recently bought an SSR (solid state relay) so let’s take this opportunity and upgrade our node to the newest boilerplate and write a handler for relays.
NodeMCU boilerplate – GitHub
Due to memory problem I looked once again at the code and.. I found that I’m not using classes properly.
Why? Because every function and attribute were static. I didn’t use self or anything similar.
I scratched my head, looked into google and rewritten temperature sensor.
It can create class instances with self values and static functions.
We have a nice NodeMCU server for LCDs. But there is one catch. We can control one LCD or all connected LCDs. But imagine that we have two LCDs and we want to display different content on each.
In message we can set node name but not device connected to it. So there is case with 1+ screens or broader with many devices connected to one Node.
Another problem: we start LCD server and we want lets say start a server with temperature sensor. We cannot. Lcd would take port and that is all. To do something with this we will introduce event handlers and listers. Big and useful change.
Each module would have an event handler, a function that gets message and do something with it. Returns true when it can handle this event and false when not.
I mention temperature sensor, currently we have none so first lets create one.
Our module displays strings as soon as function write is called. It is mostly enough but sometimes it is better to prepare what we want to display and then display it. Such action uses buffer and that why I’m calling this buffered mode.
We made something like this in CharLCD so we can convert idea to NodeMCU. Due to LUA characteristic both modes are combined into one module.