What is it?
OpenSensors Occupancy Sensors are small ultrasonic distance measurement sensors that measure whether or not a desk space is occupied.
With increasing numbers of workers opting to work from home for days at a time and the costs of office space rising, the ability to reliably monitor your office occupancy is becoming critical to keeping costs down. This hardware project utilising Node-RED allows you to do just that.
Check this out before reading on...
https://github.com/OpenSensorsIO/desk-sensors
This repo contains the Arduino code for the RFu328 ultrasonic desk sensor as well as the Node-RED flow for the hub device and the PCB EAGLE files.
Check out localhost:1880/status
for output from the sensors.
Big acknowledgement of Oxford Flood Network, ThingInnovations and Andrew Lesley for great examples.
PS for the EAGLE files: board v3 was designed to take 6-12V input and use two Wirelessthings PowerPods (PowerPOD 1117) to transform to 3.3V (for the RFu328) and 5V (for the HC-SR04 ultrasonic device). However, it was found that these down-regulating pods have unacceptable quiescent currents. We now use board v3 with a bridge (connecting Vin to Vout for the designated 3.3V pod), and put a PowerPOD NCP1402 to transform incoming 3.6V from a SAFT battery to 5V.
There's a board v4 with a transistor to control the quiescent draw of either ultrasonic or PIR sensors.
This project runs through the workflow for bringing a network of OpenSensors workspace occupancy sensors online.
Installing Node Red
Import Node Red flow
Once you've booted up Node Red, click on the menu icon in the top right corner, click import. This will bring up a small window. Copy and paste the code from OpenSensors' github into this window and press OK. OpenSensors' desk sensor workflow should now have appeared.
Create a new OpenSensors topic for your Raspberry Pi hub
Before continuing, log in to OpenSensors.io and create a new Topic for your hub. Be sure to label your device as a hub, this will make it easier for you later on. For the unit of measurement, enter CM.
Editing the MQTT input node
Coming back to Node Red, you will see a range of coloured boxes, these are referred to as nodes. Identify the MQTT input node, the magenta node on the middle-left. Double click the MQTT input node. You should see three fields, broker, topic, name - in the topic field enter your OpenSensors hub topic path:
For example: /users/james/deskhub1/+
Note: Do not remove /+ at the end of the path, this refers to ‘all topics under this branch and is important to the functioning of the program.
Click the small pencil icon besides the broker field to bring up MQTT-broker config mode. You should see five fields, broker (should read: mqtt.opensensors.io), Port (should read: 1883), Client ID, Username and Password, these last three at this stage should be blank.
Create a new OpenSensors device for your Raspberry Pi hub
Without exiting Node Red, return to OpenSensors on another tab or window and create a new device for your Raspberry Pi hub. When you have created a new device, input the Client ID and Device Password of your new device into the Node Red fields - the username field is simply your OpenSensors username. Password refers to Device Password, not your OpenSensors account password. To continue press update followed by OK.
Review the MQTT output node
Now cast your eyes to the other MQTT node in the top right of the Node Red flow connected to extractSensorNames_Distances.
Double-click the node and click the pencil icon as before. Check the Client ID, username and password (password should not be visible) are the same as the previous node.
Edit extractSensorNames_Distances function node
Once completed, return to the flow and double-click the peach-coloured function node extractSensorNames_Distances, attached to that last MQTT node we just reviewed.
On line #4 of the large edit field is a topic path, replace the existing topic path with that of your own hub’s topic path, for example: /users/james/deskhub1/
Note: Take care not to delete or modify “+ result[1]; at the end of the path. This enables OpenSensors to dynamically create new topics for each of your publishing sensors.
Configure the Radio node
Return to the main Node Red flow. Identify the Radio node in the top left-hand corner. Open it and click the pencil icon. You should see a number of fields, replace the path in the Serial Port field with:
/dev/ttyAMA0
Additionally, change the Baud Rate to 9600 on the field below. These are the correct settings for the Raspberry Pi. When finished, press update and checking these settings were correctly submitted, return to the main work flow.
Deploy your Node Red flow
We’re nearly finished. Now you can deploy your flow. Press the Deploy button in the top right of the window (above the info/debug sidebar).
The Radio & MQTT nodes should show a green square and read “successful” or “connected”.
Congratulations, you’re now ready to deploy your sensors into the field.
Click debug on the sidebar below the Deploy button. Place a battery into one of your OpenSensors occupancy sensors.
Immediately the sensor will have sent a message to your Raspberry Pi indicating that it has started. Within one minute you will see a message containing a payload in the debug sidebar that should look like:
XXXCM123
The first three characters of the payload indicate the sensor’s new ID (for example: aFE), which is also immediately automatically created and published to OpenSensors.io under your My Topics page.
The next two characters, CM, are the unit of measurement taken by the sensor.
The remaining digits are the actual measurement taken by the sensor, in CM.
These payloads are publishing to your OpenSensors.io sensor topics and to your hub topic.
In another tab or window on your Raspberry Pi, open up:
You should see a list of your publishing devices and sensor sleep settings. You may also notice the LED attached to your sensor will blink once per minute as it publishes measurements to OpenSensors.io.
To find out more about how you can create a smart office environment feel free to pop an email to hello@opensensors.io
Comments