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

I want to send temperature (using existing sensor on nRF DK) data from server to client.

Hello,

I want to use existing Generic light switch model to send temperature sensor data from server to client.

using Light switch example of nRF Mesh V2.2.0.

Functionality of Light Switch:

  • The Button 1 on the client board turns ON LED 1 on the servers with Odd addresses.
  • The Button 2 on the client board turns OFF LED 1 on the servers with Odd addresses.
  • The Button 3 on the client board turns ON LED 1 on the servers with Even addresses.
  • The Button 4 on the client board turns OFF LED 1 on the servers with Even addresses 

Like wise without disturbing the existing functionality I want to send temperature data.

while pressing button 1 on client board It has to get temperature data from server and display it on RTT viewer. 

while pressing button 3 also on client board It has to get temperature data from server and display it on RTT viewer. 

along with that by pressing button 3 on server it has to send temperature data of the server to client.

please help me.

  • Hi,

    Have you already bought a temperature sensor or do you want to use the die temperature function on the dev kit itself? It seems like you want the die temperature. If you are using a temperature sensor, have you already hooked this part up to a dev kit & gotten temperature readings on the log?

    If not, I would focus on this part first.

    Next, do you really require mesh for this usecase? Are you planning on having multiple servers which each send temperature data to the client? If not, I would recommend taking a look at one of our easier ble central & peripheral examples instead.

    Then, I would focus on sending the acknowledged status message back to the client from the server. First off, you will need to change the functionality to get this working. Pressing the buttons on the client publishes a set message to the odd or even group address, which the odd & even servers are subscribed to. Therefore, you will not get an acknowledged message from the server in return, saying in essence: "Hey, I got your message & processed it correctly".

    You probably want to send an acknowledged unicast message to the server address & change the status message (see config_messages.h for tips & create your own status message reply) slightly so that you not only send a status code, but also a status value (i.e. temperature value). You will most likely want to create your own model to achieve this (or update the generic on off model).

    Update: You could also send a get message from the client to the server & the server will then send a status message back to the client. However, if you want to set the LED on the server & get the temperature, it could be an idea to use a acknowledged set message instead.

    Kind Regards,

    Bjørn

  • You could also send a get message from the client to the server & the server will then send a status message back to the client. However, if you want to set the LED on the server & get the temperature, it could be an idea to use a acknowledged set message instead.

    Can you help me in this regard.

    Where and what I have to change.

    here I did some changes look into that.

    in server/main.c

    /* Callback for reading the hardware state */
    static void app_onoff_server_get_cb(const app_onoff_server_t * p_server, bool * p_present_onoff, uint32_t *temp)
    {
    /* Resolve the server instance here if required, this example uses only 1 instance. */
    int32_t uiTempVal;
    sd_temp_get(&uiTempVal);
    *p_present_onoff = hal_led_pin_get(ONOFF_SERVER_0_LED);
    *temp = uiTempVal; //storing die temperature in temp variable in get call back.
    }

    generic_onoff_commom.h

    Here I changed the structure format

    /** Parameters for the Generic OnOff Status message. */
    typedef struct
    {
    uint8_t present_on_off; /**< The present value of the Generic OnOff state */
    uint8_t target_on_off; /**< The target value of the Generic OnOff state (optional) */
    uint32_t remaining_time_ms; /**< Remaining time value in milliseconds */
    uint32_t server_temp; /**<Trying to send temperature data> */
    } generic_onoff_status_params_t;
    
    

    app_onoff.c

    getting temperature value and sending through publish API.

    static void generic_onoff_state_set_cb(const generic_onoff_server_t * p_self,
    const access_message_rx_meta_t * p_meta,
    const generic_onoff_set_params_t * p_in,
    const model_transition_t * p_in_transition,
    generic_onoff_status_params_t * p_out)
    {
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "msg: SET: %d\n", p_in->on_off);
    //__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "msg: SET: %d\n", p_in->on_off);
    
    app_onoff_server_t * p_server = PARENT_BY_FIELD_GET(app_onoff_server_t, server, p_self);
    
    /* Update internal representation of OnOff value, process timing */
    p_server->value_updated = false;
    p_server->state.target_onoff = p_in->on_off;
    //p_out->server_temp = p_server->state.server_temp; //.................updated
    
    //p_in->server_temp = p_server->state.server_temp; ////////////...updated
    //p_server->state.server_temp = p_out->server_temp;
    
    if (p_in_transition == NULL)
    {
    p_server->state.delay_ms = 0;
    p_server->state.remaining_time_ms = 0;
    }
    else
    {
    p_server->state.delay_ms = p_in_transition->delay_ms;
    p_server->state.remaining_time_ms = p_in_transition->transition_time_ms;
    //p_out->server_temp = p_server->state.server_temp; //.................updated
    //p_server->state.server_temp = p_out->server_temp;
    }
    
    onoff_state_value_update(p_server);
    onoff_state_process_timing(p_server);
    
    /* Prepare response */
    if (p_out != NULL)
    {
    p_out->present_on_off = p_server->state.present_onoff;
    //p_out->present_on_off = p_server->state.server_temp;
    p_out->target_on_off = p_server->state.target_onoff;
    p_out->remaining_time_ms = p_server->state.remaining_time_ms;
    p_server->onoff_get_cb(p_server, &p_server->state.present_onoff,&p_server->state.server_temp);
    __LOG(LOG_SRC_APP, LOG_LEVEL_ERROR, "In set message %X\n" , p_server->state.server_temp);
    p_out->server_temp = p_server->state.server_temp; //.................updated
    //p_in->server_temp = p_server->state.server_temp;
    }
    }

    Is this correct way?

    almost I changed all structures and functionality to store temperature data.

    Here is the Output of changed code.

    In Client Button 1 st Instance.

    button 1 pressed on client.

     0> <t: 4457067>, main.c, 177, 
    0> 
    0> Button 0 pressed
    0> <t: 4457070>, main.c, 205, Sending msg: ONOFF SET 1
    0> <t: 4457080>, main.c, 224, Server temperature in button 1 20000038
    0> <t: 4458959>, main.c, 124, Acknowledged transfer success.
    0> <t: 4458961>, main.c, 150, OnOff server: 0x0103, Present OnOff: 0, Target OnOff: 1, Remaining Time: 100 ms, Temperature: 1966080

    on server reply to button 1:

    0> <t: 13272255>, app_onoff.c, 212, msg: SET: 1
    0> <t: 13272257>, app_onoff.c, 213, msg: temp of client: 1416368128
    0> <t: 13272262>, app_onoff.c, 250, In set message D321D14B
    0> <t: 13272264>, generic_onoff_server.c, 73, 
    0> Temperature in generic_on_offserver.c message: D321D14B
    0> <t: 13272267>, generic_onoff_server.c, 115, 
    0> forwarding from status send message .............///////////// 536934392
    0> <t: 13272271>, access.c, 1087, 
    0> Temperature in access.c message model replay after converting: 2000F8A2
    0> <t: 13273898>, main.c, 102, Setting GPIO value: 1

    button 2 pressed on client.

    0> <t: 4501945>, main.c, 177, 
    0> 
    0> Button 1 pressed
    0> <t: 4501947>, main.c, 205, Sending msg: ONOFF SET 0
    0> <t: 4501957>, main.c, 224, Server temperature in button 1 23F97
    0> <t: 4502782>, main.c, 124, Acknowledged transfer success.
    0> <t: 4502785>, main.c, 150, OnOff server: 0x0103, Present OnOff: 1, Target OnOff: 0, Remaining Time: 100 ms, Temperature: 1966080

    on server reply to button 2:

    0> <t: 15197613>, app_onoff.c, 212, msg: SET: 0
    0> <t: 15197615>, app_onoff.c, 213, msg: temp of client: 1416368128
    0> <t: 15197619>, app_onoff.c, 250, In set message D321D14B
    0> <t: 15197622>, generic_onoff_server.c, 73, 
    0> Temperature in generic_on_offserver.c message: D321D14B
    0> <t: 15197625>, generic_onoff_server.c, 115, 
    0> forwarding from status send message .............///////////// 536934392
    0> <t: 15197629>, access.c, 1087, 
    0> Temperature in access.c message model replay after converting: 2000F8A2
    0> <t: 15202533>, main.c, 102, Setting GPIO value: 0

    In Server.

    button 1 pressed.

    0> <t: 3846118>, app_onoff.c, 210, msg: SET: 1
    0> <t: 3846121>, app_onoff.c, 247, In set message 70
    0> <t: 3847758>, app_onoff.c, 124, Temperature after set message 70
    0> <t: 3847761>, generic_onoff_server.c, 247, publishing temperature from server: 64
    0> <t: 3847764>, main.c, 102, Setting GPIO value: 1
    0> <t: 3851044>, app_onoff.c, 124, Temperature after set message 70
    0> <t: 3851047>, generic_onoff_server.c, 247, publishing temperature from server: 0

    on client display info after button 1 pressed on server:

    0> <t: 2634559>, generic_onoff_client.c, 87, temperature in onoff client........... 1679687680
    0> <t: 2634562>, main.c, 155, OnOff server: 0x0103, Present OnOff: 0, Temperature: 641E0000
    
    

    button 2 pressed.

    0> <t: 3889954>, app_onoff.c, 210, msg: SET: 0
    0> <t: 3889958>, app_onoff.c, 247, In set message 70
    0> <t: 3894871>, app_onoff.c, 124, Temperature after set message 70
    0> <t: 3894874>, generic_onoff_server.c, 247, publishing temperature from server: 0
    0> <t: 3894877>, main.c, 102, Setting GPIO value: 0

    on client display info after button 2 pressed on server:

    0> <t: 4025437>, generic_onoff_client.c, 87, temperature in onoff client........... 1679687680
    0> <t: 4025440>, main.c, 155, OnOff server: 0x0103, Present OnOff: 0, Temperature: 641E0000

    I am sending Temperature value correctly, But it's not reflecting in client.


     

  • Sorry for the delayed response. Are you sure this does not have something to do with the way you are printing the messages in the log function? Have you tried using %d instead of %X for example?

  • Yes, I tried to print temperature data using both %d and %X,

    But no result.

    I am getting correct value in server before publishing.

    But while extracting in client, it's value changing.

    1. So, is there any way to extract meta data in correct way while receiving packet on client side.
  • What do you mean by extracting in client? Are you logging at different locations in the client & you notice a change in the value? Or does the value change as soon as it reaches the client?

Related