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.

  • Update I used uart_event_handle function instead of uart_getstring and uart_putstring but still not able to send data over mesh

    I only modified uart_error_handle() and commented uart_putstring and uart_getstring 

    void uart_error_handle(app_uart_evt_t * p_event)
    {
        //added 
        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);
                
                send_my_message(s); //failed to pass s value to this function
               
                Index = 0;
            }
        }
        
        else 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);
        }
    }
    
    //send_my_message function
    
    void send_my_message (uint8_t* s)                          
    {
        uint32_t status=0;
        uint8_t buffer[10];
        strcpy(buffer, 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);
                       }
                    }
    }

  • Hi Arij, 

     

    I would suggest to set the logging debug level to LOG_LEVEL_DBG1 when init logging module, and in mesh_msg_handle() in access.c you print out more information in the call  __LOG(LOG_SRC_ACCESS, LOG_LEVEL_DBG1, "RX: [aop: 0x%04x]\n", opcode.opcode); so that it not only printout opcode but also other information such as message src, dst, length, buffer, etc. 

    You can do the same inside packet_tx() as well. 

    By doing this you can monitor all message processed at the node. 

     

    Have you verified that you mesh functions normally ? You can control LED on and off from your client ? 

    How did you check that your send_my_message() sends random data ? Please try to send just one byte first. 

    We posted an example here combining light switch example SDK v2.0.1 and ble_app_uart for SDK v15 not sure if needed for you though. 

     

     

  • I added the call   __LOG(LOG_SRC_ACCESS, LOG_LEVEL_DBG1, "TX: Msg %s \n", p_tx_message->p_buffer) to packet_tx() function in access.c, but it doesn't show my messages, I'm not sure if I'm doing it right,

    I verified my mesh functions and they work normally, I'am able to send and receive my messages over mesh from server to client and vice versa when I press a button, but not the messages that I want to send from UART.

    Yes I tested that example combining light switch example SDK v2.0.1 and ble_app_uart sdk v15 and I'am using it on the server side in order to get the data received from the phone and put it on mesh but I'm struggling on how to acheive that. Could you please check my code above and see if it's correct, thank you 
     

  • How do you check on the other side if you are receiving correct data ? 

    The way you printing the message out is not very correct. It's a byte array, not a string. It's better to do a loop to print out every byte of the array instead of doing that. And please do the same with the RX on the other side. You may want to print the payload length out also.

  • Now this function __LOG(LOG_SRC_ACCESS, LOG_LEVEL_DBG1, "TX: Msg %s\n", p_tx_message->p_buffer) work for printing the message, I don't know why it doesn't at first when I added it, but now my problem is when I send data from pc (termite terminal) to my board and send it over mesh, It will be sent like this 

    this is the log of the sending side 

    here what I receive on the othe side 

    and here is a snippet of my code

    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);
    
         printf(" message : %s \n ", s);
          
         send_my_message(s); 
    
        }

    This is my send_my_message() function

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

    The string data is sent separately, please help

    Thank you

Related