Ubidots Community

Script to send data from dht22 sensor (raspberry pi)

hello there,
i have a dht22 sensor connected to a raspberry pi. The connection is good as i execute the following code and i get temp and humidity results
import Adafruit_DHT

import time
import requests
import math
import random

TOKEN = “BBFF-xxxxx” # Put your TOKEN here
DEVICE_LABEL = “Raspberry” # Put your device label here
VARIABLE_LABEL_1 = “temperature” # Put your first variable label here
VARIABLE_LABEL_2 = “humidity” # Put your second variable label here
VARIABLE_LABEL_3 = “position” # Put your second variable label here

while True:
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)

while True:
r = requests.post(‘http://things.ubidots.com/api/v1.6/devices/raspberry/?token={BBFF-VxxxxxxV}’, data=temperature())
print(‘Posting temperatures in Ubidots’)

can you please provide me with the python scripi so i can upload temp and humidity results to ubidots (i have an account and i have the device connected)
Thanks in advance

Good day @tsagarjohn,

Thank you for sharing your case with the community.

If you have an Industrial (trial or licensed) or STEM account, the URL is industrial.api.ubidots.com instead of things.ubidots.com. Additionally you can refer to the following article to learn how to connect your Raspberry Pi with Ubidots cloud.

All the best,

thank you very much for your response.
the tutorial that you refer to, is in order to test the connection and send test data.
Is there a script to send the data from an already setup raspberry with dht22 sensor to my account to ubidots?
Thanks again.

Good day @tsagarjohn,

I hope all is well.

Unfortunately, there isn’t a specific tutorial to connect the dht22 sensor with the Raspberry Pi and send that data to Ubidots cloud. Nonetheless, with the base tutorial, you can learn how to send data and investigate how you should connect your sensor and read its value to then modify the example to send that value to an Ubidots device.

All the best,