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

Receive string message from node in ble mesh.

I have extend the light switch example to send message to the other node. I have refer This example to send message. But how to configure another node to receive the message and relay the same message to server using WiFi. Will you please provide some sample example code to receive the message and relay that message. It also gives the error "Undefined reference to address_set." in following code

uint32_t status=0;
uint8_t buffer[30];
uint8_t length;
uint16_t address;
access_message_tx_t msg;
length= SEGGER_RTT_Read(0,buffer, sizeof(buffer));
           if (length)
            {
              msg.opcode.opcode =simple_message_OPCODE_SEND;
              msg.opcode.company_id = 0x0059; // Nordic's company ID
      
              msg.p_buffer = (const uint8_t *) &buffer[0];
              msg.length =length;
              address = 0xCAFE;
              address_set(address);
              SEGGER_RTT_printf(0,"Sending to group address 0x%04x\n", address);
              status= access_model_publish(m_clients[0].model_handle, &msg);

              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);
               }
            }
  • The relay functionality should already be enabled if you take a look at the light_switch example in the mesh sdk v1.0.1 for example. In network_init() in network.c, the m_relay_enable boolean is set to true during initialization of the network layer. 

    The should_relay() function inside network.c decides whether a packet should be relayed or not. The packet_relay() function relays the actually packet. The ttl is decremented inside the packet_relay function.

    This link (search for Network Layer)  also verifies that the network layer is responsible for the relay feature, just as the Nordic Mesh SDK has implemented it.

  • Thanks for you response.

    But how we know that message is relayed, because at server side in light switch example message is received in function set_cb(). So relaying of packet is automatically handled by sdk or we have use access_model_publish to manually relay it? and at remote node how we know the message is received from relay node or how we detect message is received or not?

  • should_relay() method returns true only when dst address is group address and not unicast address, so that packet_relay() method is not called when dst address is unicast address. 

Related