Hi, I am trying to publish MQTT messages from IoT in Geospatial Analytics. I think I am doing everything ok. GA is receiving messages from MQTT, but is not detecting any device in geozone. I have a device registered in my IoT is sending messages with this format:
{"ts":"2015-09-04T09:23:42.656+0200","d":{"NComb":"59","Speed":"62","Revs":"3168","Temperature":"47","Latitude":"41.380814","FM":"0013","Longitude":"2.183176","idK":"urp3174m8lyr"}}
And I start the GA service with the next code:
var jsonObject = JSON.stringify({
"mqtt_client_id_input" : "a:"+ config.your_org + ":geoInput",
"mqtt_client_id_notify" : "a:"+ config.your_org + ":geoNotify",
"mqtt_uid" : config.mqtt.username,
"mqtt_pw" : config.mqtt.pass,
"mqtt_uri" : config.mqtt.host+":"+config.mqtt.port,
"mqtt_input_topics" : config.subscribeTopic,
"mqtt_notify_topic" : notify_topic_string,
"device_id_attr_name" : "idK",
"latitude_attr_name" : "Latitude",
"longitude_attr_name" : "Longitude"
});
Then, I have a quiestion: The "device_id_attr_name" attribute is the name of id attribute in JSON object or is the name of deviceId in IoT?
I think the problem must be in this point.
Thanks in advance.
Answer by MikeBranson (643) | Sep 04, 2015 at 04:50 PM
Hello,
To answer the last question that you ask, the "device_id_attr_name" is the name of id attribute in the JSON object. It will be used in the notify messages that get published back to MQTT.
Now on to the main subject of your post. You state that the Geo service is correctly receiving messages from MQTT, but it is not detecting any device-region events. We think that the issue may be with the JSON schema of your MQTT message. "Latitude", "Longitude" and "idK" are not at the top level of your JSON object. They are within a nested object.
Are you able to flatten out your message schema so that the timestamp and the other attributes are all in the top-level object? If so, it would be interesting to see if that eliminates your issue.
Mike B.
Hi Mike,
I have been able to put these properties at top level of message, with "ts" and "d" and it is running. Thanks for your answers,
Answer by migueamat (3) | Sep 09, 2015 at 01:31 AM
Then, How Geospatial knows which are the attributes from JSON message that contain latitude, longitude and id to check if device enters in the zone?
Following your indications, now Latitude and Longitude are at top of the message, like this:
{"ts":"2015-09-09T12:18:23.921+0200","d":{"Latitude":"41.381424","Longitude":"2.18214","idK":"1hbg09corcode","Speed":"11","Temperature":"52","Revs":"3069","NComb":"59","FM":"0009"}}
I imagine you referred to this, because for IoT the message format always is the timestamp and the device attributes in another level inside JSON object.
Regards
Sorry if my answer wasn't clear. The order of the attributes is not important. What I was I was suggesting that you move to a message format that looks something like this, e.g.:
{"ts":"2015-09-09T12:18:23.921+0200","Latitude":"41.381424","Longitude":"2.18214","idK":"1hbg09corcode","Speed":"11","Temperature":"52","Revs":"3069","NComb":"59","FM":"0009"}
In your latest response, the 3 special attributes are still nested inside another JSON object called "d". I was suggesting that you eliminate the nesting, so that the 3 special attributes are at the first level of the JSON object.
I understood your explanation at first time, but for IoT in Bluemix the JSON object must be with format I show, with the attributes inside object called "d". For this reason I thought the problem could be the fields order. Is there any way to change this format when I send the data to IoT?
Thanks
IoT Foundation doesn't explicitly require a "d" top-level property in the JSON payload, however it does encourage this format to allow IoT Foundation to make some assumptions about how data is organized in the payload. If the IoT Foundation payload format is not followed, we refer to this as a "custom payload" in our documentation. IoT Foundation will allow you to publish a custom payload in the format that Mike has suggested:
If you would like to still include the "d" property in your payload, you could duplicate the Latitude and Longitude properties at the top level of the JSON like this:
{"ts":"2015-09-09T12:18:23.921+0200","Latitude":"41.381424","Longitude":"2.18214","d":{"Latitude":"41.381424","Longitude":"2.18214","idK":"1hbg09corcode","Speed":"11","Temperature":"52","Revs":"3069","NComb":"59","FM":"0009"}}
https://docs.internetofthings.ibmcloud.com/messaging/payload.html