{ "cells": [ { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\jerin\\AppData\\Local\\Temp\\ipykernel_4616\\2478473330.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" ] }, { "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[10], line 94\u001b[0m\n\u001b[0;32m 90\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m2\u001b[39m)\n\u001b[0;32m 93\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m---> 94\u001b[0m \u001b[43mpublish_sensor_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 95\u001b[0m \u001b[38;5;66;03m# time.sleep(0.1)\u001b[39;00m\n\u001b[0;32m 96\u001b[0m client\u001b[38;5;241m.\u001b[39mdisconnect()\n", "Cell \u001b[1;32mIn[10], line 90\u001b[0m, in \u001b[0;36mpublish_sensor_data\u001b[1;34m()\u001b[0m\n\u001b[0;32m 55\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 56\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 57\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 87\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 88\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 89\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---> 90\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m2\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(\"sample_data_smooth_01.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 index, row in df.iterrows():\n", " hp_hws_temp = row['hp_hws_temp']\n", " rtu_003_sa_temp = row['rtu_003_sa_temp']\n", " rtu_003_oadmpr_pct = row['rtu_003_oadmpr_pct']\n", " rtu_003_ra_temp = row['rtu_003_ra_temp']\n", " rtu_003_oa_temp = row['rtu_003_oa_temp']\n", " rtu_003_ma_temp = row['rtu_003_ma_temp']\n", " rtu_003_sf_vfd_spd_fbk_tn = row['rtu_003_sf_vfd_spd_fbk_tn']\n", " rtu_003_rf_vfd_spd_fbk_tn =row['rtu_003_rf_vfd_spd_fbk_tn']\n", " rtu_004_sa_temp = row['rtu_004_sa_temp']\n", " rtu_004_oadmpr_pct = row['rtu_004_oadmpr_pct']\n", " rtu_004_ra_temp = row['rtu_004_ra_temp']\n", " rtu_004_oa_temp = row['rtu_004_oa_temp']\n", " rtu_004_ma_temp = row['rtu_004_ma_temp']\n", " rtu_004_sf_vfd_spd_fbk_tn = row['rtu_004_sf_vfd_spd_fbk_tn']\n", " rtu_004_rf_vfd_spd_fbk_tn = row['rtu_004_rf_vfd_spd_fbk_tn']\n", " rtu_001_sa_temp = row['rtu_001_sa_temp']\n", " rtu_001_oadmpr_pct = row['rtu_001_oadmpr_pct']\n", " rtu_001_ra_temp = row['rtu_001_ra_temp']\n", " rtu_001_oa_temp = row['rtu_001_oa_temp']\n", " rtu_001_ma_temp = row['rtu_001_ma_temp']\n", " rtu_001_sf_vfd_spd_fbk_tn = row['rtu_001_sf_vfd_spd_fbk_tn']\n", " rtu_001_rf_vfd_spd_fbk_tn =row['rtu_001_rf_vfd_spd_fbk_tn']\n", " rtu_002_sa_temp = row['rtu_002_sa_temp']\n", " rtu_002_oadmpr_pct = row['rtu_002_oadmpr_pct']\n", " rtu_002_ra_temp = row['rtu_002_ra_temp']\n", " rtu_002_oa_temp = row['rtu_002_oa_temp']\n", " rtu_002_ma_temp = row['rtu_002_ma_temp']\n", " rtu_002_sf_vfd_spd_fbk_tn = row['rtu_002_sf_vfd_spd_fbk_tn']\n", " rtu_002_rf_vfd_spd_fbk_tn = row['rtu_002_rf_vfd_spd_fbk_tn']\n", " rtu_004_sat_sp_tn = row['rtu_004_sat_sp_tn']\n", " rtu_003_sat_sp_tn = row['rtu_003_sat_sp_tn']\n", " rtu_001_sat_sp_tn = row['rtu_001_sat_sp_tn']\n", " rtu_002_sat_sp_tn = row['rtu_002_sat_sp_tn']\n", " air_temp_set_1 = row['air_temp_set_1']\n", " air_temp_set_2 = row['air_temp_set_2']\n", " dew_point_temperature_set_1d = row['dew_point_temperature_set_1d']\n", " relative_humidity_set_1 = row['relative_humidity_set_1']\n", " solar_radiation_set_1 = row['solar_radiation_set_1']\n", " \n", " \n", " client.publish(topic, payload=json.dumps({'hp_hws_temp':hp_hws_temp,\n", " 'rtu_003_sa_temp':rtu_003_sa_temp,\n", " 'rtu_003_oadmpr_pct': rtu_003_oadmpr_pct,\n", " 'rtu_003_ra_temp':rtu_003_ra_temp,\n", " 'rtu_003_oa_temp': rtu_003_oa_temp,\n", " 'rtu_003_ma_temp': rtu_003_ma_temp,\n", " 'rtu_003_sf_vfd_spd_fbk_tn': rtu_003_sf_vfd_spd_fbk_tn,\n", " 'rtu_003_rf_vfd_spd_fbk_tn':rtu_003_rf_vfd_spd_fbk_tn,\n", " 'rtu_004_sa_temp':rtu_004_sa_temp,\n", " 'rtu_004_oadmpr_pct':rtu_004_oadmpr_pct,\n", " 'rtu_004_ra_temp':rtu_004_ra_temp,\n", " 'rtu_004_oa_temp':rtu_004_oa_temp,\n", " 'rtu_004_ma_temp':rtu_004_ma_temp,\n", " 'rtu_004_sf_vfd_spd_fbk_tn':rtu_004_sf_vfd_spd_fbk_tn,\n", " 'rtu_004_rf_vfd_spd_fbk_tn':rtu_004_rf_vfd_spd_fbk_tn,\n", " 'rtu_001_sa_temp':rtu_001_sa_temp,\n", " 'rtu_001_oadmpr_pct': rtu_001_oadmpr_pct,\n", " 'rtu_001_ra_temp':rtu_001_ra_temp,\n", " 'rtu_001_oa_temp': rtu_001_oa_temp,\n", " 'rtu_001_ma_temp': rtu_001_ma_temp,\n", " 'rtu_001_sf_vfd_spd_fbk_tn': rtu_001_sf_vfd_spd_fbk_tn,\n", " 'rtu_001_rf_vfd_spd_fbk_tn':rtu_001_rf_vfd_spd_fbk_tn,\n", " 'rtu_002_sa_temp':rtu_002_sa_temp,\n", " 'rtu_002_oadmpr_pct':rtu_002_oadmpr_pct,\n", " 'rtu_002_ra_temp':rtu_002_ra_temp,\n", " 'rtu_002_oa_temp':rtu_002_oa_temp,\n", " 'rtu_002_ma_temp':rtu_002_ma_temp,\n", " 'rtu_002_sf_vfd_spd_fbk_tn':rtu_002_sf_vfd_spd_fbk_tn,\n", " 'rtu_002_rf_vfd_spd_fbk_tn':rtu_002_rf_vfd_spd_fbk_tn,\n", " 'rtu_004_sat_sp_tn':rtu_004_sat_sp_tn,\n", " 'rtu_003_sat_sp_tn' :rtu_003_sat_sp_tn,\n", " 'rtu_001_sat_sp_tn':rtu_001_sat_sp_tn,\n", " 'rtu_002_sat_sp_tn':rtu_002_sat_sp_tn,\n", " 'air_temp_set_1':air_temp_set_1,\n", " 'air_temp_set_2':air_temp_set_2,\n", " 'dew_point_temperature_set_1d':dew_point_temperature_set_1d,\n", " 'relative_humidity_set_1':relative_humidity_set_1,\n", " 'solar_radiation_set_1':solar_radiation_set_1}))\n", " print(\"published!\")\n", " time.sleep(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 }