smart-buildings / mqttpublisher.py
akshayballal's picture
chore: Update file paths and dependencies
62fe9df
raw
history blame
682 Bytes
import paho.mqtt.client as mqtt
import time
import random
import pandas as pd
import json
clientId = "smartbuilding"
broker_address = "test.mosquito.org"
broker_port = 1883
df = pd.read_csv("data/demo_data2.csv")
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)
client.connect(broker_address, broker_port)
topic = "sensor_data"
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()