Story
At thethings.iO we want to show you different ways of using our platform for your projects and products! For this reason, we have developed a prototype using a Raspberry Pi and our REST API to monitor the access to a room.
The device, that should be embedded next to the door as you will see on the next pictures, uses an ultrasonic sensor to publish the distance to the closest wall (if any) every 10 seconds. When the door is opened by someone, the measured distance is shortened due the blocking door. The device will automatically report the incident to the thethings.iO cloud but it will allow the user to manually enter an access code to specify that the access was allowed.
Just for having fun, the sensorās distance is continuously sent so we can visualize its fluctuations in real time at thethings.iO panel. Itās easily distinguished on the following graph when someone has entered, donāt you think?
In addition, the device has four buttons, two for entering a code, one to shut it down and the last one to memorize the ānormal distanceā i.e. the deviceās distance to the closest obstacle when the door is shut. To perform the last two actions, entering a password is required.
Also, two LEDs show some feedback to the user. When the leds blink, they show that the device is memorizing a new distance. When both leds are on, a password can be entered.
Getting into the code!
To write a value toĀ thethings.iOĀ you first need to get a token that identifies your āthingā and allows it to use the cloud. To get a token you need a thethings.iO account (you get three tokens with a free account). Once you have the account, you need to activate the token, which can be done from the same thethings.iO website and just requires you to press a button. You can find detailed instructions here.
In this project, the activated token should be hard-written into the code, specifically inside the variable ātokenā of the fileĀ ttrest.py.Ā From now on,Ā writing to the cloud is as easy as calling the function ttwrite where the first parameter is the name of the variable that we want to write to and the second parameter is the actual value.
d = tt.get_distance() #retrieve distance from ultrasonic sensor
ttrest.ttwrite('Distance', str(d)) # write data to thethings.iO
Your turn!
Do you like it? Why donāt you try to do your own project with theĀ thethings.iOĀ service? Itās free for the first three devices! š
For more detail: Connecting a Door with Raspberry Pi and thethings.iO