About

When listening to music, there might be some events occurring, in particular, related to hardware or other devices that might be of some interest but using some notification system that is audible will not help unless the sound is passed through the headphones as well. Moreover, the person listening to music might be mobile such that the notification wouldn't be able to be displayed on a screen that is being looked at all the time.

For that purpose, it would be interesting to create on of those light beacons using some strong bulb, like a camera flash bulb that would be able to deliver an impulse, as a side-car to a notification system like Gotify. When a notification arrives, the beacon would flash several times indicating that an event occurred thereby attracting the attention of the person nearby.

Requirements

Perhaps the most relatable design would be the police car design where the very distinct light beacons can be seen from afar. However, this seems more like the case of a "warning" sign, such that a construction beacon with the orange-yellow typical light might be more suitable.

Aftermarket beacons are for sale very cheaply, are typically powered by $12V$ and meant to be plugged into the car smoking accessory socket but have the main drawback that they are not really that powerful. Disassembling such a contraption reveals a small LED, powered directly from the supplied voltage that is the main source of light meant to dissipate through the plastic orange cup that is placed on top.

Obviously, this is not strong enough, the effect sought after being a large powerful flash, so enter the typical household lightbulb in its unbridled form, with no smart features and with no particular "economical" contingencies.

This little puppy is capable of delivering pure tungsten-produced light at real $100W$ and for the sum total of almost being a free off-the-shelf item. It is clear that this is the right item and as far as lifespan goes, needless to say that this bulb will just be flashing so it will not be on permanently enough to even burn through the filament. It's one of those steampunk situations where a little bit of older technology comes back.

With that being established, the next part is the IoT side that will consist in:

  • a small ESP-01S; as unstable as they are, the ESP-01S will be used for wireless connectivity and a single GPIO will be used as an output

  • a low coil voltage relay, at $3.3V$ such as the "EE2-3NUH"; this will be used to light the bulb itself and due to the low coil voltage, the relay can directly be engaged by using just the GPIO voltage,

  • a flyback diode, series "1N4729A" and something, rated at 3.6V that will be used to counter the reverse-spike of the relay,

  • a mini AC-DC converter that can convert $110V$ or $220V$ down to $3.3V$; what happened is that the $3.3V$ AC-DC converter step-down that was used in the first iteration of the project more than likely was rated for a lower amperage, such that when the bulb went on, the AC-DC converter would interrupt for a split second, making the ESP-01S reboot. In order to resolve that issue, an AC-DC step-down to $5V$ was used instead that was rated at about $700mA$, which seemed sufficient to keep the ESP-01S running. These AC-DC buck step-downs are very cheap, very small and can be purchased by the bag.

  • additionally, a DC-DC buck converter was used to step down $5V$ to $3.3V$

  • for the bulb, an E27 socket was purchased that was then dismantled and fit into the casing of the alarm beacon,
  • a handful of wires of various gauges, copper thread, PCBs and the usual soldering equipment

Realization

The beacon shell is dismantled and the bottom cap removed in order to inspect the amount of available space for the rest of the components. The bulb itself fits into the E27 socket, but the porcelain case is smashed and the inner socket extracted. The bottom part of the beacon will be drilled through and a hole as large as necessary to fit the E27 bulb socket will be made.

A PCB is fit on top and the small aluminum socket will be glued or soldered to the PCB in the middle in order to host the bulb. Now the bottom part of the bulb needs to connect to something to complete the circuit so another PCB is wired as a grill and a solder pad is drawn onto the PCB such that when the bulb screws into the socket, the bottom connector will touch the solder pad.

The pad is then completed and the two PCBs are assembled, parallel to each other with the pad on the bottom and the socket on the top PCB.

The result looks overall pretty good and these should be the last structural changes necessary for the project before starting to add the components.

From the point of view of the AC-DC converter, the module is fitted next to the bulb holder and secured down with some hot melt glue. For testing, the device is plugged in and the AC-DC step-down lights up in red. Right next to it, the small PCB shim is meant to further convert the $5V$ from the AC-DC converter down to $3.3V$. On the right, the ESP-01S can be observed being powered by the converter.

The cables connect between PCBs using removable JST sockets in order to ensure that the various components can be removed in case maintenance or corrections have to be performed. On the side, the relay is placed next to the bulb, and power is drawn from =the mains connector to connect to the relay. Similarly, a GPIO pin wire is pulled along with a ground from the ESP circuit in order to be able to commute the relay when necessary.

The hardware part of the project is now complete and only the software component needs to be addressed.

Arduino & Node-Red

The software loaded onto the ESP-01S is the generic Arduino GPIO tool mostly because not much else must be done by the ESP-01S except to toggle a GPIO pin now and then. The template is uploaded and then a Node-Red flow is created.

Here is the corresponding Node-Red flow:

