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

Receive data to nrf9160 from the server using MQTT

Hi,

I am developing the system where I am sending the data of three sensors to the server using MQTT. For the above development, I used two microcontrollers one to collect the data from the sensors and nrf9160 to handle MQTT Prorocol.

Also need to add the feature of user-specific data should display. ( user will send the ID no of the sensor to nrf9160 from the server and only that sensor ID data will be display)

I am successfully sending the data to the server using one channel but I now want to implement user-specific.


Question:

1) To receive the data from the server can I use the same channel which I am using to send data to a server?

or do I need to create a different channel for it?

Also, you can suggest me alternate option to implement the above idea.

Parents Reply Children
  • When your node should fetch data from the server, you subscribe to a specific topic.

    Just to make sure, So in this situation server would be the publisher and Nordic device will become subscriber. Right?

    Can we use same topic which we used to send data or need to create different topic name ?

    Kind Regards,

    Rahul Kidecha

  • Hi Rahul,

     

    Rkidechaa said:
    Just to make sure, So in this situation server would be the publisher and Nordic device will become subscriber. Right?

    You subscribe to a topic, and when anyone publishes to that topic; you will be notified with the data.

    The publisher can be anyone connected to the mqtt-broker.

     

    Rkidechaa said:
    Can we use same topic which we used to send data or need to create different topic name ?

     Yes, that is possible. Usually you want to differentiate your subscribed and publish topics; but this shall work.

     

    Kind regards,

    Håkon

  • Hi Hakon,

    Thank you for your reply.

    1) To receive the data from server I used different topic and it worked.

    Now I don't know where exactly it storing the feedback data because I need to use that data to enable and disable the sensor.

    2) publishing data to broker and receiving data from broker will work parallel ? Because I got the error (#define EBUSY 16 /* Mount device busy */ ) when tried to receive the data from broker when nrf9160 publishing some other data to broker. (topic name is different)

    3) If parallel is not possible then what could be fastest way to work in continues mode. like publishing and receiving works simultaneously. In our project we are sending the data over LTE in every 5 minute. 

    Thank you in Advance.

    With Regards,
    Rahul 

  • Hi Rahul,

     

    Rkidechaa said:
    Now I don't know where exactly it storing the feedback data because I need to use that data to enable and disable the sensor.

    The received data? That is available in the callback handler:

    https://github.com/nrfconnect/sdk-nrf/blob/v1.5.1/samples/nrf9160/aws_fota/src/main.c#L196-L227

     

    Rkidechaa said:
    publishing data to broker and receiving data from broker will work parallel ? Because I got the error (#define EBUSY 16 /* Mount device busy */ ) when tried to receive the data from broker when nrf9160 publishing some other data to broker. (topic name is different)

    Not sure which call returns EBUSY, but in general you need to invoke the mqtt state machine in between each transfer (ie: let the main loop run).

    Could you share where you get this error and what calls you queued up previous to this error?

    Rkidechaa said:
    If parallel is not possible then what could be fastest way to work in continues mode. like publishing and receiving works simultaneously. In our project we are sending the data over LTE in every 5 minute. 

    the mqtt library requires that mqtt_input() is called in between each operation.

    Note that sending data each 5 minutes will be power consuming for your application. If your application is battery powered, you should consider buffering up data, and sending over the network in larger chunks once per hour for instance. I fully understand that buffering up packets isn't always possible, as latency also plays in as a factor.

     

    Kind regards,

    Håkon

  • Hi,

    I am using mqtt_simple sample code to subscribe to one topic and need to store the received data from that subscribe topic.

    So where exactly that data stores ?

    the mqtt library requires that mqtt_input() is called in between each operation.

    Note that sending data each 5 minutes will be power consuming for your application. If your application is battery powered, you should consider buffering up data, and sending over the network in larger chunks once per hour for instance. I fully understand that buffering up packets isn't always possible, as latency also plays in as a factor.

    Thank you for advice. But we want to plot real time graph from those data. So that is why we chose to send after every 5 min as per battery consideration.

    Thanks you,

    Rahul

Related