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

sending ASCII bytes through Mesh between a nrf52840 development kit and two dongle

Hello everyone,

I am new and tried some example on the nrf52840 devkit and dongle, including light switch example. 

I am now going to send some ASCII bytes through the mesh between three boards and receive a verification message in the client side.

Actually I thought this is done by adding  sent and receive functions in the switch light example (server and client) inside the main.c. But after searching the devzone I was completely confused.

I read these discussions but I could not modify the code correctly.

https://devzone.nordicsemi.com/f/nordic-q-a/29836/send-and-receive-a-string-via-access-layer

https://devzone.nordicsemi.com/f/nordic-q-a/31256/receiving-simple-message-mesh/123576

https://devzone.nordicsemi.com/f/nordic-q-a/39629/how-to-send-data-to-all-node-over-mesh

https://devzone.nordicsemi.com/f/nordic-q-a/47611/sending-data-over-the-mesh-network

https://devzone.nordicsemi.com/f/nordic-q-a/46092/send-string-in-a-mesh-with-nrf52dk/

I have error on 

simple_message_OPCODE_SEND
and
the address_set function
and also in the server side:
status= access_model_publish(m_server.model_handle, &msg);

I think there are some different in the new version of the nRF52 SDK for mesh V.5 I used.

Could you please help me on this topic.

Thank you,

Sama

  • Hi, 

    There have been made a lot of changes and improvements from Mesh SDK v1.0.0 to v5.0.0. Unfortunately, we don't have any official examples for sending strings over mesh. The links you are referring to is a great starting point and gives you an idea of how you can do this. 

    When it comes to the error you get, can you get more details? What function gives which errors? What kinda error do you get? Can you provide some debug logs?

  • Hi,

    What I did is:

    copy the simple message model inside the vendor folder where there is the simple on-off model.

    add a new folder in the project file in the switch light client SES and add simple on-off and simple message models.

    add ../../../../../../models\vendor\simple_message\include and ../../../../../../models\vendor\simple_on_off\include to the User Include Directories field.

    add this code in the main.c in line 248 (switch(button_number)
    {
    case 1:
    case 3:
    set_params.on_off = APP_STATE_ON;)

    void send_my_message (void)
    {
    uint32_t status=0;
    uint8_t buffer[5]="Hello";
    uint8_t length;
    uint16_t address;
    access_message_tx_t msg;
    length= 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[3].model_handle, &msg);
    __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);
    }
    }
    }

    After running I get this

    Rebuilding ‘light_switch_client_nrf52840_xxAA_s140_7.2.0’ from solution ‘light_switch_client_nrf52840_xxAA_s140_7.2.0’ in configuration ‘Debug’
    Compiling ‘main.c’
    'simple_message_OPCODE_SEND' undeclared (first use in this function)
    each undeclared identifier is reported only once for each function it appears in
    implicit declaration of function 'address_set'; did you mean 'dsm_address_get'? [-Wimplicit-function-declaration]
    implicit declaration of function 'SEGGER_RTT_printf' [-Wimplicit-function-declaration]
    Compiling ‘mesh_provisionee.c’
    Compiling ‘rtt_input.c’
    Compiling ‘simple_hal.c’
    Build failed

    In addition to this, I do not know where I should add the void address_set(uint16_t addr) which is stated in the mentioned links.

    I am a beginner and I confuse when I deal with the names of different functions I do not know where they are and what they did. 

    Thank you,

    Sama

  • Hi,

    Have you had any progress with this? 

    You should put the send_my_message() function outside the button_event_handler(). And the void address_set(uint16_t addr) can be added to main.c.

    Additional you should add these static variables and include as well in your main.c:

    #include "simple_message_common.h"
    #include "simple_on_off_server.h"
    
    static simple_on_off_server_t m_server;
    
    static dsm_handle_t m_central_handle;

    Thanks for your patience.

  • Hi,

    Sorry for my late reply. I have been working on another part of the project.

    Now, I added these lines on the client-side:

    #include "simple_message_common.h"
    #include "simple_on_off_client.h"


    static simple_on_off_client_t m_client;
    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[0].model_handle, m_central_handle));
    }

    void send_my_message (void)
    {
    uint32_t status=0;
    uint8_t buffer[5]="Hello";
    uint8_t length;
    uint16_t address;
    access_message_tx_t msg;
    length= sizeof(buffer);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- send_message -----\n");
    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_client[0].model_handle, &msg);
    __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);
    }
    }
    }

    and also added the c files of simple_message_client and simple_onoff_client and their paths to the user include directories.

    and for server-side:

    #include "simple_message_common.h"
    #include "simple_on_off_server.h"

    static simple_on_off_server_t m_server;
    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_server.model_handle, m_central_handle));
    }

    void send_my_message (void)
    {
    uint32_t status=0;
    uint8_t buffer[5]="Hello";
    uint8_t length;
    uint16_t address;
    access_message_tx_t msg;
    length= 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_server.model_handle, &msg);
    __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);
    }
    }
    }

    and also added the c files of simple_message_server and simple_onoff_server and their paths to the user include directories.

    I want to send my message by pressing a button and stop that with another button.

    I added the send_my_message function in the button handler but it got stuck.

    So I have some questions: 

    1. Where should I add my function? Is needed any pre-requirement function?

    2. Due to existing the generic_onoff model in this example, may it cause a conflict with the simple_onoff model?

    3. In the access_model_publish_address_set function we assign an address for our model, right? how can I found if another model signed to this address or not? and is there any limitation to add models? 

    Could you please help me?

    Thank you in advance.

    Br,

    Sama

  • Hi,

    Is there any solution?

    Should I creat a new ticket?

Related