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

nrf 9160 Serial MQTT

Hello All,

I am trying to send data on serial port of nrf9160 to be published on a topic using MQTT protocol. So far using the mqtt example and UART example, I have successfully run both code independently not with each other. I am not sure how to integrate the UART received buffer in the publish function so that I could send the data to the broker on that specific topic. Can some please help me out with this. I would really appreciate it.

 The following are the modifications which I have added to the main code: 1. function to respond on serial event 

 

2. In the main function I have added this 

4. The following code has modifications. It takes data from serial port "uart_buf" and then publish it. I have made minor changes to length and some changes to if statement so that it publishes directly 

It doesn't seem to work. Can some please help me out with the same 

Parents
  • The sample works in the following manner

    • Several work items are initialized:

    • Serial data is sent from the computer to nRF9160 through a micro USB and uart_cb() gets called
    • In uart_cb() the incoming serial data is processed and put into the queue (at the top of main.c I have created an array of static struct work_data of size 5)
    • Each incoming element (separated by 10 (=LF)) is submitted to the work queue through k_work_submit()
    • When the work queue Thread gets scheduled to run, it will call pub_uart_mqtt() for each element, where the elements will be published to the topic CONFIG_MQTT_PUB_TOPIC through data_publish()

    Try following these steps:

    • Build and run the sample
      • west build -b nrf9160_pca10090ns
      • nrfjprog --eraseall
      • west flash
    • Subscribe to the topic /my/publish/topic -v from the mosquitto broker, by typing the following in a command line (cmd, git bash etc..)
      • mosquitto_sub -h mqtt.eclipse.org -t /my/publish/topic -v
    • Open Tera Term with the following setup:

    • Then, in Tera Term, type in e.g. "Hey", followed by enter and you should see the following response in the command line where mosquitto_sub -h were called

Reply
  • The sample works in the following manner

    • Several work items are initialized:

    • Serial data is sent from the computer to nRF9160 through a micro USB and uart_cb() gets called
    • In uart_cb() the incoming serial data is processed and put into the queue (at the top of main.c I have created an array of static struct work_data of size 5)
    • Each incoming element (separated by 10 (=LF)) is submitted to the work queue through k_work_submit()
    • When the work queue Thread gets scheduled to run, it will call pub_uart_mqtt() for each element, where the elements will be published to the topic CONFIG_MQTT_PUB_TOPIC through data_publish()

    Try following these steps:

    • Build and run the sample
      • west build -b nrf9160_pca10090ns
      • nrfjprog --eraseall
      • west flash
    • Subscribe to the topic /my/publish/topic -v from the mosquitto broker, by typing the following in a command line (cmd, git bash etc..)
      • mosquitto_sub -h mqtt.eclipse.org -t /my/publish/topic -v
    • Open Tera Term with the following setup:

    • Then, in Tera Term, type in e.g. "Hey", followed by enter and you should see the following response in the command line where mosquitto_sub -h were called

Children
No Data