Home » Eclipse Projects » OM2M » MQTT: Error in creating container/content instance on MN-CSE/IN-CSE
|
Re: MQTT: Error in creating container/content instance on MN-CSE/IN-CSE [message #1783098 is a reply to message #1782043] |
Wed, 07 March 2018 21:39 |
Jairo Ariza Messages: 9 Registered: March 2018 |
Junior Member |
|
|
Hi with this python code I manage to create app, container and send data via MQTT.
import paho.mqtt.client as mqtt
import time
def on_message(client, userdata, msg):
print("Respuesta del topico: "+str(msg.payload.decode("UTF-8")))
topic="/oneM2M/req/Sensor_MQTT/in-cse/json"
payload_lista=[]
payload1="""{"m2m:rqp": {"m2m:fr": "Sensor_1","m2m:to": "/in-cse","m2m:op": 2,"m2m:rqi": 123456}}"""
payload2="""{"m2m:rqp": {
"m2m:fr" : "admin:admin",
"m2m:to" : "/in-cse/in-name",
"m2m:op" : 1,
"m2m:rqi": 123456,
"m2m:pc": {
"m2m:ae": {
"api": "app-sensor",
"rr": "false",
"lbl": ["Type/sensor", "Category/temperature", "Location/home"],
"rn": "MY_SENSOR"}},
"m2m:ty": 2}}"""
payload3="""{"m2m:rqp": {
"m2m:fr" : "admin:admin",
"m2m:to" : "/in-cse/in-name/MY_SENSOR",
"m2m:op" : 1,
"m2m:rqi": 123456,
"m2m:pc": {"m2m:cnt": {"rn": "DESCRIPTOR"}},
"m2m:ty": 3}}"""
payload5="""{"m2m:rqp": {
"m2m:fr" : "admin:admin",
"m2m:to" : "/in-cse/in-name/MY_SENSOR",
"m2m:op" : 1,
"m2m:rqi": 123456,
"m2m:pc": {"m2m:cnt": {"rn": "DATA"}},
"m2m:ty": 3}}"""
payload6="""{"m2m:rqp": {
"m2m:fr" : "admin:admin",
"m2m:to" : "/in-cse/in-name/MY_SENSOR/DATA",
"m2m:op" : 1,
"m2m:rqi": 123454,
"m2m:pc": {
"m2m:cin": {"cnf":"message",
"con":"55 C"
}
},
"m2m:ty": 4}}"""
payload_lista.append(payload1)
payload_lista.append(payload2)
payload_lista.append(payload3)
payload_lista.append(payload5)
payload_lista.append(payload6)
for payload in payload_lista:
client = mqtt.Client("OM2M_MQTT")
client.on_message = on_message
client.connect("127.0.0.1", 1883)
client.loop_start()
client.subscribe("/oneM2M/resp/in-cse/Sensor_MQTT/json")
print("prueba del MQTT: "+payload)
print()
client.publish(topic,payload)
time.sleep(1)
client.on_message = on_message
client.loop_stop()
I hope this helps
Regards
[Updated on: Wed, 07 March 2018 21:41] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Sun Oct 13 04:00:33 GMT 2024
Powered by FUDForum. Page generated in 0.03842 seconds
|