Spaces:
Sleeping
Sleeping
File size: 682 Bytes
2bc71f8 736c64e 2bc71f8 b911d24 62fe9df 2bc71f8 62fe9df |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import paho.mqtt.client as mqtt
import time
import random
import pandas as pd
import json
clientId = "smartbuilding"
broker_address = "test.mosquitto.org"
broker_port = 1883
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)
client.connect(broker_address, broker_port)
topic = "sensor_data"
df = pd.read_csv("data/demo_data2.csv")
def publish_sensor_data():
for i in range(len(df)):
data = {}
for col in df.columns:
data[col] = df[col][i]
client.publish(topic, payload=json.dumps(data))
print("published!")
time.sleep(0.2)
while True:
publish_sensor_data()
# time.sleep(0.1)
client.disconnect()
|