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

Issue sending data from UART over mesh

Hi, 

I've been working on a project where I need to send data from UART over mesh, I managed to create custom model for sending string data over mesh, I did merge UART example with mesh SDK, I started with light switch demo from mesh SDK v2.0.1 and with nRF5 SDK v15, now I'm trying to get the data received on UART to send it over mesh, but I didn't do it correctly, the send_my_message function kept sending the same random data, Any idea on how to make that work, it would be greatly appreciated.

Here is a snippet of my code:

//function to send data over mesh

void send_my_message (char s[])                          
{
    uint32_t status=0;
    uint8_t buffer[5];
    strcpy(buffer, (uint8_t) s);                         
    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;
                 status= simple_message_client_set_unreliable(&m_clients[0], buffer, length);
                 __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);
                   }
                }
}

//function for receiving and sending data over UART
void uart_putstring(char s[])
  {
       uint8_t len = strlen(s);
       for (uint8_t i = 0; i < len; i++)
         {
       while (app_uart_put(s[i]) != NRF_SUCCESS);
         }
   }

void uart_getstring(char s[])
   {
    uint8_t len = strlen(s);
    for (uint8_t i = 0; i < len; i++)
         {
       while (app_uart_get(&s[i]) != NRF_SUCCESS);
         }
   }
//how I send the data over mesh from UART

printf("\r\nUART example started.\r\n");

    for (;;)
    {
        (void)sd_app_evt_wait();
       // uint8_t cr;
        char s[5];

       uint32_t status = NRF_SUCCESS;

      // while (app_uart_get(&cr) != NRF_SUCCESS);
      // while (app_uart_put(cr) != NRF_SUCCESS);

      uart_getstring(s);  
      uart_putstring(s);
      
       send_my_message(s); // failed to send data from UART 

    }

here is my log 

Thank you,

A.

  • Hi Arji, 

     

    Please try testing with sending an array of bytes. Don't play with string first. 

    You can try to send something like 

    uint8_t data_array = {1,2,3,4,5}

    And check on the other side if you receive 1 2 3 4 5 array or not. To print an array out , you can use a loop and print each element out. 

    Main different between a string and byte array is the terminate character. In C it's the NULL character (0). But I don't think this char sent over mesh because of the length. 

     

     

     

  • Hi again,

    I want the data that I receive on UART (string data) to send it over mesh, I tested with array of bytes as you said and it works, but in my case I want to get any data sent by pc terminal(termite) to send it over mesh, I did a lot of tests and nothing wrong with mesh, now I switch using this function  to get data from UART: 

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        if (p_event->evt_type == APP_UART_DATA_READY)
        {
          while (app_uart_get(&cr) != NRF_SUCCESS);
            s[Index++] =  cr;
            s[Index] = 0;
            if(cr == '\n')
            {
                printf("RX end : %s\r\n", s);   //show nothing     
                send_my_message(s); //fail here 
                Index = 0;
            }
         }
        
        if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_communication);
        }
        else if(p_event->evt_type == APP_UART_FIFO_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_code);
        }
    }

    So this function works fine when I don't add send_my_message() function as shown in line 11 above in code, but when add it,  it stuck and the function shows nothing 

    here is result without send_my_message() function

    and here with send_my_message() function

    send_my_function() is mentioned in my previous comment, please help

    Thank you

  • Can you check what when wrong when you call send_my_message() ? any assertion ? 

    Did the application run normally after that or it crashed ? 

    How did you setup  __LOG  ? via RTT or UART ? 
    If you printing out log via UART you will have a conflict with your printf. 

     

    If you comment out printf do you receive the data on the other node in mesh ? 

  • Here's what happen when I call send_my_message(), there is a softdevice assert and a warning:  mesh_softdevice_init.c,  104, sd_ble_enable: app_ram_base should be adjusted to 0x200032C8


    For the setup  __LOG, I'am not sure if you talk about this 

    or the setup in sdk_config.h, actually I added the setup_config.h of the uart_example and add some defines from sdk_config.h of client example because I delete it from the project but in both files there is no defines for rtt or uart log enable, there is only nrf_log_enable which is set to 0 

    If I comment out printf, I don't receive any data on the other node and still have the same problem

Related