MQTT_SERV = "localhost"
MQTT_PATH = "RPICT7V1"
MQTT_USER = ""
MQTT_PASS = ""
CHANNELS = ["NodeID", "RP1", "RP2", "RP3", "RP4", "RP5", "RP6", "RP7",
"Irms1", "Irms2", "Irms3", "Irms4", "Irms5", "Irms6", "Irms7",
"Vrms"]
import paho.mqtt.client as mqtt
import serial
ser = serial.Serial('/dev/ttyAMA0', 38400)
client = mqtt.Client("P1")
client.username_pw_set(MQTT_USER, MQTT_PASS)
client.connect(MQTT_SERV)
try:
while 1:
line = ser.readline()
line = line[:-2]
Z = line.split(' ')
print line
for i in range(len(Z)):
client.publish("%s/%s" % (MQTT_PATH, CHANNELS[i]), Z[i])
except KeyboardInterrupt:
client.disconnect()
ser.close()