{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\arbal\\AppData\\Local\\Temp\\ipykernel_1472\\1157986887.py:13: DeprecationWarning: Callback API version 1 is deprecated, update to latest version\n", " client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, clientId)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\n", "published!\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[2], line 102\u001b[0m\n\u001b[0;32m 98\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m0.2\u001b[39m)\n\u001b[0;32m 101\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m--> 102\u001b[0m \u001b[43mpublish_sensor_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 103\u001b[0m \u001b[38;5;66;03m# time.sleep(0.1)\u001b[39;00m\n\u001b[0;32m 104\u001b[0m client\u001b[38;5;241m.\u001b[39mdisconnect()\n", "Cell \u001b[1;32mIn[2], line 98\u001b[0m, in \u001b[0;36mpublish_sensor_data\u001b[1;34m()\u001b[0m\n\u001b[0;32m 59\u001b[0m client\u001b[38;5;241m.\u001b[39mpublish(topic, payload\u001b[38;5;241m=\u001b[39mjson\u001b[38;5;241m.\u001b[39mdumps({\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhp_hws_temp\u001b[39m\u001b[38;5;124m'\u001b[39m:hp_hws_temp,\n\u001b[0;32m 60\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrtu_003_sa_temp\u001b[39m\u001b[38;5;124m'\u001b[39m:rtu_003_sa_temp,\n\u001b[0;32m 61\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrtu_003_oadmpr_pct\u001b[39m\u001b[38;5;124m'\u001b[39m: rtu_003_oadmpr_pct,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrelative_humidity_set_1\u001b[39m\u001b[38;5;124m'\u001b[39m:relative_humidity_set_1,\n\u001b[0;32m 96\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msolar_radiation_set_1\u001b[39m\u001b[38;5;124m'\u001b[39m:solar_radiation_set_1}))\n\u001b[0;32m 97\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpublished!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 98\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m0.2\u001b[39m)\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(r\"sample_test_data.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", " for i in range(len(df)):\n", "\n", " data = {}\n", " for col in df.columns:\n", " data[col] = df[col][i]\n", "\n", " \n", " client.publish(topic, payload=json.dumps(data))\n", " print(\"published!\")\n", " time.sleep(0.2)\n", "\n", "\n", "while True:\n", " publish_sensor_data()\n", " # time.sleep(0.1)\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 }