# MQTT client that works with Google IOT cloud

**URL:** <https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286>\
**Category:** Cloud & Connectivity\
**Created:** [January 7, 2019, 12:44pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286 "2019-01-07T12:44:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [January 7, 2019, 12:44pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/1 "2019-01-07T12:44:29Z")

</div>

Hello

We are today using paho and this MQTT wrapper: [https://github.com/mangOH/MqttClient/tree/use\_paho\_linux\_version](https://github.com/mangOH/MqttClient/tree/use_paho_linux_version) developed by @dfrey and others to connect to our own mosquitto broker with TLS encryption.

But I’m now trying to connect to google’s mqtt bridge with TLS and JWT. But I get a socket error when trying to connect. Not sure how to investigate this further but I think this may be a clue?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/1X/282c2cc2fefd1a32ceb7646a39770885ad0511fd.png)

Is there a known issue connecting to gcloud with sierra (WP85) and this wrapper or have someone made it work?

---

<div class="post-metadata">

**Author:** ![NhonChu](https://avatars.discourse-cdn.com/v4/letter/n/85f322/32.png) [@NhonChu](https://mangoh.discourse.group/u/NhonChu)\
**Post date:** [January 21, 2019, 9:42am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/2 "2019-01-21T09:42:38Z")

</div>

Hi @nilsarve,  
If you are still looking for a solution, you could try this option: [https://github.com/nhonchu/mqttClient-for-Legato](https://github.com/nhonchu/mqttClient-for-Legato)

Hope this helps

---

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [January 21, 2019, 10:53am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/3 "2019-01-21T10:53:10Z")

</div>

Looks great. Will check it out. 😀

---

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [January 25, 2019, 8:55am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/4 "2019-01-25T08:55:05Z")

</div>

Hi @NhonChu,  
Did some testing today but could not connect to Google cloud platform.

First of all is there a type here?  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/1X/f5528f5e4dc39cee320422b5549629ac1debd874.png)  
Had to make it

> openssl genrsa -out rsa\_private.pem **2048**

for google to accept my public key.

But when running

> gmqtt session start  
> i get Failed:
> 
> ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/1X/f268b18d717ce1e12cbc5f39e4cd23269dc8750b.png)

Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![NhonChu](https://avatars.discourse-cdn.com/v4/letter/n/85f322/32.png) [@NhonChu](https://mangoh.discourse.group/u/NhonChu)\
**Post date:** [January 28, 2019, 10:26am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/5 "2019-01-28T10:26:38Z")

</div>

Hi @nilsarve,

Thank you for reporting the typo (2048 instead of 2018) for the key generation.

Your device passed the SSL authentication steps, however for some reason the server rejects your mqtt connection request. Could you check these points :

- is the device communication has been allowed ?  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/1X/20f3b36bf87d0205f54dd8a0fdd74946ee143b58.png)

- have you uploaded the public key certificate to Google IoT Core ? And have the app to selected the private key?

Nhon

---

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [January 28, 2019, 11:02am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/6 "2019-01-28T11:02:28Z")

</div>

- Yes the device is allowed  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/1X/6f759808a814d116d4436a0dc71841b4a551a9be.png)
- Content of rsa\_public.pem added to IOT core as RS256 format.  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/1X/1bc717fcf9d57ed7d321debef6001635f369c635.png)

Did not build a system image but used the path option. Maybe I should try building a system image?

---

<div class="post-metadata">

