{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\jerin\\AppData\\Local\\Temp\\ipykernel_18680\\2251714346.py:13: DeprecationWarning: Callback API version 1 is deprecated, update to latest version\n", " client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)\n" ] }, { "ename": "KeyboardInterrupt", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[1], line 28\u001b[0m\n\u001b[0;32m 26\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m 27\u001b[0m publish_sensor_data()\n\u001b[1;32m---> 28\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m5\u001b[39m)\n\u001b[0;32m 29\u001b[0m client\u001b[38;5;241m.\u001b[39mdisconnect()\n", "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ "import paho.mqtt.client as mqtt\n", "import time\n", "import random\n", "import pandas as pd\n", "import json\n", "\n", "clientId = \"smartbuilding\"\n", "broker_address = \"localhost\"\n", "broker_port = 1883\n", "\n", "df = pd.read_csv(\"buildingdata.csv\")\n", "\n", "client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)\n", "client.connect(broker_address, broker_port)\n", "topic = \"sensor_data\"\n", "\n", "def publish_sensor_data():\n", " # temp = round(random.uniform(20, 30), 2) \n", " # pressure = round(random.uniform(900, 1100), 2) \n", " for index, row in df.iterrows():\n", " sa_temp = row['rtu_004_sa_temp']\n", " ma_temp = row['rtu_004_ma_temp']\n", " client.publish(topic, payload=json.dumps({\"sa_temp\": sa_temp, \"ma_temp\": ma_temp}))\n", "\n", "\n", "while True:\n", " publish_sensor_data()\n", " time.sleep(5)\n", "client.disconnect()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "smartbuilding", "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.11.8" } }, "nbformat": 4, "nbformat_minor": 2 }