document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/env python
  2.  
  3. import mosquitto
  4. import json
  5. import os
  6.  
  7. URLFMT = "%s,%s"
  8.  
  9. def on_message(msg):
  10. try:
  11. data = json.loads(str(msg.payload))
  12. except:
  13. print "Can't decode payload"
  14. try:
  15. f = open('/var/www/location.current', 'w')
  16. f.write(URLFMT % (data['lat'], data['lon']))
  17. f.close()
  18. except Exception, e:
  19. print "Can't write file: %s" % str(e)
  20.  
  21. mqttc = mosquitto.Mosquitto("locator")
  22. mqttc.on_message = on_message
  23.  
  24. mqttc.connect("127.0.0.1", 1883, 60)
  25. mqttc.subscribe("mqttitude/#", 0)
  26.  
  27. while mqttc.loop() == 0:
  28. pass
');