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

Multi-byte data using Mesh Sensor Model

Hello,

I am trying to adapt the new Mesh Sensor Model examples in v4.2.0 of the SDK for Mesh to allow sending >1 byte sensor data over the mesh network. I have two nRF52840DK boards, with one running the sensor server example and the other running the sensor client example. I have been able to successfully use the stock example code to transmit 1 byte of data from server to client. 

I tried modifying the code to send 4 data bytes by modifying the sensor server example file "main.c". I first modified the code on line 192 from

required_out_bytes = 1;
  to

required_out_bytes = 4;

Then I replaced lines 225-227 with the following lines:

p_out[0] = 0x00; p_out[1] = 0xC0; p_out[2] = 0xFF; p_out[3] = 0xEE;
*p_out_bytes = 4;

The modified code builds with no errors, but when I press RTT key 8 on the client side to send the status GET message for the Motion Sensed property I receive the following error in the server RTT terminal:

<t:     175638>, main.c,  240, inadequate buffer (0x0042 (66), 4, 1) = (property id, required, actual)
<t:     175645>, app_sensor_utils.c,  705, ERR: sensor_get_cb() failed (1, 0) = (bytes expected, bytes returned).
<t:     175649>, app_error_weak.c,  105, Mesh assert at 0x00028512 (:0)

Upon further inspection, it seems the line that throws this error comes from the file "app_sensor_utils.c" inside the "sensor_current_value_set(sensor_cadence_t * p)" function.

if (bytes != p->range_value_bytes_allocated)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_ERROR,
              "ERR: sensor_get_cb() failed (%d, %d) = (bytes expected, bytes returned).\n",
              p->range_value_bytes_allocated,
              bytes);

        NRF_MESH_ASSERT(false);
    }

I have attempted to work back from this point to find where the "range_value_bytes_allocated" value is set, but I have not been able to find it.

I appreciate any and all assistance you can provide me in resolving this issue!

Parents
  • Hi.

    Unfortunately, our Mesh experts are on vacation at the moment, but I'll do my best to help in the meantime.

    range_value_bytes_allocated is set to range_vector_bytes, one of the arguments in the cadence_initialize function in app_sensor_utils.c:519.

    cadence_initialize is called in two different functions:

    cadence_new and sensor_cadence_create.

    In cadence_new, range_vector_bytes is set by the cadence_bytes_get function, which in turns calls range_vector_bytes_get. In range_vector_bytes_get, we find that range_vector_bytes is set to sizeof(pir_data_size_t). pir_data_size_t is defined in app_sensor.h as a uint8_t.

    If we track the flow through sensor_cadence_create instead, we find the same path through cadence_bytes_get.

    Searching through the sample for pir_data_size_t reveals that it is only used in two places, and both places are only using the size of the type. No variable of the type pir_data_size_t is ever created. The two places the size of pir_data_size_t is used is in range_vector_bytes_get (app_sensor_utils.c:79) and delta_vector_bytes_get (app_sensor_utils.c:93).

    I hope that helps you getting further.

    Best regards,

    Didrik

Reply
  • Hi.

    Unfortunately, our Mesh experts are on vacation at the moment, but I'll do my best to help in the meantime.

    range_value_bytes_allocated is set to range_vector_bytes, one of the arguments in the cadence_initialize function in app_sensor_utils.c:519.

    cadence_initialize is called in two different functions:

    cadence_new and sensor_cadence_create.

    In cadence_new, range_vector_bytes is set by the cadence_bytes_get function, which in turns calls range_vector_bytes_get. In range_vector_bytes_get, we find that range_vector_bytes is set to sizeof(pir_data_size_t). pir_data_size_t is defined in app_sensor.h as a uint8_t.

    If we track the flow through sensor_cadence_create instead, we find the same path through cadence_bytes_get.

    Searching through the sample for pir_data_size_t reveals that it is only used in two places, and both places are only using the size of the type. No variable of the type pir_data_size_t is ever created. The two places the size of pir_data_size_t is used is in range_vector_bytes_get (app_sensor_utils.c:79) and delta_vector_bytes_get (app_sensor_utils.c:93).

    I hope that helps you getting further.

    Best regards,

    Didrik

Children
Related