This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do we use nrf9160DK with google cloud MQTT Pub/Sub?

Hi

We are a group of students working with the nRF9160dk.

We want to try connecting the nRF9160dk to google cloud and send data through MQTT.

We have tried to follow this guide (link to guide), but the setup does not work and we assume that it is because it's developed using an older SDK version.

We saw a repository (repository) in the comments of the guide which is more up to date.

Based on the newer repository, we have made a project that is similar in structure to the guide.

It builds and runs, but we don't know how it is supposed to subscribe to a topic we've made in the Pub/Sub service.

In addition we aren't sure if it's actually connected to our Google cloud project since the output in link monitor tells us we've got a connection, but it can't publish messages.

System info:

Operative System: Windows 10

Hardware: nRF9160dk, firmware 

Software: ncs v1.4.99-dev1

Zipped code & log from Link Monitor:

nrfgcloud_new.7z

Google cloud setup:

- Project Info
 

- Registry Info

- Device info

- Pub/Sub     topic & subscription & member/role

  • Hi,

    As of now, we do not have any official updated example where the nRF9160 connects to Google Cloud. The first guide you linked to was a student project, and as such has not been updated. I believe it was built using NCS v0.4.0, so it's very outdated, and you're correct that this causes it to not work. The SDK has changed a lot since that version, so it might not be straightforward to get it to work with a newer version of NCS. Something you can also do is to look at the samples we have in NCS that connects to other cloud services and uses MQTT, such as Simple MQTT and Cloud client, to see how this is done with other cloud services than Google.

    You should be able to see whether your device is connected or not in the Google Cloud Platform. When you go to IoT Core -> <your_registry> -> Devices, you should be able to see a list over your devices and when they were last seen. If they haven't been seen yet, you haven't been able to connect to Google Cloud and communicate with it. You can also see active devices under Monitoring in IoT Core. From your log it seems like it wasn't able to connect to Google Cloud. It started connecting, but there's no log that you successfully connected, and it says that you're trying to publish data while not connected.

    Best regards,

    Marte

  • Hi!

    Continuing our offline discussion here. I notice two things in your log:
    1. The application tries to (seemingly) connect to GCP before the LTE connection is established. This may be because LOG messages are less prioritized than printk. Does LED1 turn on before gcloud_connect(...) is called?
    2. The gcloud_thread is not started at all. The code you have based your application on has implemented some changes to how the threads are started, though they are removed in your code. Try to add them again so that the thread is started properly. Alternatively you can uncomment line 72, 73 and 74 in gcloud.c.

    Best regards,
    Carl Richard

  • Hi again!

    1.

    Yes, the LED1 does turn on before gcloud_connect() is called.

    2.  

    We have not tested the gcloud_thread since we have made new changes to our code since the last time we uploaded our zip-file in DevZone. 
    The changes we've made does not make use of threads but still tries to connect to GCP after we've succesfully run Modem_configure(). This version of our code is based on mqtt_simple. We tried adding what we thought was necessary from gcloud.c. 

    Attached is our new version of the code.

    mqtt_gcloud_custom.zip

  • Hi!

    1. Great! 

    2. Understood! Looking through the code now. Does the log provide any meaningful information? I still recommend debugging the code to see where it gets stuck. I've also attached the pathfinder project, which was done on NCS v1.0.0 (i.e. newer) and should be easier to port. 

    pathfinder.zip

    Best regards,
    Carl Richard

  • Hi again

    We've been trying to port different gcloud projects over the past week, including, but not limited to (ZephyrGoogleIoT and pathfinder), but haven't been able to make it work. 


    Unfortunately we don't have enough experience to make a proper port of others code. Most of our attempts we don't really know what we are doing.

    Something we noticed across the different projects is that the CA certificate varies, but we don't know how it works or how to set it up correctly. That seems to be the issue.
    Everything else including JWT used for authenticating device seems to be the same for all the projects.

    Would it be possible for you to make a simple example for our use case?

    (Connect to Gcloud, publish a message via MQTT from nrf9160dk)

    Kind Regards,

    Yuyanton

Related