[{"id":"149083f5c6bf2d08","type":"tab","label":"Alarm","disabled":false,"info":"","env":[]},{"id":"4fe73d2c27de0a40","type":"mqtt in","z":"149083f5c6bf2d08","name":"","topic":"alarm","qos":"2","datatype":"auto-detect","broker":"331ec98c048042f6","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":620,"wires":[["f4d5db9c6f1f452e"]]},{"id":"f4d5db9c6f1f452e","type":"debug","z":"149083f5c6bf2d08","name":"debug 94","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":340,"y":620,"wires":[]},{"id":"24812ec7febd3ada","type":"template","z":"149083f5c6bf2d08","name":"blink","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n  \"pin\": \"3\",\n  \"action\": \"debounce\",\n  \"sleep\": \"1000\"\n}\n","output":"str","x":330,"y":80,"wires":[["0c48f88582858ac6","23c7c91253711257"]]},{"id":"0c48f88582858ac6","type":"mqtt out","z":"149083f5c6bf2d08","name":"","topic":"alarm","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"331ec98c048042f6","x":510,"y":80,"wires":[]},{"id":"11a37ea7e9f45f1b","type":"inject","z":"149083f5c6bf2d08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":80,"wires":[["24812ec7febd3ada"]]},{"id":"96496a6c952c8ea4","type":"websocket in","z":"149083f5c6bf2d08","name":"gotify","server":"","client":"c66daf11cd200f0c","x":150,"y":500,"wires":[["5a479f50138b45f5"]]},{"id":"9629db3c04017af6","type":"change","z":"149083f5c6bf2d08","name":"","rules":[{"t":"set","p":"blinkCount","pt":"flow","to":"settingsBlinkCount","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":400,"wires":[["f2fa29cecf9d96a7"]]},{"id":"459d53d8e85a752b","type":"delay","z":"149083f5c6bf2d08","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":340,"y":240,"wires":[["f2fa29cecf9d96a7"]]},{"id":"23c7c91253711257","type":"switch","z":"149083f5c6bf2d08","name":"","property":"blinkCount","propertyType":"flow","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":160,"wires":[["459d53d8e85a752b"],[]]},{"id":"e9c9f1c55ad69eba","type":"link in","z":"149083f5c6bf2d08","name":"link in 31","links":[],"x":165,"y":420,"wires":[["5a479f50138b45f5"]]},{"id":"f2fa29cecf9d96a7","type":"function","z":"149083f5c6bf2d08","name":"function 68","func":"var count = flow.get('blinkCount')\n--count\nflow.set('blinkCount', count)\n\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":320,"wires":[["24812ec7febd3ada"]]},{"id":"5a479f50138b45f5","type":"switch","z":"149083f5c6bf2d08","name":"","property":"blinkCount","propertyType":"flow","rules":[{"t":"gt","v":"0","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":480,"wires":[[],["9629db3c04017af6"]]},{"id":"b8644bbc72ae83c2","type":"inject","z":"149083f5c6bf2d08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":360,"wires":[["5a479f50138b45f5"]]},{"id":"3dac860625dabcab","type":"change","z":"149083f5c6bf2d08","name":"Settings","rules":[{"t":"set","p":"settingsBlinkCount","pt":"flow","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":320,"wires":[[]]},{"id":"ecdabbf311ddc2b2","type":"inject","z":"149083f5c6bf2d08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":650,"y":260,"wires":[["3dac860625dabcab"]]},{"id":"331ec98c048042f6","type":"mqtt-broker","name":"iot.internal","broker":"iot.internal","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"c66daf11cd200f0c","type":"websocket-client","path":"wss://gotify.lan/stream?token=","tls":"14b5e98591d4e0fb","wholemsg":"false","hb":"0","subprotocol":""},{"id":"14b5e98591d4e0fb","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":true,"alpnprotocol":""}]

The flow is very simple, the blink template node creates a payload designed to debounce the GPIO that is connected to the relay coil positive terminal as per the semantics of the GPIO tool template and then publishes the payload onto the MQTT bus marked alarm in the template that will be picked up by the ESP inside the device and will make the bulb light up.

The former is sufficient to make the beacon light up once and then turn off but it would be more interesting to make the beacon flash a few times such that the rest of the template spanning downward contains the necessary logic to make that happen. The switch node compares a counter, the message is delayed $2s$ by the delay node and then the Decrement node will decrease the counter and all of this takes place until the very first switch node finds the counter to be smaller or equal to zero, at which point the loop doesn't repeat anymore. The "Decrement" node is from the node-red-contrib-calc node-red contribution and is used instead of a function to keep things semantically contained.

Finally, the re-entrance safety of the flow is ensured by first checking whether the counter is greater than zero before even starting the loop. This is to prevent concurrent messages from altering the behavior of the logic built around the counter variable and hence by interfering with the blinking sequence of the device. In the end, even if there are multiple concurrently occurring events, the alarm is just meant as a signalling device and not a terse descriptor of the properties of the event that took place.

Practical Application

Now that the means to trigger a beacon a number of times is available, the project can be put to use and, given an existing Gotify sever on the network, it was deemed interesting to make the beacon flare up every time a message is sent to the Gotify server. This works great, because the Gotify server is a proper notification service that aggregates events from multiple sources, whilst this beacon that was just created will be a signalling output for Gotify.

For that purpose, a client key is created within Gotify by the administrator by following "Gotify menu"→ClientsCreate Client and then a websockets node in Node-Red is configured to subscribe to the "stream" Gotify service that provides all notifications by using the URL wss://gotify.lan/stream?token=CLIENT_TOKEN where CLIENT_TOKEN is the client token just created.

With the client token created, all that remains is to plug the newly created gotify node into a node that sets the flash counter, and then the rest will be plugged into the regular Node-Red loop for the alarm beacon in order to make the alarm flash a set number of times whenever a Gotify notification message arrives. Note that no particular handling of the message from Gotify is performed, but if necessary, the message could be interpreted and perhaps different actions taken depending on the Gotify message (for example, different flash counts for different Gotify applications).


iot/creating_an_alarm_beacon.txt · Last modified: 2025/01/17 00:56 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.