P2P custom firmware RAK3172

Hallo,

I’m trying to create my custom firmware based on the RUI3 firmware with two RAK3172 modules.
One module should be the sender and one module the receiver.
Transmitter side: I’m sending binary messages coming from UART2
Receiver side: I want to receive the raw bytes and also send them via UART2 to another device.

Is such an example already available or could anyone help me with creating such a firmware. I tried using the RUI3 example for LoRa_P2P but based on that it is more difficult than I thought to modify the code to be suitable for my needs.

This is what I tried, but it doesn’t really do what I thought.

void loop()
{
    // Read data from UART2 (Serial2)
    while (Serial2.available()) {
        char c = Serial2.read();
        if (c == '\n' || uart2_len >= UART2_BUF_SIZE - 1) {
            uart2_buffer[uart2_len] = '\0';  
            uart2_len = 0;
            rx_done = true; 
            break;
        } else {
            uart2_buffer[uart2_len++] = c;
        }
    }

    uint8_t payload[UART2_BUF_SIZE];
    memcpy(payload, uart2_buffer, strlen(uart2_buffer));


    bool send_result = false;
    if (rx_done) {
        rx_done = false;
        while (!send_result) {
            send_result = api.lora.psend(strlen((char*)payload), payload);
            Serial.printf("P2P send %s\r\n", send_result ? "Success" : "Fail");
            if (!send_result) {
                Serial.printf("P2P finish Rx mode %s\r\n", api.lora.precv(0) ? "Success" : "Fail");
                delay(1000);
            }
        }
    }

    delay(500);
}

Thanks

Is this even possible or do I need to change code on the RUI3 SDK? I think UART2 is reserved for AT commands, which means when I send anything except for AT commands, I’ll get the error “AT_COMMAND_NOT_FOUND”.

I am not sure if I understand what you are trying to do.

What is connected to the UART2?

You can send out data over UART to e.g. a computer or a host MCU, but you cannot use it to connect two RAK3172 and let them communicate with each other.

I’m sorry if I haven’t explained my setup properly.
I have two hardware components that usually communicate with each other over serial RS422. I want to replace the serial cable with a wireless LoRa connection. One device is sending RS422 signals to a RS422 to UART converter which is connected to one RAK3172. This should send the data over LoRa to another RAK3172 and transmit the signals to a UART to RS422 converter which is again connected to the other hardware device.

I hope that clarifies things a bit.

There are two options, depending on your “hardware component”

  1. If you can change the firmware in your “hardware component”
    Just send AT commands from your “hardware component” to the RAK3172 to initiate the sending
    Listen to +EVT:RX events on the other “hardware component” to receive the data

  2. If you cannot change the firmware in your “hardware component”

  • Option 1 use UART1:
    You will need to use UART1 (Serial1) of the RAK3172 to receive the data from the “hardware component”, then send it over LoRa
    Use RX callback on the other RAK3172 to get the LoRa P2P payload and send it to your other “hardware component” over UART1 (Serial1)
    But then you cannot use lowest power saving mode, only STOP mode 1.

  • Option 2 use UART2:
    Initialize UART2 of the RAK3172 as custom with Serial.begin(115200, RAK_CUSTOM_MODE);
    Receive data over UART2 from your “hardware component” and send it over LoRa
    Initialize UART2 of the other RAK3172 as custom with Serial.begin(115200, RAK_CUSTOM_MODE);
    Use RX callback on the other RAK3172 to get the LoRa P2P payload and send it to your other “hardware component” over UART2 (Serial)
    But then you cannot use AT commands anymore.
    But you can setup the complete transmission parameters with API calls from your application.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.