Kulshrest Tiwari
Published © GPL3+

Temperature monitoring

Monitor home temperature from anywhere using cloud

BeginnerFull instructions provided2 hours208
Temperature monitoring

Things used in this project

Hardware components

SB Components 2x2 Display Board Powered with ESP32 S3 WROOM-1 /Raspberry Pi Pico
×1

Software apps and online services

SB Components Thonn

Story

Read more

Code

main.py

Python
application code
from machine import Pin,SPI,I2C
import sdcard
import os
import bme280
import network
from time import sleep
from umqtt.simple import MQTTClient
i2c = I2C(0,scl=Pin(21), sda=Pin(20), freq=40000)
spi = SPI(0,sck=Pin(18),mosi=Pin(19),miso=Pin(16))
sd = sdcard.SDCard(spi,Pin(17))
bme = bme280.BME280(i2c=i2c)

vfs = os.VfsFat(sd)
os.mount(vfs,"/sd")
filename = "/sd/data_store.csv"
wlan = network.WLAN(network.STA_IF)
user = ""# wifi user name
password = ""# wifi password
wlan.active(True)
wlan.connect(user,password)
print(wlan.isconnected())
mqtt_host = "io.adafruit.com"
mqtt_user = "" adafruit username
mqtt_key = "" adafruit key
mqtt_topic = ""  # feed path
mqtt_client_id = "" #any unique name 

mqtt = MQTTClient(
    client_id = mqtt_client_id,
    server = mqtt_host,
    user= mqtt_user,
    password = mqtt_key)
mqtt.connect()
with open(filename,"w") as f:
        f.write("temperature,humidity,pressure \n")
for i in range (0,5):
    a = bme.temperature[:-1]
    mqtt.publish(mqtt_topic,a)
    a = str(bme.temperature)
    b = str(bme.humidity)
    c = str(bme.pressure)
    with open(filename,"a") as f:
        f.write(f"{a},{b},{c} \n")
        print("data print successfully")
    sleep(2)
with open(filename,"r") as f:
    print(f.read())  

os.umount("/sd")

Credits

Kulshrest Tiwari
5 projects • 2 followers
embedded sofware engineer
Contact

Comments

Please log in or sign up to comment.