[SOLVED] How can I set up my first source with MQTT and adafruit

Good evening,
I am new with Ubidots and it’s first post.
I have a Adafruit Feather Mo Adaloger board with a Fona808 and I am trying to send latitude and longitude and other variable. I want to use MQTT protocol and there is no exemple for adafruit.

I am trying to use Adafruit_MQTT library.

I ma not sure how to setup my first source. The first I created is name ‘FONA’ with the label ‘fona’. I created two variable named ‘latitude’ with the label ‘lat’ and ‘longitude’ with the label ‘lng’.

I think my problem is how I sent it from my code. (how I code it). Some of you has a experience how to send and format data from the sketch code?

I will try to explian how I did it

First I connect to Ubidots. The connection was successful.
Then I publish the data. and I got a sucessfully message, but I looked the Ubidots dashboard, I can not see any update.

My problem, I do not know it the data (latitude/longitude) must in json format and how I have to label it.
My topics is : v1.6/devices/fona
My playload is : {“lat”:46.21979,“lng”:6.14112} (it’s a char variable and not a json variable. I parsed it into a char varaible)

My packet is:

MQTT publish packet:
0 [0x30], 2 [0x32], [0x00], [0x12], v [0x76], 1 [0x31], . [0x2E], 6 [0x36],
/ [0x2F], d [0x64], e [0x65], v [0x76], i [0x69], c [0x63], e [0x65], s [0x73],
/ [0x2F], f [0x66], o [0x6F], n [0x6E], a [0x61], [0x20], { [0x7B], " [0x22],
l [0x6C], a [0x61], t [0x74], " [0x22], : [0x3A], 4 [0x34], 6 [0x36], . [0x2E],
2 [0x32], 1 [0x31], 9 [0x39], 7 [0x37], 9 [0x39], , [0x2C], " [0x22], l [0x6C],
n [0x6E], g [0x67], " [0x22], : [0x3A], 6 [0x36], . [0x2E], 1 [0x31], 4 [0x34],
1 [0x31], 1 [0x31], 2 [0x32], } [0x7D],
Writing packet (Adafruit_MQTT_FONA.h line 121)
—> AT+CIPSTATUS
<— OK
<— STATE: CONNECT OK
AT+CIPSEND=52
0x30 0x32 0x0 0x12 0x76 0x31 0x2E 0x36 0x2F 0x64 0x65 0x76 0x69 0x63 0x65 0x73 0x2F 0x66 0x6F 0x6E 0x61 0x20 0x7B 0x22 0x6C 0x61 0x74 0x22 0x3A 0x34 0x36 0x2E 0x32 0x31 0x39 0x37 0x39 0x2C 0x22 0x6C 0x6E 0x67 0x22 0x3A 0x36 0x2E 0x31 0x34 0x31 0x31 0x32 0x7D
<— >
<— SEND OK
publish true
MQTT Publish to Ubdots!

I am really new and I am not sure if I post my question in the right forum, but if someone has experience with Adafruit and Ubidots and can tell me how to use Adafruit_MQTT library to succeffuly format my data to be sent with MQTT, it would be ver great!!!

Thank a lot
Cheers

Hello, you are building something like this actually:

v1.6/devices/fona {“lat”.46.21979,“lng”:6.14112}

Below you create two variables called “lat” and “lng”, but for position purpouses you must send lat and lng as context, you should build something like this:

v1.6/devices/fona {“YOUR_VARIABLE_NAME”:{“value”:YOUR_VALUE, “context”:{“lat”:YOUR_LAT, “lng”: YOUR_LNG}}}

Please refer to the documentation for more information: https://ubidots.com/docs/api/index.html#send-values

Regards

Dear José

Thank for replying,

Yes I know, my data are change as the following
{“position”:{“value”:0,“timestamp”:1482527616.00000,“context”:{“lat”:46.21984,“lng”:6.14123,“IMEI”:“86000000000”,“Battery”:93,“Quality”:“GSM”,“Tower”:“228,03,1771,2d6f,45,32”}},“battery”:93}
I have problem to correctly set the imestamp.
Can it be a string?

I am using this to save it into a json string (I am using ajson)
aJson.addNumberToObject(jobject1, “timestamp”, posix);

Cheers

Hello Pierrot10, you are sending the timestamp as float and that is the reason because Ubidots rejects it. You should send the timestamp in milliseconds and send it as int or as string in order for Ubidots accepts it, please construct your timestamp in milliseconds using this web page: http://www.epochconverter.com/

An example: Mon, 26 Dec 2016 14:01:50 GMT to timestamp in milliseconds will be ‘1482760910000’.

Regards.