Spaces:
Sleeping
Sleeping
Commit ·
f9ed3a9
1
Parent(s): ae81576
added node-red details
Browse filesFiles changed (6)
- gradio/README.md+6-1
- node-red/MQTT_InfluxDB_Example.pngAdded
- node-red/README.md+5
- notebooks/tests.ipynbDeleted-100
- requirements.txt-3
- streamlit/app.pyDeleted-51
1123456## Gradio App## Gradio App
This app is hosted on Hugging Face at the link below:https://huggingface.co/spaces/van-william/machine_monitoring
The Gradio app consists of the app.py file and makes use of gradio.Blocks() for a simpliied app creation framework12345678910111213
## Node Red IntegrationsNode-Red is used to query the current clamp and then write the data to the cloud (In this case MQTT and InfluxDB)
A high-level example of the MQTT and InfluxDB portion is shown below:
## MQTT- Here, I used the native MQTT connector to publish messages to my MQTT broker (In this case, HiveMQ)- I experimented with sending data in line protocol via MQTT but later opted to send data directly to InfluxDB via the Node-Red Module
## InfluxDB- For InfluxDB integrations, you can integrate via Telegraf and stream the MQTT messages in via Telegraf and parse to InfluxDB (This does not require anything on the Node Red side)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "import paho.mqtt.client as mqtt\n", "import pandas as pd\n", "import time\n", "from influxdb_client_3 import InfluxDBClient3\n", "import threading\n", "from datetime import datetime\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", "import os" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2}12343475paho-mqtt==2.1.0gradio==4.44.1gradio_client==1.3.0huggingface-hub==0.25.2pandas==2.2.3plotly==5.24.1requests==2.32.3influxdb3-python==0.9.0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import streamlit as stimport paho.mqtt.client as mqttimport pandas as pdimport plotly.graph_objs as gofrom influxdb_client_3 import InfluxDBClient3import osimport timeimport threading
# InfluxDB configurationINFLUXDB_URL = "https://us-east-1-1.aws.cloud2.influxdata.com/"INFLUXDB_TOKEN = os.getenv("INFLUXDB_TOKEN")INFLUXDB_ORG = "dd7895c825a7c36a"INFLUXDB_BUCKET = "machine_monitoring"
# MQTT configurationMQTT_BROKER = "broker.hivemq.com"MQTT_PORT = 1883MQTT_TOPIC = "test_fan"
# Global variablesdata_points = []MAX_DATA_POINTS = 100
# Initialize InfluxDB clientinflux_client = InfluxDBClient3(host=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG)
def query_influxdb(query): table = influx_client.query(query=query, database="machine_monitoring", language="sql") df = table.to_pandas().sort_values(by="time") return df
def main(): st.title("Data Visualization Dashboard")
# InfluxDB Query and Visualization st.header("Historical Data from InfluxDB") query = ''' SELECT * FROM "fan" WHERE time >= now() - interval '2 week' ''' df = query_influxdb(query) if not df.empty: st.line_chart(data=df, x='time', y='current') else: st.write("No historical data available for the past week.")
if __name__ == "__main__": main()gradio/README.md+6-1
node-red/MQTT_InfluxDB_Example.pngAdded

node-red/README.md+5
notebooks/tests.ipynbDeleted-100
requirements.txt-3
streamlit/app.pyDeleted-51