Skip to content

Commit c4dc635

Browse files
authored
Create test.py
1 parent 8b01ace commit c4dc635

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import paho.mqtt.client as mqtt, json, base64
2+
3+
# The callback for when the client receives a CONNACK response from the server.
4+
def on_connect(client, userdata, flags, rc):
5+
print("Connected with result code "+str(rc))
6+
7+
# Subscribing in on_connect() means that if we lose the connection and
8+
# reconnect then subscriptions will be renewed.
9+
client.subscribe("application/1/device/+/event/up")
10+
11+
# The callback for when a PUBLISH message is received from the server.
12+
def on_message(client, userdata, msg):
13+
Jmsg=json.loads(msg.payload)
14+
mydata=Jmsg["object"]
15+
if (mydata!=""):
16+
print(mydata)
17+
Jmydata=json.loads(mydata)
18+
19+
#def bleu():
20+
# msg="blue"
21+
# msg_bytes=msg.encode('ascii')
22+
# b64_bytes=base64.b64encode(msg_bytes)
23+
#b64_msg=b64_bytes.decode('ascii')
24+
#print(b64_msg)
25+
#payloadJson={"confirmed":False,"fPort":5,"data":b64_msg}
26+
#client.publish(topic="application/1/device/0c7e450102030102/command/down",payload=json.dumps(payloadJson))
27+
28+
client = mqtt.Client()
29+
client.on_connect = on_connect
30+
client.on_message = on_message
31+
32+
client.connect("chirpstack.iut-blagnac.fr", 1883, 60)
33+
34+
# Blocking call that processes network traffic, dispatches callbacks and
35+
# handles reconnecting.
36+
# Other loop*() functions are available that give a threaded interface and a
37+
# manual interface.
38+
client.loop_forever()

0 commit comments

Comments
 (0)