{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\arbal\\AppData\\Local\\Temp\\ipykernel_20872\\3033510885.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" ] } ], "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(\"data/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(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 }