Problem with publish MQTT message via Telit GSM

2,284 views
Skip to first unread message

Norbert Towiański

unread,
Oct 15, 2015, 6:49:25 AM10/15/15
to MQTT
I have problem with publish any MQTT message via Telit GSM GL865 Quad. Firstly I am connecting to broker (iot.eclipse.org or test.mosquitto.org):

AT+CGDCONT=1,"ip","internet"

AT&K0
AT#SCFG= 1,1,300,90,600,50
AT+CGATT?                                             
AT#SGACT=1,1                                    
AT#SD=1,0,1883,"test.mosquitto.org"

Then I got message: "CONNECT" and then I suppose that I can send data via MQTT.
So I have implemented PAHO embedded C library in my AVR32UC3 processor: 
  1. MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
  2. int rc = 0;
  3. char buf[200];
  4. MQTTString topicString = MQTTString_initializer;
  5. char* payload = "mypayloadnew";
  6. int payloadlen = strlen(payload);
  7. int buflen = sizeof(buf);
  8. data.clientID.cstring = "me";
  9. data.keepAliveInterval = 20;
  10. data.cleansession = 1;
  11. int len = MQTTSerialize_connect(buf, buflen, &data); /* 1 */
  12. topicString.cstring = "public/mytopic";
  13. len += MQTTSerialize_publish(buf + len, buflen - len, 0, 0, 0, 0, topicString, payload, payloadlen); /* 2 */
  14. len += MQTTSerialize_disconnect(buf + len, buflen - len);
  15.                                      
  16.                                        
  17. int i=0;
  18. for(i=0;i<=len;i++){
  19.        usart_putchar(&AVR32_USART0, buf[i]);
  20. }

After initialization of connection I send following frame (I see that on terminal): [01][0E][00][04]MQTT[04]@[00][14][00][02]me[03][1C][00][0E]public/mytopicmypayloadnew[0E][00][00], where my topic is "public/mytopic" and my payload is "mypayloadnew".

After a few seconds I get answer from GSM: NO CARRIER what means: connection lost. Please advise me what is wrong?  
  
 

Paul Fremantle

unread,
Oct 15, 2015, 8:11:06 AM10/15/15
to mq...@googlegroups.com
Are you sure your message is not being published? Your code is doing a disconnect, so I would expect to see the code disconnect.

Paul

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.



--
Paul Fremantle
Part-time PhD student - School of Computing
twitter: pzfreo / skype: paulfremantle / blog: http://pzf.fremantle.org
Co-Founder, WSO2
Apache Member and Committer
07740 199 729

Norbert Towiański

unread,
Oct 15, 2015, 8:50:06 AM10/15/15
to MQTT
I installed MQTT Lens to Chrome Browser and I can see what I get. I tried to install android app (My MQTT), publish some text, then subscribe on MQTT Lens and it works. Is that frame ([01][0E][00][04]MQTT...) proper?

ನಾಗೇಶ್ ಸುಬ್ರಹ್ಮಣ್ಯ (Nagesh S)

unread,
Oct 15, 2015, 1:21:31 PM10/15/15
to mq...@googlegroups.com

I have not used the C embedded client. But, shouldn't your connect call have the broker location details too? Is the AT command to connect 'cover' the MQTT connect call also?

Sent from tablet. Pardon brevity, grammar mistakes or typos.

Norbert Towiański

unread,
Oct 16, 2015, 1:53:28 AM10/16/15
to MQTT
I am using this tutorial to publish message: https://www.youtube.com/watch?v=d9F8l-xxs5I
On video we can see the socket is set up in the code because he's using TI CC3200. I think that if I am using GPRS, I have to connect to server first then I can publish message. 
Please help. 

Norbert Towiański

unread,
Oct 26, 2015, 10:54:58 AM10/26/15
to MQTT
I analysed whole frame of MQTT according to specification and I created fixed frame:

CONNECT:

0x10 – 0001(connect) + 0000 (flags)
0x13 – Remaining Length (decimal = 19)
0x00, 0x04 – Length of ‘MQTT’
0x4D, 0x51, 0x54, 0x54 – ‘MQTT’
0x04 – Protocol Level
0x02 – Clean session=1
0x00, 0x78 – Keep alive = 120
0x00, 0x07 – length of Client ID
0x4E, 0x6F, 0x72, 0x62, 0x65, 0x72, 0x74 – client ID “Norbert”

