In this training, you will learn the basics of the Internet of Things. In this part, you will learn how to visualize data acquired from an AHT10 temperature sensor.

Data acquisition from AHT10 sensor :

import time
import board
import adafruit_ahtx0

# Create sensor object, communicating over the board's default I2C bus
i2c = board.I2C()  # uses board.SCL and board.SDA
sensor = adafruit_ahtx0.AHTx0(i2c)

while True:
    print("\nTemperature: %0.1f C" % sensor.temperature)
    print("Humidity: %0.1f %%" % sensor.relative_humidity)
    time.sleep(2)

Send temperature data to the dashboard:

import time
import random
import requests
from requests.structures import CaseInsensitiveDict
import board
import adafruit_ahtx0


# Create sensor object, communicating over the board's default I2C bus
i2c = board.I2C()  # uses board.SCL and board.SDA
sensor = adafruit_ahtx0.AHTx0(i2c)

url = "https://demo.thingsboard.io/api/v1/your_device_access_token/telemetry/"

headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/json"

while True:
    temp = sensor.temperature
    print(temp)
    data = {"temperature": temp}
    resp = requests.post(url, headers=headers, data=str(data))
    time.sleep(5) 

 

0 comment

There are no comments yet.

Log in to leave a reply

Related posts

An Internet of Things Training Part 1: Getting Started

13/2/2022

Internet of Things Training Part 2: Programming of Raspberry PI GPIO

13/2/2022

Internet of Things Training Part 3: ThingsBoard IoT platform

14/2/2022