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

Send "1" or "0" (int) from server to client in Light_switch

Hello to everyone.

I'm working with Light_switch example in Mesh 3.1, with nRF52832 SDK (PCA10040).
I'm trying to stablish communication from server to client, sending a message. I've asked something similar here, but only for the function that can help me to send the message.
Now, I'm looking for the correct use of that information. I was reading in infocenter.nordicsemi that the function that Mttrinh told me (in the past question): generic_onoff_server_status_publish() from app_onoff.c --> app_onoff_status_publish(), uses other two functions and variables:

And those two functions, use more stuff (talking about their structures).

What I want to do is to send an array of "int" values (1's and 0's). This values were read from 7 different pins from their high / low states.

int Val_Array[6];

  if(nrf_gpio_pin_read(25)==true){Val0=1;}
  if(nrf_gpio_pin_read(25)==false){Val0=0;}
  if(nrf_gpio_pin_read(26)==true){Val1=1;}
  if(nrf_gpio_pin_read(26)==false){Val1=0;}
  if(nrf_gpio_pin_read(27)==true){Val2=1;}
  if(nrf_gpio_pin_read(27)==false){Val2=0;}
  if(nrf_gpio_pin_read(28)==true){Val3=1;}
  if(nrf_gpio_pin_read(28)==false){Val3=0;}
  if(nrf_gpio_pin_read(29)==true){Val4=1;}
  if(nrf_gpio_pin_read(29)==false){Val4=0;}
  if(nrf_gpio_pin_read(30)==true){Val5=1;}
  if(nrf_gpio_pin_read(30)==false){Val5=0;}
  if(nrf_gpio_pin_read(31)==true){Val6=1;}
  if(nrf_gpio_pin_read(31)==false){Val6=0;}

  Val_Array[0]=Val0; Val_Array[1]=Val1; Val_Array[2]=Val2; Val_Array[3]=Val3;
  Val_Array[4]=Val4; Val_Array[5]=Val5; Val_Array[6]=Val6;

I was thinking how to put one by one the values on the status message from generic_onoff_server_status_publish() function, to send only a number instead of an entire string (array).
Can anyone guide me about this?

****************************************************************************************************************************
****************************************************************************************************************************
****************************************************************************************************************************

EDITED:
I was trying another way to do that above. On client's code, there's a part that prints a message depending of the "status" variable.

static void app_gen_onoff_client_transaction_status_cb(access_model_handle_t model_handle,
                                                       void * p_args,
                                                       access_reliable_status_t status)
{
    switch(status)
    {
        case ACCESS_RELIABLE_TRANSFER_SUCCESS:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Acknowledged transfer success.\n");
            break;

        case ACCESS_RELIABLE_TRANSFER_TIMEOUT:
            hal_led_blink_ms(LEDS_MASK, LED_BLINK_SHORT_INTERVAL_MS, LED_BLINK_CNT_NO_REPLY);
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Acknowledged transfer timeout.\n");
            break;

        case ACCESS_RELIABLE_TRANSFER_CANCELLED:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Acknowledged transfer cancelled.\n");
            break;

        default:
            ERROR_CHECK(NRF_ERROR_INTERNAL);
            break;
    }
}

This "status" is taken from "access reliable.h" file.

typedef enum
{
    /**
     * The reliable transfer was completed successfully.
     * @note This status is only used for @ref NRF_MESH_ADDRESS_TYPE_UNICAST addresses.
     */
    ACCESS_RELIABLE_TRANSFER_SUCCESS,
    /** The reliable transfer reached its timeout. */
    ACCESS_RELIABLE_TRANSFER_TIMEOUT,
    /** The reliable transfer has been cancelled. */
    ACCESS_RELIABLE_TRANSFER_CANCELLED
} access_reliable_status_t;

/**
 * Access layer reliable message callback type.
 * Used to indicate a successful or unsuccessful reliable transfer.
 *
 * @param[in] model_handle Access layer model handle.
 * @param[in] p_args       Generic argument pointer.
 * @param[in] status       Access reliable transfer status code.
 */
typedef void (*access_reliable_cb_t)(access_model_handle_t model_handle,
                                     void * p_args,
                                     access_reliable_status_t status);

What I don't know is how the code choose the correct message to be printed, because there's no "If" or "switch" sentence to evaluate a condition.
So, how the "server" uploads its information to the "client" or what does the server has to update to make the client choose one "status" message?

Sorry for expand my question. I hope you can help me.
Best regards,

John

Parents Reply Children
No Data
Related