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

Mesh: sensor_server_status_publish function, Marshalling Data

I want to send sensor data using sensor_server_status_publish function, however struggling with data marshalling. I get unknown property ID or no data at all displayed in nRF Mesh app. Property ID (=0x004F) is correct as device properly responds to get messages.

I have tried to use both data Formats as described in Mesh Model specification (Page 121). Bellow image of data marshalling taken from the specification.

And the code:

  uint8_t * p_out = (uint8_t *)m_sensor_server.p_message_buffer;
  uint16_t bytes;

  // Format B
  bytes = 4;
  p_out[0] = ((1 << 1) | 0x01); // Sensor Data Lenght 1 Byte
  p_out[1] = (uint8_t)(SENSOR_PRESENT_AMB_TEMP_PROPERTY_ID << 8);
  p_out[2] = (uint8_t)(SENSOR_PRESENT_AMB_TEMP_PROPERTY_ID & 0xff);
  
  p_out[3] = 0xFF; // Sensor Data
  
  sensor_server_status_publish(&m_sensor_server.server.sensor_srv, 
                                p_out, bytes, SENSOR_OPCODE_STATUS);

Parents Reply Children
  • Thanks for response Terje. Indeed there was bitshift in the wrong direction. Unfortunately after fixing this I still get no Sensor Value in the app. It is updating (so published messages are received) but value as well as property ID does not appear.

  • Hi,

    How do you see that there are updates? Is there anything else that updates, and if so from what and to what?

    Regards,
    Terje

  • How do you see that there are updates?

    Text of "Sensor Values" and "Get" flicker in the app then message is received.

    I tried to simply copy data sent by Periodic Publishing, in this case it is recognized by the app.

    Maybe app accepts only Format A data and I am doing wrong marshaling for this format.

      // Format A
      bytes = 3;
      p_out[0] = ((1 << 1) | ((SENSOR_PRESENT_AMB_TEMP_PROPERTY_ID & 0x07) << 5));
      p_out[1] = (uint8_t)(SENSOR_PRESENT_AMB_TEMP_PROPERTY_ID >> 3);
      
      p_out[2] = 0xFF; // Sensor Data

    First two bytes taken from the periodic publishing are 0xE0 and 0x09, and encoded by me are 0xE2 and 0x09, so first byte is not correct. However bit1 encodes value length and has to be set if my sensor value length is 1 byte.

    Ok I think I found the problem: "The Length field is a 1-based uint4 value (valid range 0x0–0xF, representing range of 1–16).". So length of 0 represents 1 byte.

    Thank you for help.

  • Hi,

    Ah! Thanks for sharing the solution!

    That representation might look a bit weird at first, but given that values are packed tightly into as few bits as possible, it makes sense to also use the value 0x0 and so that encoding makes sense.

    Regards,
    Terje

Related