Skip to content

Instantly share code, notes, and snippets.

@Elwell
Created September 10, 2013 06:14
Show Gist options
  • Select an option

  • Save Elwell/6505599 to your computer and use it in GitHub Desktop.

Select an option

Save Elwell/6505599 to your computer and use it in GitHub Desktop.
mosquitto debugging
read_pv was failing when publishing (hangs after publish), so knocked up a dummy test client with static dictionary
andrew@guruplug:~$ ./debug_mqtt.py
{'AC_Hz': 2925, 'PV_A': 11, 'Out_W': 3428, 'PV_W': 3355, 'PV_V': 3014, 'kWh_Total': 1851, 'timestamp': 1378793395.40962, 'pid': 6573, 'kWh_today': 17, 'AC_V': 11}
loop start
^C
^C
^Z
[2]+ Stopped ./debug_mqtt.py
andrew@guruplug:~$ killall debug_mqtt.py
andrew@guruplug:~$ fg
./debug_mqtt.py
Terminated
andrew@guruplug:~$ cat debug_mqtt.py
#!/usr/bin/python
# script to poll growatt PV inverter and spit out values
# Andrew Elwell <[email protected]> 2013-09-01
import ConfigParser
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
import time
import mosquitto
import os
config = "/home/andrew/solarmon.cfg"
settings = ConfigParser.RawConfigParser()
settings.read(config)
port = settings.get('inverter', 'port')
result = {'AC_Hz': 2925, 'PV_A': 11, 'timestamp': 1378791273.609403, 'pid': 5581, 'AC_V': 11, 'Out_W': 3428, 'PV_W': 3355, 'PV_V': 3014, 'kWh_Total': 1851, 'kWh_today': 17}
result['timestamp'] = time.time()
result['pid'] = os.getpid()
clientname = 'PV_Monitor-' + str(result['pid'])
print result
# publish to local broker
broker = settings.get('mosquitto', 'broker')
mqtt = mosquitto.Mosquitto(clientname)
mqtt.connect(broker)
mqtt.loop_start()
print "loop start"
#for k,v in result.items():
# print "publishing: %s = %s" % (k, v)
# mqtt.publish(k,v)
print "stopping... ",
mqtt.loop_stop()
print "loop stopped"
mqtt.disconnect()
print "disconnect"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment