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

Send String from Server to Client in Light_Switch Example

Hi I am using Mesh V 4.0 and Stack V 16.0

I have created the Message Model in Client side and can able to send string from Client to Server on button press.

Now when I am trying to send command from Server to Client on button press event it is not getting sent.I am receiving below error 

<t: 192320>, main.c, 198, Button 1 pressed
<t: 192328>, access.c, 1196, Status=7<t: 192330>, main.c, 177, Status : 7
<t: 192332>, app_error_weak.c, 115, Mesh error 7 at 0x000268E9 (C:\nRF_mesh\nrf5_SDK_for_Mesh_v4.0.0_src\examples\light_switch\server\src\main.c:187)

static simple_on_off_client_t m_client;
static generic_onoff_server_t m_servers[2];
static bool                   m_device_provisioned;
static dsm_handle_t m_central_handle;



void address_set(uint16_t addr)
{
   ERROR_CHECK(dsm_address_publish_add(addr, &m_central_handle));
   ERROR_CHECK(access_model_publish_address_set(m_client.model_handle, m_central_handle)); 

}


void send_start (void) 
{
    uint32_t status=0;
    uint8_t buffer[2]={0x05,0xFB};
    uint8_t length;
    uint16_t address;
    access_message_tx_t msg;
    length= sizeof(buffer);
               if (length)
                { 
                  msg.opcode.opcode = 0xC5;
                  msg.opcode.company_id = 0x0059; // Nordic's company ID
      
                  msg.p_buffer = (const uint8_t *) &buffer[0];
                  msg.length =length;
                  address = 0x0005;                                            //SERVER ID 
                  address_set(address);
                  

//                SEGGER_RTT_printf(0,"Sending to group address 0x%04x\n", address);
                  status= access_model_publish(m_servers[0].model_handle, &msg);        //CHANGED TO 0 FROM 3 
                  __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status : %u \n", status);

                  if (status == NRF_ERROR_INVALID_STATE ||
                  status == NRF_ERROR_BUSY||status == NRF_ERROR_NO_MEM)
                   {
                     __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Cannot send. Device is busy.\n");
                      hal_led_blink_ms(LEDS_MASK, 50, 4);
                   }
                   else
                   {
                         ERROR_CHECK(status);
                   }
                }
}


static void button_event_handler(uint32_t button_number)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
    switch (button_number)
    {
        /* Pressing SW1 on the Development Kit will result in LED state to toggle and trigger
        the STATUS message to inform client about the state change. This is a demonstration of
        state change publication due to local event. */
        case 0:
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "User action \n");
            hal_led_pin_set(ONOFF_SERVER_0_LED, !hal_led_pin_get(ONOFF_SERVER_0_LED));
            app_onoff_status_publish(&m_onoff_server_0);
            break;
        }

       case 1:
               
        {   
            send_start();
            break;
    }   }
}

Parents
  • Hi Gecko, 

    What is at main.c line 177 ? The error code 7 means NRF_ERROR_INVALID_PARAM (please check nrf_error.h)

    But anyway if you want to send data from the server to the client the better way is to configure a client on the server node and then a server on the client node. Then you can send data the same way as how you send data from client to the server. 

    Of course it's possible to broadcast data from the server to the client but it's not usually how it's done. The server usually only broadcasts data when it receives a command to change state. 

Reply
  • Hi Gecko, 

    What is at main.c line 177 ? The error code 7 means NRF_ERROR_INVALID_PARAM (please check nrf_error.h)

    But anyway if you want to send data from the server to the client the better way is to configure a client on the server node and then a server on the client node. Then you can send data the same way as how you send data from client to the server. 

    Of course it's possible to broadcast data from the server to the client but it's not usually how it's done. The server usually only broadcasts data when it receives a command to change state. 

Children
No Data
Related