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

Turn on client LED with another's client signal in Mesh Network

Hello to everyone.

I´m working with the Light_switch examples (server-client-provisioner) in BLE Mesh 3.10 for nRF52 DK PCA10040.
I´m trying to make a network with 2 clients and 2 servers. Obviously, both clients can send a message to servers and I know that I can connect two clients eachother but what I want to know is if I can take the code of the server (the code that makes the server to turn on the LED when a client send a message) and put it on the client's code. That´s only to be sure (phisically) that the message was sent correctly, watching the LED.

I hope you can help me.

Parents Reply Children
  • /*****CLIENT*****/
    
    #include <stdint.h>
    #include <string.h>
    
    /* HAL */
    #include "boards.h"
    #include "simple_hal.h"
    #include "app_timer.h"
    
    /* Core */
    #include "nrf_mesh_config_core.h"
    #include "nrf_mesh_gatt.h"
    #include "nrf_mesh_configure.h"
    #include "nrf_mesh.h"
    #include "mesh_stack.h"
    #include "device_state_manager.h"
    #include "access_config.h"
    
    /* Provisioning and configuration */
    #include "mesh_provisionee.h"
    #include "mesh_app_utils.h"
    
    /* Models */
    #include "generic_onoff_client.h"
    
    /* Logging and RTT */
    #include "log.h"
    #include "rtt_input.h"
    
    /* Example specific includes */
    #include "app_config.h"
    #include "nrf_mesh_config_examples.h"
    #include "light_switch_example_common.h"
    #include "example_common.h"
    #include "ble_softdevice_support.h"
    
    #define APP_STATE_OFF                (0)
    #define APP_STATE_ON                 (1)
    
    #define APP_UNACK_MSG_REPEAT_COUNT   (2)
    
    static generic_onoff_client_t m_clients[CLIENT_MODEL_INSTANCE_COUNT];
    static bool                   m_device_provisioned;

    Hello Mttrinh, thank you for answer.
    Actually, in the main.c code, looks like the one above. I've done some chenges in the code, adding libraries, the generic_onoff_server model and another stuff:

    /*****CLIENT*****/
    
    #include <stdint.h>
    #include <string.h>
    
    /* HAL */
    #include "boards.h"
    #include "simple_hal.h"
    #include "app_timer.h"
    
    /* Core */
    #include "nrf_mesh_config_core.h"
    #include "nrf_mesh_gatt.h"
    #include "nrf_mesh_configure.h"
    #include "nrf_mesh.h"
    #include "mesh_stack.h"
    #include "device_state_manager.h"
    #include "access_config.h"
    #include "proxy.h"
    
    /* Provisioning and configuration */
    #include "mesh_provisionee.h"
    #include "mesh_app_utils.h"
    
    /* Models */
    #include "generic_onoff_client.h"
    #include "generic_onoff_server.h"
    
    /* Logging and RTT */
    #include "log.h"
    #include "rtt_input.h"
    
    /* Example specific includes */
    #include "app_config.h"
    #include "example_common.h"
    #include "nrf_mesh_config_examples.h"
    #include "light_switch_example_common.h"
    #include "app_onoff.h"
    #include "ble_softdevice_support.h"
    
    #define APP_STATE_OFF                (0)
    #define APP_STATE_ON                 (1)
    #define ONOFF_SERVER_0_LED           (BSP_LED_0) //***********************
    #define APP_ONOFF_ELEMENT_INDEX      (0)         //***********************
    
    #define APP_UNACK_MSG_REPEAT_COUNT   (2)
    
    static generic_onoff_client_t m_clients[CLIENT_MODEL_INSTANCE_COUNT];
    static bool                   m_device_provisioned;
    
    //SERVER FUNCTION
    /*************************************************************************************************/
    /*************************************************************************************************/
    /*************************************************************************************************/
    static void app_onoff_server_set_cb(const app_onoff_server_t * p_server, bool onoff);
    static void app_onoff_server_get_cb(const app_onoff_server_t * p_server, bool * p_present_onoff);
    
    /* Generic OnOff server structure definition and initialization */
    APP_ONOFF_SERVER_DEF(m_onoff_server_0,
                         APP_CONFIG_FORCE_SEGMENTATION,
                         APP_CONFIG_MIC_SIZE,
                         app_onoff_server_set_cb,
                         app_onoff_server_get_cb)
    /*************************************************************************************************/
    /*************************************************************************************************/
    /*************************************************************************************************/

    Also, I copy-paste this part of the server code to the client:

    //SERVER FUNCTION
    /*************************************************************************************************/
    /*************************************************************************************************/
    /*************************************************************************************************/
    /* Callback for updating the hardware state */
    static void app_onoff_server_set_cb(const app_onoff_server_t * p_server, bool onoff)
    {
        /* Resolve the server instance here if required, this example uses only 1 instance. */
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setting GPIO value: %d\n", onoff)
    
        hal_led_pin_set(ONOFF_SERVER_0_LED, onoff);
    }
    
    /* Callback for reading the hardware state */
    static void app_onoff_server_get_cb(const app_onoff_server_t * p_server, bool * p_present_onoff)
    {
        /* Resolve the server instance here if required, this example uses only 1 instance. */
    
        *p_present_onoff = hal_led_pin_get(ONOFF_SERVER_0_LED);
    }
    
    static void app_model_init(void)
    {
        /* Instantiate onoff server on element index APP_ONOFF_ELEMENT_INDEX */
        ERROR_CHECK(app_onoff_init(&m_onoff_server_0, APP_ONOFF_ELEMENT_INDEX));
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "App OnOff Model Handle: %d\n", m_onoff_server_0.server.model_handle);
    }
    /*************************************************************************************************/
    /*************************************************************************************************/
    /*************************************************************************************************/

    But I can't make it work.
    Any ideas?

  • Can you give me more details on what is not working? Do you get any error codes? 

  • There´s no error codes and the client example is working normally.
    It's like the server code wasn't there.

  • Sorry for not answering before.
    The image shows all the elements that the Client has in the App.
    Are the same elements that has in a "normal" client code.

Related