Home » Eclipse Projects » OM2M » Test MQTT blinding in OM2M(Test MQTT blinding in OM2M)
|
Re: Test MQTT blinding in OM2M [message #1777780 is a reply to message #1776864] |
Mon, 04 December 2017 15:50 |
Dorian Kurzaj Messages: 16 Registered: May 2016 |
Junior Member |
|
|
1. Start the binding
I don't remember, but probably, by default the MQTT module is not enabled in the product (mn or in) you launch. To do so you can take example on how to activate an IPE here : https://wiki.eclipse.org/OM2M/one/Developer#Add_the_plugin_to_the_OM2M_product.28s.29 You just need to do the same, but for the MQTT binding.
2. How to create topic req,resp and AE ? Have it available ?
You need to have a MQTT broker (it's some king of MQTT server which manages the MQTT message queues). In the OM2M tutorial they advise you to use the Mosquitto broker, but you can use any you want. Then, you need to configure OM2M to use this MQTT broker (as described here : https://wiki.eclipse.org/OM2M/one/MQTT_Binding#Constants), and finally, if you want to communicate to OM2M through MQTT you have to make a program which implements an MQTT client which is going to connect to the same broker, so that OM2M and your program can communicate through the same topics.
Here is a Python MQTT client simulating a thermometer I developed :
from random import randint
import paho.mqtt.client as mqtt
import time
####################################################
def on_message(client, userdata, message):
print("message received ", str(message.payload.decode("utf-8")))
print("message topic=", message.topic)
print("message qos=", message.qos)
print("message retain flag=", message.retain)
###################################################
mqttc = mqtt.Client()
mqttc.on_message = on_message # Attach function to callback
mqttc.connect("localhost", 1883, 60)
mqttc.loop_start()
mqttc.subscribe("/oneM2M/resp/mn-cse/THERMOMETER/json", 2)
while 1:
temperature = randint(-10, 40)
payload = ("""
{
"m2m:rqp": {
"fr": "THERMOMETER",
"to": "/mn-cse/mn-name/THERMOMETER/DATA",
"op": 1,
"rqi": 123456,
"pc": {
"m2m:cin": {
"cnf": "message",
"con": "%s"
}
},
"ty": 4
}
}
""" % str(temperature))
print("Send:", payload)
(result, mid) = mqttc.publish(
"/oneM2M/req/THERMOMETER/mn-cse/json", payload, 2)
time.sleep(5)
mqttc.loop_stop()
mqttc.disconnect()
This is a MQTT client using the Paho library to communicate in MQTT to my Mosquitto MQTT broker running in localhost:1883. The goal of this MQTT client is to send data to a previously created device registered in OM2M at the URI : /mn-cse/mn-name/THERMOMETER.
I hope this helps ! :)
Best regards,
Dorian
[Updated on: Thu, 14 December 2017 15:02] Report message to a moderator
|
|
|
Re: Test MQTT blinding in OM2M [message #1777791 is a reply to message #1777780] |
Mon, 04 December 2017 16:21 |
hieu tran Messages: 19 Registered: November 2017 |
Junior Member |
|
|
Thanks for your answer. I had run mqtt broker and start mqtt blinding.
However, I don't know what strutures of messsage could be sent.
According Tuturial https://wiki.eclipse.org/OM2M/one/MQTT_Binding,
when i sent a message in req topic, om2m have sent back one message to resp topic. But in fact, when sending message into req topic, the response message has some thing wrong:
{
"m2m:rsp": {
"m2m:rsc": 4000,
"m2m:pc": "Invalid content provided in request primitive",
"m2m:to": "THERMOMETER",
"m2m:fr": "/in-cse"
}
}
{
"m2m:rsp": {
"m2m:rsc": 4000,
"m2m:pc": "Invalid content provided in request primitive",
"m2m:to": "THERMOMETER",
"m2m:fr": "/in-cse"
}
}
Could you show me the response of your example and guide me step how to creat AE or resgister AE to oneM2M ?
Many thanks,
[Updated on: Mon, 04 December 2017 16:22] Report message to a moderator
|
|
|
Re: Test MQTT blinding in OM2M [message #1778464 is a reply to message #1777791] |
Thu, 14 December 2017 14:44 |
Dorian Kurzaj Messages: 16 Registered: May 2016 |
Junior Member |
|
|
I just retried and indeed, I have the same error message as you have, maybe the latest update broke the MQTT binding. Is anyone working with MQTT and having no issue using it like the HTTP binding (REST API)?
And I tried with an XML payload (to see if the error would be the same) on the XML dedicated topics, but I get another error:
[ERROR] - org.eclipse.om2m.datamapping.jaxb.Mapper
JAXB unmarshalling error!
javax.xml.bind.UnmarshalException
- with linked exception:
[Exception [EclipseLink-25008] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A descriptor with default root element {http://www.onem2m.org/xml/protocols}rqp was not found in the project]
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:980)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:588)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:182)
at org.eclipse.om2m.datamapping.jaxb.Mapper.stringToObj(Mapper.java:181)
at org.eclipse.om2m.binding.mqtt.MqttRequestHandler.messageArrived(MqttRequestHandler.java:180)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:354)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:162)
at java.lang.Thread.run(Thread.java:748)
Caused by: Exception [EclipseLink-25008] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A descriptor with default root element {http://www.onem2m.org/xml/protocols}rqp was not found in the project
at org.eclipse.persistence.exceptions.XMLMarshalException.noDescriptorWithMatchingRootElement(XMLMarshalException.java:148)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshallerHandler.startElement(SAXUnmarshallerHandler.java:302)
at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parseEvent(XMLStreamReaderReader.java:132)
at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:99)
at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:86)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:895)
at org.eclipse.persistence.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:659)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:585)
... 6 more
[INFO] - org.eclipse.om2m.binding.mqtt.MqttRequestHandler
Invalid content provided in MQTT request
Here is the type of payload I sent in MQTT:
<m2m:rqp xmlns:m2m="http://www.onem2m.org/xml/protocols">
<fr>THERMOMETER</fr>
<to>/mn-cse/mn-name/THERMOMETER/DATA</to>
<op>1</op>
<rqi>123456</rqi>
<pc>
<m2m:cin xmlns:m2m="http://www.onem2m.org/xml/protocols">
<cnf>application/xml</cnf>
<con>%s</con>
</m2m:cin>
</pc>
</m2m:rqp>
Apparently, according to the error stack trace, my use of the tag: <m2m:rqp xmlns:m2m="http://www.onem2m.org/xml/protocols"> is wrong or bugged. Any hint about that too ?
[Updated on: Mon, 18 December 2017 09:11] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Thu Oct 03 23:32:18 GMT 2024
Powered by FUDForum. Page generated in 0.04263 seconds
|