Blog

Publish a Sensor Reading using the Wia Python SDK

Creating a device and publishing sensor data to the cloud has never been easier. Follow these simple steps and get up and running in a few minutes.

Install the Wia Python SDK

In order to use the Wia Python SDK, you will first need to install it. This can be accomplished by running the command ‘pip install wia’ in your command line.

Create your Device

Go to the Wia dashboard and select Devices. From here, click on the + symbol and the Add New Device modal will appear. Enter ‘Temperature Device’ as the name and click Add Device. Click on View device to go to the device's overview page. Take a note of the device's secret key, we'll need this later.

Write code to publish sensor reading

Create a file called “sensor_device.py” using command “nano sensor_device.py”. This will open our text editor where we will write our code. Insert the following code (replace 'device-secret-key' with your device secret key from the wia dashboard):

import wia

wia.secret_key = 'device-secret-key'
wia.Stream.connect()

t = 21

while True:
  wia.Sensor.publish(
    name="temperature",
    data=t
  )

Test the application

Save the code and run it by running the command “python sensor_device.py” in the console. Go to the Sensors tab of your device in the Wia dashboard to see the published readings from your device.

Ready to get started?
Talk to our sales team or setup an account.