PUBLISH:

0x30 – 0011(publish) + 0000 (flags – QOS=0)
0x0F – Remaining length (decimal =15)
0x00,0x06 – legth of topic
0x70, 0x75, 0x62, 0x74, 0x6F, 0x70 – name of topic “pubtop”
0x70, 0x61, 0x79, 0x6C, 0x6F, 0x61, 0x64 – name of payload “payload”

DISCONNECT:

0xE0 – 1110(disconnect) + 0000(reserved)
0x00 – remaining length   

After connection with iot.eclipse.org via AT Commands, I send above frame via UART to GPRS Module. Then I get... nothing, any answer. I checked in MQTT SPY if any message reached, but not.
Anyone have reached connection: Microcontroller-->GSM-->MQTT-->Broker? 

Ian Craggs

unread,
Oct 29, 2015, 4:31:25 PM10/29/15
to MQTT
One thing to be aware of with the Paho embedded client is that it uses bitfields for the MQTT headers.  The order in which they need to be applied depends on the compiler and the architecture of the processor.  There is a compile time flag, -DREVERSED to be used if they need to be, well, reversed.  The easiest way to find out which way works is to use the flag, and see if that helps.  Some day I should sort out the build process.

Ian

Karl Palsson

unread,
Oct 29, 2015, 8:10:52 PM10/29/15
to mq...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ian Craggs <icr...@gmail.com> wrote:
> One thing to be aware of with the Paho embedded client is that
> it uses bitfields for the MQTT headers. The order in which they
> need to be applied depends on the compiler and the architecture
> of the processor. There is a compile time flag, -DREVERSED to
> be used if they need to be, well, reversed. The easiest way to
> find out which way works is to use the flag, and see if that
> helps. Some day I should sort out the build process.

The alternative way is to drop bitfields. They're almost always
broken, or do something similar to what you want, but not quite
what you want.

Cheers,
Karl P

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAEBAgAGBQJWMrUGAAoJEBmotQ/U1cr2zIQP/jvlU2ndlVEK8BI86sQq6HFN
VU0s0efVjeQ0srRLiu8/7BYIK3KX5e3UU5qy/dkOIlmHM/J+VeoBeKjWst9G6oJZ
mrhxxJaPlscf3kEiZQpnxd+Qz980ajpYVUwHFNmeqhA03WRq16nio0o3suLHFT7n
TETLoK92IdBjetIOvQauPeQ54DB1bus7JeupNPai47acwssJB26zjb1atyNfbZrB
XWksmqAkAQTd9fddgmoxdXoUW3+c8HDShCbiz7MZTWPuEGXrvu0O1dNWZ9U0zlEp
CMXv6FpMIvNEQtjkRFtgQZJNb4C+XlA7c5yD7atjpXVWMW7nvyoKgRc0hmkicPjM
mW8GD6Iz2WCHENzQT3EKAGFzuoebIn4Hf9IJAOVW6SIWOxt976x7xNiIIo1Hqnna
kZOLeVZaTI5KiYNF/POYjF9bCJnDR4I+WGZlGDJIRAtp4eZgcooVYFVAzHaiOuza
wPpTYrCHifzxGSsdItqNV+FxhF9U06ssvkGu8bRvWPyzYiXpO4k8xT8Y9kEr5UoG
hOOgPdskckxLIvllarV8zE7OxKs48sOhXKirBC++wo0bQFSxkIV3SnzTHLRKZlN7
xi7s/dq+bigc2qUmOzxp8y0H9gX1wJePmXW93dzcAEb42SkDQlR5KulX4CnaLxac
PsWWV6ZRuYXMjDqQ2seY
=vV4g
-----END PGP SIGNATURE-----

neeraj m

unread,
Mar 29, 2016, 3:36:39 PM3/29/16
to MQTT
Hi Norbert,
Were you able to find the solution? Iam facing similar issue with GL865.
Thanks.

oherkan

unread,
Apr 20, 2016, 7:07:28 AM4/20/16
to MQTT
  I have the same problem.. If i only publish like below every second, the message gets delivered but there's a problem with the timing. It gets all 3 messsages after 3 seconds. BTW i use Telit GL850 module. Before sending these packets, i open a tcp socket to iot.eclipse.org:1883

    First connect,


    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.clientID.cstring = "me";
    data.keepAliveInterval = 20;
    data.cleansession = 1;
    len = MQTTSerialize_connect(buf, buflen, &data);

    for ( i=0;i<len;i++) {
        Board_UARTPutChar(buf[i]);
    }





   Then publish your message like below every sec. without disconnecting. 

    
    
