.
The problem is: how our workspace being utilised? Can we save cost by optimising our space? Do we have enough meeting rooms?
I will build a system which can measure, manage, and optimize workplace occupancy, with proximity sensors and cloud analytics.
Proximity sensors are used to detected the presence of people at the workplace and track workplace occupancy. Reports and analytics of workplace will be presented in the form of dashboard.
.
Setup Pyro Sensor with MKR1000.
Follow the blog Pyro Switch: Hidden IR Detection, I use the same schematic and circuit diagram to build this project. The code is included in the code section.
.
.
I am using a name card plastic case as the enclosure of the Pyro sensor.
.
A video showing the working of Pyro sensor with MKR1000:
.
Platform: dweet.io.
The sensor sends the data to the cloud by "dweeting" to dweet.io. Sending data is very simple. No setup or no configuration. Just call an URL like what I used:
https://dweet.io/dweet/for/my-pyro-sensor?pyro=[on|off]
I name my sensor as my-pyro-senso
r and query parameter pyro
which indicate the occupancy of a particular workspace.
To read the lasted dweet from my sensor, I just call:
http://dweet.io/get/latest/dweet/for/my-pyro-sensor
which will response with something similar to:
{"this":"succeeded","by":"getting","the":"dweets","with":[{"thing":"my-pyro-sensor","created":"2020-02-29T05:10:31.766Z","content":{"pyro":"on"}}]}
.
Platform: ThingsBoard.
ThingsBoard
is an open-source IoT Platform for data collection, processing, visualization and device management.
You can install an instance to your local machine. But I am using the free cloud version: demo.thingsboard.io
.
You need to sign up and create an account:
.
Add Assets and Devices:
.
Establishing relations between assets and devices:
.
Here you can view the latest telemetry of a device:
.
.
.
Here is the ThingsBoard dash with 2 temperature sensors and 3 Pyro sensors. All temperture sensors' data are generated from device emulation created in ThingsBoard. The first Pyro sensor's data is pushed from the sensor from the setup above; the others are from device emulation.
.
This is the detail page of the temperature sensor showing current temperature, history and alarms.
.
Here is ThingsBoard dashboard showing the live Pyro sensor: Worx PS-1, which is the first one in the list on the right of the dashboard. You can see that the on/off
is in sync with the LED.
.
The Code.
The following is the code that send data to dweet.io:
void dweet(int onOff) {
String command = "GET /dweet/for/my-pyro-sensor?pyro=";
command += onOff ? "on" : "off";
command += " HTTP/1.1";
Serial.println("\nStarting connection to dweet.io...");
// if you get a connection, report back via serial:
if (client.connect(dweet_server, 80)) {
Serial.println("connected to server");
// Make a HTTP request:
// client.println("GET /dweet/for/my-pyro-sensor?pyro=on HTTP/1.1");
client.println(command);
client.println("Host: dweet.io");
client.println("Connection: close");
client.println();
delay(2000);
while (client.available()) { // Print on the console the answer of the server
char c = client.read();
Serial.write(c);
}
client.stop(); // Disconnect from the server
}
}
.
And this send data to ThingsBoard:
void post_thingsboard(int onOff) {
String command = String("POST /api/v1/") + THINGSBOARD_TOKEN + "/telemetry HTTP/1.1";
String data = String("{ \"pyro\": \"");
data += onOff ? "on" : "off";
data += "\" }";
Serial.println("\nStarting connection to demo.thingsboard.io...");
// if you get a connection, report back via serial:
if (client.connect(thingsboard_server, 80)) {
Serial.println("connected to server");
Serial.println(command);
Serial.println(data);
Serial.println(data.length());
// Make a HTTP request:
client.println(command);
client.print("Host: "); client.println(thingsboard_server);
client.print("Content-Length: "); client.println(data.length());
client.println("Connection: close");
client.println("Content-Type:application/json");
client.println();
client.println(data);
client.println();
delay(2000);
while (client.available()) { // Print on the console the answer of the server
char c = client.read();
Serial.write(c);
}
// client.stop(); // Disconnect from the server
}
}
.
Summary.
Clearly this project lacks of a lot of features. It show only how to push Pyro sensor data to the cloud via MKR1000, and data collection and visualization presented with ThingsBoard dash board.
Other features such as reports and analytics, measurement and tracking of workplace occupancy which will help to improve cost and space optimization of workplace.
As for the sensor, further adjustment and calibration are requried to make the more accurate readings.
.
Useful linksMake Sense of the Proximity Sensor
Pyro Switch: Hidden IR Detection
.
Comments