This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Importing the modules | |
# ----------------------------------------------------------------------------- | |
import dash | |
from dash import html, dcc, Input, Output | |
import dash_bootstrap_components as dbc | |
import paho.mqtt.client as mqtt | |
global current_temperature | |
current_temperature = "NaN" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import paho.mqtt.client as mqtt | |
import Adafruit_DHT | |
# MQTT Client | |
mqttc = mqtt.Client() | |
mqttc.connect("mqtt.eclipseprojects.io", 1883, 60) | |
# DHT11 sensor data | |
dht11_sensor = Adafruit_DHT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Main function | |
# ----------------------------------------------------------------------------- | |
if __name__ == "__main__": | |
app.run_server(debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Callback for updating temperature data | |
# ----------------------------------------------------------------------------- | |
@app.callback( | |
Output('temperature', 'children'), | |
Input('update', 'n_intervals') | |
) | |
def update_temperature(timer): | |
return ("Temperature: " + str(current_temperature)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Application layout | |
# ----------------------------------------------------------------------------- | |
app.layout = dbc.Container( | |
[ | |
dcc.Interval(id='update', n_intervals=0, interval=1000*3), | |
html.H1("Monitoring IoT Sensor Data with Plotly Dash"), | |
html.Hr(), | |
dbc.Row(dbc.Col(card, lg=4)) | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Temperature card | |
# ----------------------------------------------------------------------------- | |
card = dbc.Card( | |
html.H4(id="temperature") | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Defining Dash app | |
# ----------------------------------------------------------------------------- | |
app = dash.Dash(external_stylesheets=[dbc.themes.DARKLY]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# MQTT Subscribe | |
# ----------------------------------------------------------------------------- | |
mqttc = mqtt.Client() | |
mqttc.connect("mqtt.eclipseprojects.io", 1883, 60) | |
def on_connect(client, userdata, flags, rc): | |
print("Connected with result code "+str(rc)) | |
mqttc.subscribe("myroom/temperature") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Importing the modules | |
# ----------------------------------------------------------------------------- | |
import dash | |
from dash import html, dcc, Input, Output | |
import dash_bootstrap_components as dbc | |
import paho.mqtt.client as mqtt | |
global current_temperature | |
current_temperature = "NaN" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paho.mqtt.client as mqtt | |
def on_connect(client, userdata, flags, rc): | |
print("Connected with result code "+str(rc)) | |
mqttc.subscribe("myroom/temperature") | |
def on_message(client, userdata, msg): | |
print("Received:", msg.payload.decode()) | |
mqttc = mqtt.Client() |
NewerOlder