Commit 36add0d9 authored by kiran.ak's avatar kiran.ak

-mqtt publish structure changes, added extra logger statements

parent 0753042f
source:
host: "192.168.19.87"
port: 1883
topic: "ilens/monitor/live/site_143"
tag_old: "site_214$line_490$equipment_301$tag_572"
tag: "site_214$line_414$tag_155"
destination:
host: "iot-hub.ilens.io"
port: 1883
topic: "ilens/monitor/live/site_203"
tag_old: "site_143$line_144$equipment_1050$tag_317"
tag: "site_143$line_152$tag_5790"
site_id: "site_143"
#To send the recieved json as it is just mapping the mapping as empty
mapping:
site_143$line_140$equipment_181$tag_198: site_203$line_282$equipment_444$tag_423
site_143$line_140$equipment_178$tag_198: site_203$line_282$equipment_438$tag_423
site_143$line_141$equipment_182$tag_198: site_203$line_283$equipment_445$tag_423
site_143$line_141$equipment_183$tag_198: site_203$line_283$equipment_446$tag_423
site_143$line_164$equipment_230$tag_198: site_203$line_288$equipment_449$tag_423
\ No newline at end of file
......@@ -2,12 +2,12 @@
"source": {
"ip": "192.168.0.220",
"port": 1883,
"topic": "ilens/monitor/live/site_143"
"topic": "ilens/monitor/live/sit_143"
},
"destination": {
"ip": "iot-hub.ilens.io",
"ip": "192.168.0.220",
"port": 1883,
"topic": "ilens/monitor/live/site_203"
"topic": "ilens/monitor/live/sit_203"
},
"mapper": {
"site_143$line_140$equipment_181$tag_198": "site_203$line_282$equipment_444$tag_423",
......
......@@ -25,7 +25,8 @@ class myThread(threading.Thread):
if tag in self.mapper:
new_data[self.mapper[tag]] = payload_data['data'][tag]
payload_data["data"] = new_data
self.mqtt_pub.publish_data(payload_data)
if payload_data["data"]:
self.mqtt_pub.publish_data(payload_data)
if __name__ == '__main__':
......
......@@ -30,15 +30,18 @@ class MQTTPublisher(object):
def publish_data(self, message):
try:
self.connect_to_destination()
logger.debug("MQTT Publish to :{}".format(self.destination_topic))
logger.debug("MQTT DATA : {}".format(str(message)))
msg_info = self.mqtt_client.publish(self.destination_topic, json.dumps(message), qos=1)
self.mqtt_client.disconnect()
if msg_info[0] == 4:
logger.debug("mqtt connection lost")
return False
else:
logger.info("MQTT Message published successfully")
return True
except Exception as e:
logger.exception("Exception while publishing the message to topic:" + str(e))
return False
......@@ -17,7 +17,9 @@ class MQTTSubscriber:
def on_message(self, client, userdata, message):
try:
logger.info("data arrived : {}".format(str(time.time())))
DATA_LIST.append(json.loads(message.payload))
payload = json.loads(message.payload)
logger.debug("Payload DATA : {}".format(payload["data"]))
DATA_LIST.append(payload)
except Exception as es:
logger.error("Exception in received data : {}".format(str(es)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment