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

Parents
  • 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

  • Hi again!

    Just wanted to pop in and update that I'm working on getting a simple sample up and running now!

    Best regards,
    Carl Richard

  • Hi again!

    I have a working sample now. If you setup the device according to the blog post (or readme) it should work properly (even with the "old" Root CA). I've disabled topic subscription in the sample as there were some issues with the handling of the received messages, but I believe this is good enough for you to get started.

    The sample is tested on version 1.5 of the nRF Connect SDK. The main loop simply publishes data with a timestamp at fixed intervals. I hope this helps you on your way and as always; feedback would be appreciated! 

     nrf_to_gcloud_ncs1.5.0.zip
    Best regards,
    Carl Richard

  • Hi Carl Richard!

    Sorry for the delayed reply

    We had to temporarily set this on hold while working with other things. We have finally got back to testing with google cloud, and your sample is working fine! Smile.

    We have also enabled subscription on the default command-topic from google devices. We did this by running this function on the received data:

     

    int mqtt_readall_publish_payload(structmqtt_client *client, uint8_t *buffer, size_t length)


    Thank you again for helping us! 

    Best regards,

    Yuyanton

Reply
  • Hi Carl Richard!

    Sorry for the delayed reply

    We had to temporarily set this on hold while working with other things. We have finally got back to testing with google cloud, and your sample is working fine! Smile.

    We have also enabled subscription on the default command-topic from google devices. We did this by running this function on the received data:

     

    int mqtt_readall_publish_payload(structmqtt_client *client, uint8_t *buffer, size_t length)


    Thank you again for helping us! 

    Best regards,

    Yuyanton

Children
Related