Commit 4d69dd96 authored by Reik Wolff's avatar Reik Wolff

init commit

parents
/.idea
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
import paho.mqtt.client as mqtt
import json
# Wichtig: paho-mqtt Bibliothek vorher einbinden:
#
# pip install paho-mqtt
#
# ODER
#
# git clone https://github.com/eclipse/paho.mqtt.python.git
# cd org.eclipse.paho.mqtt.python.git
# python setup.py install
def on_connect(client, userData, resultCode):
print("Connected")
def on_message(client, userData, message):
try:
jsonData = json.loads(str(message.payload))
date = jsonData['date']
value = jsonData['value']
print(message.topic + ": " + str(value))
except:
print(message.topic + ": " + str(message.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("sdacehub.de", 1883, 60)
topic = "hackathon/test/python"
message = "Das Pferd frisst keinen Gurkensalat!"
qos = 0
retained = False
client.publish(topic, message, qos, retained)
client.subscribe("hackathon/ehz/+")
client.loop_forever()
\ No newline at end of file
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