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

Serial Mesh

Hi,

 I have been working with mesh and I'm using the version 4.2 Mesh SDK.As I understand it I should use nrf_mesh_serial_tx() api to send serial message.When I use this api to send message there is 2 unknown characters come up before the message. I am sharing the result of between nrf52 DK and PC. Also I tried make a serial communication between  nrf52 DK and raspberry. I got the same result. Am I doing someting wrong or is this a bug? Additionally, I added the mesh serial to light switch client model and I observed the same results.

 I just wrote the following code to make a simple example and added the result I got on the serial monitor.

 

int main(void)
{
    initialize();
    start();
    hal_led_mask_set(LEDS_MASK, LED_MASK_STATE_OFF);
    hal_led_blink_ms(LEDS_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_START);
 
    char data[] = "Help";
    uint32_t result = nrf_mesh_serial_tx(data,sizeof(data));

    for (;;)
    {
      (void)sd_app_evt_wait();

    }
}

Thanking you in advance.

Parents
  • Hi,

    The unknown characters you are seeing is coming from these functions, serial_start() and nrf_mesh_serial_tx(). In the code snippet below I have commented on the parts that printed those, its from opcodes that are being sent.

    Inside nrf_mesh_serial.c:

    uint32_t nrf_mesh_serial_tx(uint8_t* p_data, uint32_t length)
    {
        if (serial_state_get() != NRF_MESH_SERIAL_STATE_RUNNING)
        {
            return NRF_ERROR_INVALID_STATE;
        }
        if (p_data == NULL)
        {
            return NRF_ERROR_NULL;
        }
        if (length == 0 || length > NRF_MESH_SERIAL_PAYLOAD_MAXLEN)
        {
            return NRF_ERROR_INVALID_LENGTH;
        }
    
        serial_packet_t * p_evt;
        uint32_t status = serial_packet_buffer_get(SERIAL_PACKET_LENGTH_OVERHEAD + length, &p_evt);
        if (status == NRF_SUCCESS)
        {
            //This part gives the "unknown characters" you see
            p_evt->opcode = SERIAL_OPCODE_EVT_APPLICATION;
            memcpy(p_evt->payload.evt.application.data, p_data, length);
            serial_tx(p_evt); 
        }
    
        return status;
    }

    Inside serial.c:

    uint32_t serial_start(void)
    {
        if (m_state != NRF_MESH_SERIAL_STATE_INITIALIZED)
        {
            __LOG(LOG_SRC_SERIAL, LOG_LEVEL_WARN, "Not initialized.");
            return NRF_ERROR_INVALID_STATE;
        }
        m_state = NRF_MESH_SERIAL_STATE_RUNNING;
        /* Send device started event. */
        serial_packet_t * p_start_packet;
        /* Should not fail: */
        uint32_t err_code = serial_packet_buffer_get(sizeof(serial_evt_device_started_t) + NRF_MESH_SERIAL_PACKET_OVERHEAD, &p_start_packet);
        if (NRF_SUCCESS != err_code)
        {
            __LOG(LOG_SRC_SERIAL, LOG_LEVEL_ERROR, "Unable to get a serial packet buffer, error_code: %u\n", err_code);
            m_state = NRF_MESH_SERIAL_STATE_INITIALIZED;
        }
        else
        {
            //This part gives out the "unknown characters" you see
            p_start_packet->opcode = SERIAL_OPCODE_EVT_DEVICE_STARTED;
            p_start_packet->payload.evt.device.started.operating_mode = SERIAL_DEVICE_OPERATING_MODE_APPLICATION;
            p_start_packet->payload.evt.device.started.hw_error = NRF_POWER->RESETREAS & RESET_REASONS_HW_ERROR;
            p_start_packet->payload.evt.device.started.data_credit_available = NRF_MESH_SERIAL_PAYLOAD_MAXLEN;
            serial_tx(p_start_packet);
        }
        return err_code;
    }

    Also be aware that it is not expected to have any user interface(human text) on serial in this example. Logging is printed out on RTT. So this is not the interface to print logs or send commands via terminal.

Reply
  • Hi,

    The unknown characters you are seeing is coming from these functions, serial_start() and nrf_mesh_serial_tx(). In the code snippet below I have commented on the parts that printed those, its from opcodes that are being sent.

    Inside nrf_mesh_serial.c:

    uint32_t nrf_mesh_serial_tx(uint8_t* p_data, uint32_t length)
    {
        if (serial_state_get() != NRF_MESH_SERIAL_STATE_RUNNING)
        {
            return NRF_ERROR_INVALID_STATE;
        }
        if (p_data == NULL)
        {
            return NRF_ERROR_NULL;
        }
        if (length == 0 || length > NRF_MESH_SERIAL_PAYLOAD_MAXLEN)
        {
            return NRF_ERROR_INVALID_LENGTH;
        }
    
        serial_packet_t * p_evt;
        uint32_t status = serial_packet_buffer_get(SERIAL_PACKET_LENGTH_OVERHEAD + length, &p_evt);
        if (status == NRF_SUCCESS)
        {
            //This part gives the "unknown characters" you see
            p_evt->opcode = SERIAL_OPCODE_EVT_APPLICATION;
            memcpy(p_evt->payload.evt.application.data, p_data, length);
            serial_tx(p_evt); 
        }
    
        return status;
    }

    Inside serial.c:

    uint32_t serial_start(void)
    {
        if (m_state != NRF_MESH_SERIAL_STATE_INITIALIZED)
        {
            __LOG(LOG_SRC_SERIAL, LOG_LEVEL_WARN, "Not initialized.");
            return NRF_ERROR_INVALID_STATE;
        }
        m_state = NRF_MESH_SERIAL_STATE_RUNNING;
        /* Send device started event. */
        serial_packet_t * p_start_packet;
        /* Should not fail: */
        uint32_t err_code = serial_packet_buffer_get(sizeof(serial_evt_device_started_t) + NRF_MESH_SERIAL_PACKET_OVERHEAD, &p_start_packet);
        if (NRF_SUCCESS != err_code)
        {
            __LOG(LOG_SRC_SERIAL, LOG_LEVEL_ERROR, "Unable to get a serial packet buffer, error_code: %u\n", err_code);
            m_state = NRF_MESH_SERIAL_STATE_INITIALIZED;
        }
        else
        {
            //This part gives out the "unknown characters" you see
            p_start_packet->opcode = SERIAL_OPCODE_EVT_DEVICE_STARTED;
            p_start_packet->payload.evt.device.started.operating_mode = SERIAL_DEVICE_OPERATING_MODE_APPLICATION;
            p_start_packet->payload.evt.device.started.hw_error = NRF_POWER->RESETREAS & RESET_REASONS_HW_ERROR;
            p_start_packet->payload.evt.device.started.data_credit_available = NRF_MESH_SERIAL_PAYLOAD_MAXLEN;
            serial_tx(p_start_packet);
        }
        return err_code;
    }

    Also be aware that it is not expected to have any user interface(human text) on serial in this example. Logging is printed out on RTT. So this is not the interface to print logs or send commands via terminal.

Children
Related