**Author:** ![NhonChu](https://avatars.discourse-cdn.com/v4/letter/n/85f322/32.png) [@NhonChu](https://mangoh.discourse.group/u/NhonChu)\
**Post date:** [January 28, 2019, 3:46pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/7 "2019-01-28T15:46:34Z")

</div>

Thanks for the info.  
You don’t need to build a system image, just the app.  
I’ll try on WP85 and will let you know.

---

<div class="post-metadata">

**Author:** ![NhonChu](https://avatars.discourse-cdn.com/v4/letter/n/85f322/32.png) [@NhonChu](https://mangoh.discourse.group/u/NhonChu)\
**Post date:** [January 28, 2019, 10:03pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/8 "2019-01-28T22:03:08Z")

</div>

Hi @nilsarve,  
I found the issue (side effect of memory optimization). It has been fixed, please retrieve the new mqttGeneric.h file and recompile all components.  
Let me know if this solves your connection issue.  
Thanks

---

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [January 29, 2019, 9:49am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/9 "2019-01-29T09:49:47Z")

</div>

Thanks @NhonChu!  
That solved it! 😃

---

<div class="post-metadata">

**Author:** ![NhonChu](https://avatars.discourse-cdn.com/v4/letter/n/85f322/32.png) [@NhonChu](https://mangoh.discourse.group/u/NhonChu)\
**Post date:** [January 29, 2019, 9:52am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/10 "2019-01-29T09:52:58Z")

</div>

Hi @nilsarve,  
Great 👌😀  
Thank you for reporting this.

---

<div class="post-metadata">

**Author:** ![dbeckwith](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dbeckwith/32/2139_2.png) [@dbeckwith](https://mangoh.discourse.group/u/dbeckwith)\
**Post date:** [May 28, 2019, 3:47pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/11 "2019-05-28T15:47:26Z")

</div>

@nilsarve How is this MQTT with Google IOT Cloud working for you? Did you notice any changes in your data costs not having to deal with the LWM2M registration?

Thanks

---

<div class="post-metadata">

**Author:** ![dbeckwith](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dbeckwith/32/2139_2.png) [@dbeckwith](https://mangoh.discourse.group/u/dbeckwith)\
**Post date:** [August 14, 2019, 6:25pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/12 "2019-08-14T18:25:27Z")

</div>

@NhonChu How do I go about ensuring the private key will be persisted across FOTA?

Thanks,  
Darren

---

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [August 14, 2019, 10:18pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/13 "2019-08-14T22:18:56Z")

</div>

@dbeckwith The google cloud solution consumed alot of data as the overhead is a bit rich so we send our data to a mosquitto broker and forward data to google iot cloud from our server.

---

<div class="post-metadata">

**Author:** ![dbeckwith](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dbeckwith/32/2139_2.png) [@dbeckwith](https://mangoh.discourse.group/u/dbeckwith)\
**Post date:** [August 14, 2019, 10:54pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/14 "2019-08-14T22:54:08Z")

</div>

@nilsarve Any idea as to why there is so much overhead with the Google Cloud IoT vs Mosquitto? Are both solutions using TLS?

---

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [August 15, 2019, 9:58am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/15 "2019-08-15T09:58:16Z")

</div>

Yes both solutions use TLS but google uses a long topic name but on top of that I have measured 403 bytes of overhead on every publish while I have measured this to 225 bytes on every publish to my mosquitto broker.

Might not sound like much but if you publish like every other minute every day 24/7 then you have alot of data. If you send big payloads but not so often it might not be a big issue.

---

<div class="post-metadata">

**Author:** ![dbeckwith](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dbeckwith/32/2139_2.png) [@dbeckwith](https://mangoh.discourse.group/u/dbeckwith)\
**Post date:** [August 15, 2019, 5:19pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/16 "2019-08-15T17:19:02Z")

</div>

@nilsarve How do you go about saving your TLS certificate so that it persists across rollbacks or app/Legato updates?

---

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [August 16, 2019, 6:00am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/17 "2019-08-16T06:00:16Z")

</div>

If just bundle the certificates with my app and that works great for me.

```
bundles:
 {
    file:
    {
        certs / 
    }
 }
```

---

<div class="post-metadata">

**Author:** ![dbeckwith](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dbeckwith/32/2139_2.png) [@dbeckwith](https://mangoh.discourse.group/u/dbeckwith)\
**Post date:** [August 19, 2019, 4:17pm UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/18 "2019-08-19T16:17:43Z")

</div>

@nilsarve Thank you for the example. I feel I’m still missing something on my part. Isn’t the certificates file device specific? If so how do you do produce units if the the certificates file is part of the build?

---

<div class="post-metadata">

**Author:** ![nilsarve](https://avatars.discourse-cdn.com/v4/letter/n/e36b37/32.png) [@nilsarve](https://mangoh.discourse.group/u/nilsarve)\
**Post date:** [August 26, 2019, 6:59am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/19 "2019-08-26T06:59:47Z")

</div>

If you use the same certificate on all clients this will work but if you want to have a uniqe certificate then maybe you could use the config tree to store the certificate?

---

<div class="post-metadata">

**Author:** ![aruna](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@aruna](https://mangoh.discourse.group/u/aruna)\
**Post date:** [December 11, 2020, 9:45am UTC](https://mangoh.discourse.group/t/mqtt-client-that-works-with-google-iot-cloud/2286/20 "2020-12-11T09:45:09Z")

</div>

Hi i facing issue with the sample code which is mentioned in above messages, I am able to send data to [iot.eclipse.org](http://iot.eclipse.org) but receiving is not happening,

SubAck is receiving for the subscribed topic, Receive handler is assigned properly,

Can you pls suggest a solution for this issue
