{ "cells": [ { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\jerin\\AppData\\Local\\Temp\\ipykernel_3260\\368714138.py:22: DeprecationWarning: Callback API version 1 is deprecated, update to latest version\n", " client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'date': '2018-05-02 00:09:00', 'hp_hws_temp': 96.3, 'rtu_003_sa_temp': 64.2, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.5, 'rtu_003_oa_temp': 61.6, 'rtu_003_ma_temp': 63.5, 'rtu_003_sf_vfd_spd_fbk_tn': 77.8, 'rtu_003_rf_vfd_spd_fbk_tn': 54.3, 'rtu_004_sa_temp': 68.9, 'rtu_004_oadmpr_pct': 54.2, 'rtu_004_ra_temp': 73.3, 'rtu_004_oa_temp': 67.4, 'rtu_004_ma_temp': 67.6, 'rtu_004_sf_vfd_spd_fbk_tn': 75.7, 'rtu_004_rf_vfd_spd_fbk_tn': 78.3, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n", "{'date': '2018-05-02 00:10:00', 'hp_hws_temp': 97.0, 'rtu_003_sa_temp': 64.1, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.4, 'rtu_003_oa_temp': 61.9, 'rtu_003_ma_temp': 63.3, 'rtu_003_sf_vfd_spd_fbk_tn': 77.2, 'rtu_003_rf_vfd_spd_fbk_tn': 52.5, 'rtu_004_sa_temp': 68.8, 'rtu_004_oadmpr_pct': 80.6, 'rtu_004_ra_temp': 73.3, 'rtu_004_oa_temp': 68.2, 'rtu_004_ma_temp': 66.1, 'rtu_004_sf_vfd_spd_fbk_tn': 75.6, 'rtu_004_rf_vfd_spd_fbk_tn': 67.3, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n", "{'date': '2018-05-02 00:11:00', 'hp_hws_temp': 97.6, 'rtu_003_sa_temp': 64.1, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.4, 'rtu_003_oa_temp': 62.0, 'rtu_003_ma_temp': 63.8, 'rtu_003_sf_vfd_spd_fbk_tn': 78.2, 'rtu_003_rf_vfd_spd_fbk_tn': 56.7, 'rtu_004_sa_temp': 67.3, 'rtu_004_oadmpr_pct': 76.6, 'rtu_004_ra_temp': 73.4, 'rtu_004_oa_temp': 68.6, 'rtu_004_ma_temp': 64.3, 'rtu_004_sf_vfd_spd_fbk_tn': 78.6, 'rtu_004_rf_vfd_spd_fbk_tn': 77.5, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n", "{'date': '2018-05-02 00:12:00', 'hp_hws_temp': 98.3, 'rtu_003_sa_temp': 64.2, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.4, 'rtu_003_oa_temp': 62.1, 'rtu_003_ma_temp': 64.1, 'rtu_003_sf_vfd_spd_fbk_tn': 76.4, 'rtu_003_rf_vfd_spd_fbk_tn': 52.9, 'rtu_004_sa_temp': 66.7, 'rtu_004_oadmpr_pct': 51.4, 'rtu_004_ra_temp': 73.4, 'rtu_004_oa_temp': 68.9, 'rtu_004_ma_temp': 65.1, 'rtu_004_sf_vfd_spd_fbk_tn': 79.6, 'rtu_004_rf_vfd_spd_fbk_tn': 82.5, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n", "{'date': '2018-05-02 00:13:00', 'hp_hws_temp': 98.9, 'rtu_003_sa_temp': 64.3, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.3, 'rtu_003_oa_temp': 62.2, 'rtu_003_ma_temp': 63.8, 'rtu_003_sf_vfd_spd_fbk_tn': 78.5, 'rtu_003_rf_vfd_spd_fbk_tn': 57.0, 'rtu_004_sa_temp': 67.8, 'rtu_004_oadmpr_pct': 52.4, 'rtu_004_ra_temp': 73.4, 'rtu_004_oa_temp': 68.9, 'rtu_004_ma_temp': 67.8, 'rtu_004_sf_vfd_spd_fbk_tn': 78.3, 'rtu_004_rf_vfd_spd_fbk_tn': 73.9, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n", "{'date': '2018-05-02 00:14:00', 'hp_hws_temp': 99.3, 'rtu_003_sa_temp': 64.4, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.4, 'rtu_003_oa_temp': 62.5, 'rtu_003_ma_temp': 63.9, 'rtu_003_sf_vfd_spd_fbk_tn': 75.9, 'rtu_003_rf_vfd_spd_fbk_tn': 49.8, 'rtu_004_sa_temp': 68.8, 'rtu_004_oadmpr_pct': 52.4, 'rtu_004_ra_temp': 73.3, 'rtu_004_oa_temp': 68.1, 'rtu_004_ma_temp': 68.3, 'rtu_004_sf_vfd_spd_fbk_tn': 76.5, 'rtu_004_rf_vfd_spd_fbk_tn': 74.7, 'air_temp_set_1': 14.9, 'air_temp_set_2': 14.44, 'dew_point_temperature_set_1d': 7.02, 'relative_humidity_set_1': 59.5, 'solar_radiation_set_1': 335.9}\n", "{'date': '2018-05-02 00:15:00', 'hp_hws_temp': 99.0, 'rtu_003_sa_temp': 63.9, 'rtu_003_oadmpr_pct': 88.4, 'rtu_003_ra_temp': 72.3, 'rtu_003_oa_temp': 62.6, 'rtu_003_ma_temp': 63.6, 'rtu_003_sf_vfd_spd_fbk_tn': 74.3, 'rtu_003_rf_vfd_spd_fbk_tn': 53.5, 'rtu_004_sa_temp': 69.1, 'rtu_004_oadmpr_pct': 79.0, 'rtu_004_ra_temp': 73.3, 'rtu_004_oa_temp': 67.2, 'rtu_004_ma_temp': 66.6, 'rtu_004_sf_vfd_spd_fbk_tn': 75.3, 'rtu_004_rf_vfd_spd_fbk_tn': 69.0, 'air_temp_set_1': 16.0, 'air_temp_set_2': 15.48, 'dew_point_temperature_set_1d': 6.63, 'relative_humidity_set_1': 54.0, 'solar_radiation_set_1': 426.3}\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[6], line 26\u001b[0m\n\u001b[0;32m 24\u001b[0m client\u001b[38;5;241m.\u001b[39mconnect(broker_address, broker_port)\n\u001b[0;32m 25\u001b[0m client\u001b[38;5;241m.\u001b[39msubscribe(topic)\n\u001b[1;32m---> 26\u001b[0m \u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mloop_forever\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[1;32mc:\\Users\\jerin\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\paho\\mqtt\\client.py:2291\u001b[0m, in \u001b[0;36mClient.loop_forever\u001b[1;34m(self, timeout, retry_first_connection)\u001b[0m\n\u001b[0;32m 2289\u001b[0m rc \u001b[38;5;241m=\u001b[39m MQTTErrorCode\u001b[38;5;241m.\u001b[39mMQTT_ERR_SUCCESS\n\u001b[0;32m 2290\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m rc \u001b[38;5;241m==\u001b[39m MQTTErrorCode\u001b[38;5;241m.\u001b[39mMQTT_ERR_SUCCESS:\n\u001b[1;32m-> 2291\u001b[0m rc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_loop\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 2292\u001b[0m \u001b[38;5;66;03m# We don't need to worry about locking here, because we've\u001b[39;00m\n\u001b[0;32m 2293\u001b[0m \u001b[38;5;66;03m# either called loop_forever() when in single threaded mode, or\u001b[39;00m\n\u001b[0;32m 2294\u001b[0m \u001b[38;5;66;03m# in multi threaded mode when loop_stop() has been called and\u001b[39;00m\n\u001b[0;32m 2295\u001b[0m \u001b[38;5;66;03m# so no other threads can access _out_packet or _messages.\u001b[39;00m\n\u001b[0;32m 2296\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_thread_terminate \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m 2297\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_out_packet) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m 2298\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_out_messages) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m):\n", "File \u001b[1;32mc:\\Users\\jerin\\anaconda3\\envs\\smartbuilding\\Lib\\site-packages\\paho\\mqtt\\client.py:1657\u001b[0m, in \u001b[0;36mClient._loop\u001b[1;34m(self, timeout)\u001b[0m\n\u001b[0;32m 1654\u001b[0m rlist \u001b[38;5;241m=\u001b[39m [\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sock, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sockpairR]\n\u001b[0;32m 1656\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 1657\u001b[0m socklist \u001b[38;5;241m=\u001b[39m select\u001b[38;5;241m.\u001b[39mselect(rlist, wlist, [], timeout)\n\u001b[0;32m 1658\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[0;32m 1659\u001b[0m \u001b[38;5;66;03m# Socket isn't correct type, in likelihood connection is lost\u001b[39;00m\n\u001b[0;32m 1660\u001b[0m \u001b[38;5;66;03m# ... or we called disconnect(). In that case the socket will\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1663\u001b[0m \u001b[38;5;66;03m# rc != MQTT_ERR_SUCCESS and we don't want state to change from\u001b[39;00m\n\u001b[0;32m 1664\u001b[0m \u001b[38;5;66;03m# mqtt_cs_disconnecting.\u001b[39;00m\n\u001b[0;32m 1665\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m (_ConnectionState\u001b[38;5;241m.\u001b[39mMQTT_CS_DISCONNECTING, _ConnectionState\u001b[38;5;241m.\u001b[39mMQTT_CS_DISCONNECTED):\n", "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ "import paho.mqtt.client as mqtt\n", "import json\n", "import pandas as pd\n", "\n", "broker_address = \"localhost\"\n", "broker_port = 1883\n", "topic = \"sensor_data\"\n", "\n", "df = pd.DataFrame(columns=[\"sa_temp\", \"ma_temp\"])\n", "\n", "def on_message(client, userdata, message):\n", " global df\n", " payload = json.loads(message.payload.decode())\n", " # sa_temp = payload[\"sa_temp\"]\n", " # ma_temp = payload[\"ma_temp\"]\n", " \n", " print(payload)\n", " # df.loc[len(df)] = {\"sa_temp\": sa_temp, \"ma_temp\": ma_temp}\n", " \n", "\n", "\n", "client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)\n", "client.on_message = on_message\n", "client.connect(broker_address, broker_port)\n", "client.subscribe(topic)\n", "client.loop_forever()\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | sa_temp | \n", "ma_temp | \n", "
---|---|---|
0 | \n", "68.6 | \n", "70.0 | \n", "
1 | \n", "68.6 | \n", "70.0 | \n", "
2 | \n", "68.6 | \n", "70.0 | \n", "
3 | \n", "68.6 | \n", "70.0 | \n", "