Python GUI application for displaying DHT11 Sensor Values

preview_player
Показать описание
Develop a Python GUI application for Implementing the MQTT subscribe operation to the given demo MQTT publish operation using Thingspeak Cloud.Connect either to 1) Raspberry Pi+Arduino+Digital Temperature Sensor(KY028)(OR) 2) Raspberry Pi+DHT11 Sensor.
Рекомендации по теме
Комментарии
Автор

#!/usr/bin/python3

import json
import sqlite3
import tkinter as tk

from matplotlib import animation
from matplotlib import pyplot as plt
from paho.mqtt import subscribe as sub
from import FigureCanvasTkAgg

require_info = dict()

# The ThingSpeak Channel ID.
# Replace <YOUR-CHANNEL-ID> with your channel ID.
CHANNELID = "1379680"

# The read API key for the channel.
# Replace <YOUR-CHANNEL-WRITEAPIKEY> with your write API key.
READAPIKEY = "4509YU9SIR82AAQE"

# The hostname of the ThingSpeak MQTT broker.
MQTTHOST = "mqtt.thingspeak.com"

# You can use any username.
MQTTUSERNAME =

# Your MQTT API key from Account > My Profile.
MQTTAPIKEY = "43GRWC90R8UAF2LE"

TTRANSPORT = "websockets"
TPORT = 80

# Create the topic string.
topic =

info = {'CHANNELID': CHANNELID, 'READAPIKEY': READAPIKEY,
'MQTTAPIKEY': MQTTAPIKEY, 'MQTTHOST': MQTTHOST,
'MQTTUSERNAME': MQTTUSERNAME, 'TTRANSPORT': TTRANSPORT,
'TPORT': TPORT, 'topic': topic}

con = sqlite3.connect('values.db') # Create database
print("Database created")

con.execute('''CREATE TABLE DATA
(ID INT PRIMARY KEY NOT NULL, TEMPERATURE REAL, HUMIDITY REAL)''') # Table created
print("Created Table")

def get_temp_and_humid_data():
global info, text, window
# List to store the values
temp, humid = list(), list()

i = 0
# Infinitly fetceh the data
while True:
i += 1
message = sub.simple(info['topic'], hostname= info['MQTTHOST'], auth={'username': info['MQTTUSERNAME'], 'password': info['MQTTAPIKEY']})
message =


# Inserting the data into table
print(f"Executed: INSERT INTO DATA (ID, TEMPERATURE, HUMIDITY) VALUES ({i}, {message['field1']}, {message['field2']})")
con.execute(f"INSERT INTO DATA (ID, TEMPERATURE, HUMIDITY) VALUES ({i}, {message['field1']}, {message['field2']})")
con.commit()
text.set("Latest Value fetched: Temp: %s, Humidity : %s\n" % (message["field1"], message["field2"]))
window.update()

# Create the window
window = tk.Tk()
window.title("Temperature and Humidity data from (Raspberry Pi + DHT11 Sensor)")
window.geometry("600x600")

# To display text value
text = tk.StringVar()
label = tk.Label(window, textvariable=text)

# Fetch and store data
try:
fetch = tk.Button(window, text="Fetch and Store Data", width=25,
fetch.pack()
except:
con.close()

# Close button
close = tk.Button(window, text="Close Window", width=25, command=window.destroy)
close.pack()

label.pack()

window.mainloop()

anuraganalog
Автор

Hello !!
Can You please send me your cod?

DungNguyen-tvjr
Автор

Hello! Can You please send me your code or a link to see it?

hughesphenom
Автор

Hello !! Can You please send me your cod?

ayoubessili
visit shbcf.ru