In this project, you will learn how to connect your Pi 4 to AllThingsTalk Cloud and send sensor data using Python. The OKdo cloud allows you to view your sensor data from any connected device like a browser or smartphone.
On your host computer go to allthingstalk.com and sign up for a free account. Once that is complete it will take you to the Playground page where you can set up your devices
• Select Devices and click +Connect A Device
OKdo uses the AllThingsTalk platform who provide a Python Library to make it easier to connect devices to the service.
git clone git://github.com/allthingstalk/python-sdk.git
This will clone AllThingsTalk Python SDK from Github
sudo pip3 install .
Everything is now setup to begin coding and sending data
#!/usr/bin/env python from time import sleep from sense_hat import SenseHat sense = SenseHat() sense.clear() import allthingstalk as talk class EnvironmentMonitor(talk.Device): temperature = talk.NumberAsset(unit='°C') humidity = talk.NumberAsset(unit='%') pressure = talk.NumberAsset(unit='mbar') client = talk.Client('maker:4UIYP67meScIW1VeVyLXq8lzob9vKf9IgZIDrSF') weather = EnvironmentMonitor(client=client, id='9E0myD30og7QLibUVGQChIuS') while True: weather.temperature = sense.get_temperature() weather.humidity = sense.get_humidity() weather.pressure = sense.get_pressure() sleep(5)
The Python client has place holders for the DEVICE TOKEN and DEVICE ID that must be replaced with the ones from your OKdo IoT Cloud account.
After a few seconds, the asset fields in your console should update every few seconds with your sensor readings
If the web page doesn’t update, refresh your browser to see the latest data. If all is well it should update every 5 seconds.
If that doesn’t work, try reloading the file into Thonny and running it again.
You should now have your Pi connected to the AllThingsTalk Cloud sending sensor readings for temperature, pressure and humidity every few seconds.
Using the principles learnt in this project you should be able to setup many different kinds of sensors connected to the Pi and send their data to the cloud.
Your data is accessible from other devices connected to the internet so you can access it from almost anywhere.
The OKdo service also has the ability to setup rules which can alert you if sensor readings reach a threshold value using web, email or push notifications.