This is a Project in connection with the course "IoT Ecosystems" which took place at the Esslingen University of Applied Sciences in the Winter Semester 2017/18.The idea
If you ask google for a particular place like a fitness studio, a restaurant or a store, it most likely will give you a small diagram, telling you about frequencies of people visiting the store. The diagram is based on tracking data from their smartphones.
We wanted to build a prototype, which gives us a more precise information on how many people are actually visiting a fitness studio, a store, a hairdresser, or any other particular room, hall or building.
To provide this information to everyone interested , we will publish this information online.The board
The particle photon was our choice due to the nice web IDE and the ability to flash the device OTA. We attached two IR Units for both, sending ad receiving IR signals to detect motion.
The sensors are connected to the analog inputs of the photon. Each sensor has its own ISR (interrupt service routine) to handle the events which are fired when the voltage of the analog input changes (movement is detected).
So, why do we have two sensors? Because we want to know if someone is entering, or leaving our room. We recognize this by the order in which the sensors detect movement.
Beside the sensors, there is a LED indicating the state of the counter. This is helpful for debug and testing.
To increase or decrease the counter, we need to track the state of our two sensors. The question is, if a ISR is activated, is a person actually entering, or leaving the room? To figure this out, we need some kind of a state machine, which always reflects a particular state. In our case, we have three simple states:
- Nothing happens
- Someone coming (s0)
- Someone going (s1)
Now, we can count persons coming, or leaving by simply in- or decreasing a variable.
As of now, we do not know about how many people in total are in that room. We decided to keep this information 'in the cloud', not on the photon board. Why? First, that makes it easier to handle a room with more than one door. And if a photon has to restart, we wont loose the total number of persons in that room.Communication with Losant
Next step is to publish our Counter to Losant. We will do this using MQTT, since Losant has a build in MQTT Broker which allow us to publish messages.
As a security measure, we need to allow a MQTT client to push to a particular Losant application. This means:
- You have to create a Losant application (read this)
- Create a device (read this)
- Create a access key (read this)
- Insert the access key, secret and your device id into the code.
Business logic at losant
#define DEVICE "<device id from losant>" // ID Of my Device #define ACCESS "<access key from losant>" #define SECRET "<access secret from losant>" #define TOPIC "losant/<device id from losant>/state"
Now it is time for the counter, we will
- Save a total for a room
- Add logic to increase or decrease that total
- Add a second device, to update the dash board.
Therefore we need to
- create a data table, (read this)
- and a workflow (read this)
The data table should have two column (beside the default columns):
- total with datatype number
- device with data type string
The workflow should look like this:
The workflow gets the offset from the photon, gets the total from our data table, calculates the new total, and writes it back to the table. Then our 'total' device is triggered, to update the dashboard.
You can import this workflow, the file is attached. You can read on how to import a workflow here.Displaying data
The dashboard shows the current number of people in the room. If someone enters or leaves the room, the dashboard will indicate this by increasing or decreasing the number displayed. Lean on how to use the dashboard here