General Questions on Asset_tracker_v2 application

Hi, I'm just experimenting with my nRF9160 DK and have run into some questions regarding the default asset_tracker_v2 program and how some of it works. I have read the documentation regarding the asset_tracker_v2 application at: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.8.0/nrf/applications/asset_tracker_v2/doc/asset_tracker_v2_description.html#configuration

I have the following questions:

1. In the nRF Cloud Terminal interface, there perodically appears a "Received" message with fields such as appID, messageType, data, and ts. I'm curious as to where the "appId" field is defined within the asset tracker source code?

2. I've tried to append some test values to the payload that is sent to the nRF Cloud, but they don't seem to be sent to nRF Cloud. As an example, I've tried to append a field called "newvalue1" with an integer value of 10 to be sent every time the battery voltage data is sent to nRF Cloud. After updating the structure definitions as appropriate, I added "modem_module_event->data.bat.newvalue1 = 10;" after the timestamp line within the battery_data_get() function within modem_module.c.

I have additionally added ".bat_newvalue = msg->module.modem.data.bat.newvalue1" to the if (IS_EVENT(msg, modem, MODEM_EVT_BATTERY_DATA_READY)) part of data_module.c and updated the cloud_data_battery definitions as appropriate. However, no additional data appears to be sent to nRF Cloud beyond the battery voltage and timestamp. I was wondering if there are any additional fields that I need to update in order for the data to send correctly?

3.I've been trying to implement functionality for the switches that are available on the nRF9160 DK, but am having some trouble with modifying the code such that it will respond to a change in state of the switches. A topic reply on another topic suggests referring to the http_update sample program, which has lent some insight into defining GPIO pins and reading them, but I was curious as to how this is handled within the asset_tracker_v2 program, as none of the modules seem to have explicit definition of the mappings of the buttons to physical GPIO pins. Thus, I was wondering if someone can explain where the pins are defined within this program, or maybe provide some more information regarding how to trigger an event when a switch is flipped as opposed to a button being pressed.

Thanks in advance to anyone who can offer any help!

Parents
  • Hi!
    I also just recently learned how to navigate the asset_tracker_v2 sample and here are some pointers:

    Regarding question 1: Data is encoded just before being sent to the cloud and this happens in `src/cloud/cloud_codec/nrf_cloud/nrf_cloud_codec.c` in the asset tracker (when using nRF Cloud). This is where the app IDs are filled in. Please note that polled sensor data (persisted until update) is encoded in `cloud_codec_encode_batch_data(...)`, while button presses (appearing as events) have a special `cloud_codec_encode_ui_data(...)` function.

    About question 2: adding some data to an existing event is a good start. `MODEM_EVT_BATTERY_DATA_READY` is an event that the data module subscribes to. It then calls `cloud_codec_populate_bat_buffer(...)` to save the data for later transmission. Now, you just have to add something to `nrf_cloud_codec.c:add_batch_data` so that the data is actually encoded. We use cJSON along with lots of helper functions there.
    Maybe you can try to add another call to `add_data` to also add your custom data?
    Later, you might want to define custom events and an additional cloud buffer for your data. (It's a known issue that this requires so many code changes - We're working on that.)

    Lastly, question 3: The asset tracker uses the DK Buttons and LEDs library in the UI module to handle button presses.

Reply
  • Hi!
    I also just recently learned how to navigate the asset_tracker_v2 sample and here are some pointers:

    Regarding question 1: Data is encoded just before being sent to the cloud and this happens in `src/cloud/cloud_codec/nrf_cloud/nrf_cloud_codec.c` in the asset tracker (when using nRF Cloud). This is where the app IDs are filled in. Please note that polled sensor data (persisted until update) is encoded in `cloud_codec_encode_batch_data(...)`, while button presses (appearing as events) have a special `cloud_codec_encode_ui_data(...)` function.

    About question 2: adding some data to an existing event is a good start. `MODEM_EVT_BATTERY_DATA_READY` is an event that the data module subscribes to. It then calls `cloud_codec_populate_bat_buffer(...)` to save the data for later transmission. Now, you just have to add something to `nrf_cloud_codec.c:add_batch_data` so that the data is actually encoded. We use cJSON along with lots of helper functions there.
    Maybe you can try to add another call to `add_data` to also add your custom data?
    Later, you might want to define custom events and an additional cloud buffer for your data. (It's a known issue that this requires so many code changes - We're working on that.)

    Lastly, question 3: The asset tracker uses the DK Buttons and LEDs library in the UI module to handle button presses.

Children
  • Hi, thank you very much, this is very helpful information. Regarding the last question on buttons and LEDs however, I noticed that there is a file called nrf9160dk_nrf9160_ns.overlay inside \nrf\applications\asset_tracker_v2\boards that seems to define which GPIO pin maps to which led. 

    I was wondering if this is indeed where the mappings are defined, and if so, is there a similar file for buttons/switches? What I've experimented with so far was to define a "sw0" inside dk_buttons_and_leds.h similar to what the buttons and leds are already defined to try and trigger an event whenever a switch is flipped (just trying to get it triggered every time there is a change in state of the switch for now, similar to a button when it's pressed) but that didn't seem to work.

Related