Google Cloud IoT Projects
Uses arduino mkr1000 and supersonic sensor to measure standing desk height, sending information on sitting and standing durations to Google Cloud IoT Core and visualizing it on a real-time Dashboard (Python application backend and Python/Javascript frontend using Pusher API).
It also detects state changes (sitting -> standing and standing -> sitting) and logs them in a table displayed on the webpage.
Arduino project setup is available in this link:
https://www.hackster.io/vmehmeri/quantified-desk-iot-6647bf
(The project above mentions Azure IoT Hub, but the Arduino setup is the same)
As a pre-requisite, a Google Cloud IoT Core must be setup with a Cloud Pub/Sub Topic and Subscription for the device's telemetry data streaming. Your Arduino device will also require SSL certificates for connecting to IoT core's MQTT endpoint.
-
Instructions for setting up Google Cloud IoT Core: https://cloud.google.com/iot/docs/quickstart
-
Instructions for updating Firmware and adding SSL certificate to device: https://www.arduino.cc/en/Tutorial/FirmwareUpdater
This project was developed using Python 3.7.
Create a virtual environment with version 3.7 and install the packages below.
- google-cloud-pubsub
- pusher
- pusher
- flask
All can be installed with pip
- Ultrasonic
- WiFi101
- RTCZero
- WiFiUdp
- MQTT
- CloudIoTCore
- CloudIoTCoreMqtt
- jwt
All those libraries are already available in Arduino Web Editor. The latest code can also be accessed as a Web Editor sketch through the link below:
First edit config.py and configure your connection details and secret keys. You will need to create an account in Pusher and an application (it's free)
config.py (replace values):
from pusher import Pusher
pusher = Pusher(
app_id='APP_ID',
key = "KEY",
secret = "SECRET",
cluster = "CLUSTER",
ssl=True
)
## GCP Config
project_id = "PROJECT_ID"
topic_name = "projects/PROJECT_ID/topics/TOPIC"
subscription_name = "SUBSCRIPTION_NAME"
Start frontend
python app.py
On a separate terminal, start backend
python device_broker.py
Next open a browser pointing to localhost:5000 and you should see your dashboard.