MQTTString topicString = MQTTString_initializer;
    topicString.cstring = "mytopic";

    char buf2[50];
    int buflen2 = sizeof(buf2);
    int len2=0;
    int i = 0;
    len2 = MQTTSerialize_publish(buf2, buflen2, 0, 0, 0, 0, topicString, "10.290", 6);

    for ( i=0;i<len2;i++) {
        Board_UARTPutChar(buf2[i]);
    }


   But if i do it like below, i get NO CARRIER.. If you did find a solution, can you please share ? Thanks

        
                MQTTPacket_connectData data = MQTTPacket_connectData_initializer;

int rc = 0;

char buf[200];

int buflen = sizeof(buf);


MQTTString topicString = MQTTString_initializer;

char* payload = "10.000";
int payloadlen = strlen(payload);
int len = 0;


data.clientID.cstring = "me";
data.keepAliveInterval = 20;
data.cleansession = 1;

len = MQTTSerialize_connect((unsigned char *)buf, buflen, &data);

topicString.cstring = "mytopic";
len += MQTTSerialize_publish((unsigned char *)(buf + len), buflen - len, 0, 0, 0, 0, topicString, (unsigned char *)payload, payloadlen);

len += MQTTSerialize_disconnect((unsigned char *)(buf + len), buflen - len);

for (int k=0;k<len;k++) {
Board_UARTPutChar(buf[k]);
}


oherkan

unread,
Apr 20, 2016, 7:20:14 AM4/20/16
to MQTT
Using the DREVERSED Flag did not help.. Any other ideas ?

Necdet Alpmen

unread,
Apr 21, 2016, 3:59:54 AM4/21/16
to MQTT
Hi,

I had the same problem when trying to use the transparent mode of the GPRS modem. Without transparent mode the tutorial works well on my GPRS modem + MCU.

BR,
Necdet

20 Nisan 2016 Çarşamba 14:20:14 UTC+3 tarihinde oherkan yazdı:

Nilesh Thakare

unread,
Jun 21, 2016, 7:14:31 AM6/21/16
to MQTT

Nilesh Thakare

unread,
Jun 21, 2016, 7:19:22 AM6/21/16
to MQTT
Hi,
 
I also want to interface the same thing.I Implement the MQQT on TCP/IP with Ethernet interface. Now I want to replace with GPRS modem.I also interface the HTTP with telit GL865 its working fine.
I just want to know How you tackle the problem you mention.Is there any prob to implement the mqqt layer over TCP/IP in GL865.

thanks 
  

jagadeesh

unread,
Jun 21, 2016, 1:17:18 PM6/21/16
to MQTT

Hi,
    Has anyone tried subscribe with gprs modem. I can publish successfully using paho mqttpacket library, but could not subscribe as i could not receive the response as required.

vinay puli

unread,
Jan 17, 2017, 9:33:39 AM1/17/17
to MQTT, kenosysembed...@gmail.com
Any one looking for an MQTT based solution on a GPRS modem please contact me. We have deployed MQTT based solution on a GPS modem in large scale.

Casey Shea

unread,
Sep 25, 2019, 9:43:10 PM9/25/19
to MQTT
Hello,

I am looking to deploy an MQTT implementation with a U-Blox SARA-R410 modem.  The SARA-R410 has an integrated MQTT stack but it is very unreliable.  U-Blox has recommended implementing my own MQTT client and passing the MQTT packets over an open TCP socket on the modem.  While this is not a GPRS modem, it does use a similar AT command set and I could very easily modify your implementation and just fill in the lower levels of the application.  Would you be willing to share some of your source code?

Thanks,

Casey

Bilal Riaz

unread,
Sep 26, 2019, 4:41:05 AM9/26/19
to mq...@googlegroups.com
Understand the working of MQTT, To send data to MQTT broker  via GSM, you first have to send a connection packet in the following format 
image.png
and after establishing a connection you are able to send a data packet having the following format
image.png
 Both the packets can be sent via AT commands but if you are trying to connect to AWS, Azure or Google Cloud etc then make sure that your Modem supports TLS 1.2 authentication.
Note: You have to make these packets yourself keeping in mind the above format. 


--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages