Kampi / ESP32-RAK3172

LoRaWAN / LoRa P2P library for ESP32 MCUs and the RAK3172 LoRa SoM.
https://www.kampis-elektroecke.de
MIT License
18 stars 4 forks source link

What is the recommended version of RUI to use with the library #18

Open txf- opened 2 months ago

txf- commented 2 months ago

Hi,

I'm sorry if this information is posted anywhere, but can I ask what version of RUI3 is being tested with this library?

Kampi commented 2 months ago

Hi,

you can use all RUI versions. Maybe newer commands aren't implemented but the LoRa and LoRaWAN stuff is completely.

Feel free to give me feedback if a specific version causes trouble. Then I will check it.

txf- commented 1 month ago

And does this library work with the old 1.0.4 firmware? I noticed there is a config flag to enable and disable RUI3

Unfortunately, I was given a device with this version, and flashing the newest firmware is not so easy.

This is what I get when calling RAK3172_Init():

I (20108) RAK3172: Use library version: <Not defined>
I (20108) RAK3172: Modes:
I (20108) RAK3172:      [x] LoRaWAN
I (20108) RAK3172:      [ ] P2P
I (20108) RAK3172: Reset:
I (20108) RAK3172:      [ ] Hardware reset
I (20108) RAK3172:      [x] Software reset
I (20109) RAK3172: UART config:
I (20109) RAK3172:      Interface: 0
I (20109) RAK3172:      Buffer size: 512
I (20109) RAK3172:      Stack size: 4096
I (20109) RAK3172:      Queue length: 8
I (20109) RAK3172:      Rx: 17
I (20109) RAK3172:      Tx: 16
I (20109) RAK3172:      Baudrate: 9600
D (20110) intr_alloc: Connected src 43 to int 11 (cpu 0)
D (20110) RAK3172: Start RAK3172 event task
I (20110) RAK3172: Perform software reset...
I (20111) main_task: Returned from app_main()
D (20250) RAK3172:      Pattern detected at position 125. Use buffered size: 126
D (20250) RAK3172:      Response: LoRa (R) is a registered trademark or service mark of Semtech Corporation or its affiliates. LoRaWAN (R) is a licensed mark.
D (20251) RAK3172: Response: LoRa (R) is a registered trademark or service mark of Semtech Corporation or its affiliates. LoRaWAN (R) is a licensed mark.
D (20252) RAK3172:      Pattern detected at position 2. Use buffered size: 3
D (20252) RAK3172:      Response: 
D (20252) RAK3172: Response: 
D (20312) RAK3172:      Pattern detected at position 58. Use buffered size: 59
D (20313) RAK3172:      Response: ______  ___   _   __  _    _ _          _               
D (20313) RAK3172: Response: ______  ___   _   __  _    _ _          _               
D (20373) RAK3172:      Pattern detected at position 58. Use buffered size: 59
D (20373) RAK3172:      Response: | ___ \/ _ \ | | / / | |  | (_)        | |              
D (20373) RAK3172: Response: | ___ \/ _ \ | | / / | |  | (_)        | |              
D (20433) RAK3172:      Pattern detected at position 58. Use buffered size: 59
D (20434) RAK3172:      Response: | |_/ / /_\ \| |/ /  | |  | |_ _ __ ___| | ___  ___ ___ 
D (20434) RAK3172: Response: | |_/ / /_\ \| |/ /  | |  | |_ _ __ ___| | ___  ___ ___ 
D (20494) RAK3172:      Pattern detected at position 58. Use buffered size: 59
D (20494) RAK3172:      Response: |    /|  _  ||    \  | |/\| | | '__/ _ \ |/ _ \/ __/ __|
D (20494) RAK3172: Response: |    /|  _  ||    \  | |/\| | | '__/ _ \ |/ _ \/ __/ __|
D (20554) RAK3172:      Pattern detected at position 58. Use buffered size: 59
D (20554) RAK3172:      Response: | |\ \| | | || |\  \ \  /\  / | | |  __/ |  __/\__ \__ \
D (20555) RAK3172: Response: | |\ \| | | || |\  \ \  /\  / | | |  __/ |  __/\__ \__ \
D (20615) RAK3172:      Pattern detected at position 58. Use buffered size: 59
D (20615) RAK3172:      Response: \_| \_\_| |_/\_| \_/  \/  \/|_|_|  \___|_|\___||___/___/
D (20615) RAK3172: Response: \_| \_\_| |_/\_| \_/  \/  \/|_|_|  \___|_|\___||___/___/
D (20675) RAK3172:      Pattern detected at position 58. Use buffered size: 59
D (20675) RAK3172:      Response: ========================================================
D (20676) RAK3172: Response: ========================================================
D (20715) RAK3172:      Pattern detected at position 38. Use buffered size: 39
D (20715) RAK3172:      Response: RAK3172-H Version:v1.0.4 Feb 18 2022
D (20715) RAK3172: Response: RAK3172-H Version:v1.0.4 Feb 18 2022
D (20746) RAK3172:      Pattern detected at position 30. Use buffered size: 31
D (20746) RAK3172:      Response: Current Work Mode: LoRa P2P.
D (20746) RAK3172: Response: Current Work Mode: LoRa P2P.
I (20746) RAK3172:      Successful!
I (21247) RAK3172: Transmit command: AT
D (21253) RAK3172:      Pattern detected at position 2. Use buffered size: 3
D (21253) RAK3172:      Response: 
D (21263) RAK3172:      Pattern detected at position 10. Use buffered size: 11
D (21264) RAK3172:      Response: AT_ERROR
I (21264) RAK3172:      Status: AT_ERROR
D (21264) RAK3172:     Error: 0xA004
E (21264) RAK3172: Error check failed in (RAK3172_Init) at line (616): 0xA004
E (21264) comm: Cannot initialize RAK3172! Error: 0xA004
Kampi commented 1 month ago

Hi,

the library is able to run with RUI3 and non RUI firmwares. To use firmware 1.0.4 you have to disable RUI by setting RAK3172_USE_RUI3 to n. But I haven´t tested pre RUI releases with the newest changes because I have to downgrade the firmware in my modules every time so there might be an isuse with it. Is it possible to upgrade the module firmware to the latest version? Otherwise I have to test it with 1.0.4 and check for the issue.

txf- commented 1 month ago

As a small update to this topic. I have managed to resolve the issues at init by doing a hardware reset. I'm using UART0 so it may be that the module gets confused by boot messages etc.

I have managed to Join a server and send confirmed messages. However I cannot receive messages.

I (852884) RAK3172: Transmit command: AT+RETY=1
D (852897) RAK3172_UART:      Pattern detected at position 2. Use buffered size: 3
D (852898) RAK3172_UART:      Response: 
D (852902) RAK3172_UART:      Pattern detected at position 4. Use buffered size: 5
D (852902) RAK3172_UART:      Response: OK
I (852902) RAK3172:      Status: OK
D (852902) RAK3172:     Error: 0xA000
I (852902) RAK3172: Transmit command: AT+CFM=1
D (852915) RAK3172_UART:      Pattern detected at position 2. Use buffered size: 3
D (852915) RAK3172_UART:      Response: 
D (852919) RAK3172_UART:      Pattern detected at position 4. Use buffered size: 5
D (852919) RAK3172_UART:      Response: OK
I (852920) RAK3172:      Status: OK
D (852920) RAK3172:     Error: 0xA000
I (852920) RAK3172: Transmit command: AT+SEND=1:7b7d
D (852944) RAK3172_UART:      Pattern detected at position 2. Use buffered size: 3
D (852944) RAK3172_UART:      Response: 
D (852948) RAK3172_UART:      Pattern detected at position 4. Use buffered size: 5
D (852948) RAK3172_UART:      Response: OK
I (852949) RAK3172:      Status: OK
D (852949) RAK3172:     Error: 0xA000
D (854059) RAK3172_UART:      Pattern detected at position 24. Use buffered size: 25
D (854059) RAK3172_UART:      Response: +EVT:SEND CONFIRMED OK
I (854059) RAK3172_UART: Event: +EVT:SEND CONFIRMED OK
E (858069) comm: Cannot receive message! Error: 0xA005

Does this surface the ack messages in RAK3172_LoRaWAN_Receive, or are those transparently ignored?

Kampi commented 1 month ago

As a small update to this topic. I have managed to resolve the issues at init by doing a hardware reset. I'm using UART0 so it may be that the module gets confused by boot messages etc.

Yes. The module gets confused by boot and log messages. So please try to use another UART. Switching the UART for the log messages doesn´t help because the bootloader is fixed to UART0.

I have managed to Join a server and send confirmed messages. However I cannot receive messages.

I (852884) RAK3172: Transmit command: AT+RETY=1
D (852897) RAK3172_UART:      Pattern detected at position 2. Use buffered size: 3
D (852898) RAK3172_UART:      Response: 
D (852902) RAK3172_UART:      Pattern detected at position 4. Use buffered size: 5
D (852902) RAK3172_UART:      Response: OK
I (852902) RAK3172:      Status: OK
D (852902) RAK3172:     Error: 0xA000
I (852902) RAK3172: Transmit command: AT+CFM=1
D (852915) RAK3172_UART:      Pattern detected at position 2. Use buffered size: 3
D (852915) RAK3172_UART:      Response: 
D (852919) RAK3172_UART:      Pattern detected at position 4. Use buffered size: 5
D (852919) RAK3172_UART:      Response: OK
I (852920) RAK3172:      Status: OK
D (852920) RAK3172:     Error: 0xA000
I (852920) RAK3172: Transmit command: AT+SEND=1:7b7d
D (852944) RAK3172_UART:      Pattern detected at position 2. Use buffered size: 3
D (852944) RAK3172_UART:      Response: 
D (852948) RAK3172_UART:      Pattern detected at position 4. Use buffered size: 5
D (852948) RAK3172_UART:      Response: OK
I (852949) RAK3172:      Status: OK
D (852949) RAK3172:     Error: 0xA000
D (854059) RAK3172_UART:      Pattern detected at position 24. Use buffered size: 25
D (854059) RAK3172_UART:      Response: +EVT:SEND CONFIRMED OK
I (854059) RAK3172_UART: Event: +EVT:SEND CONFIRMED OK
E (858069) comm: Cannot receive message! Error: 0xA005

Does this surface the ack messages in RAK3172_LoRaWAN_Receive, or are those transparently ignored?

What is your LoRaWAN backend and have you scheduled a confirmed downlink message? You can do it in this way in Chirpstack

image

If not this can be the issue. The return code says that the module is waiting for a downlink message after a confirmed uplink. If you don´t expect a downlink message you can ignore the return code and everything is fine. If you expect a message and this error occurs you don´t receive the confirmed downlink because of transmission issues.

txf- commented 1 month ago

I am indeed using chirpstack.

I have since tested this. I do get data back if I have messages queued. However upon receiving them I get a segfault at

RAK3172_LOGD(TAG, "Next line: %s", Response->c_str()); in rak3172_uart.cpp.

Howver if I comment out this section:


                                    #ifndef CONFIG_RAK3172_USE_RUI3
                                        // The payload is stored in the next line.
                                        char Data;
                                        int Bytes;
                                        Response->clear();
                                        // do
                                        // {
                                        //     Bytes = uart_read_bytes(Device->UART.Interface, &Data, 1, 10);
                                        //     RAK3172_LOGD(TAG, "payload bytes: %d", Bytes);
                                        //     if((Bytes != 0) && (Data != '\r') && (Data != '\n'))
                                        //     {
                                        //         *Response += Data;
                                        //     }
                                        // } while(Bytes != 0);
                                        // *Response += '\0';

                                        // RAK3172_LOGD(TAG, "Next line: %s", Response->c_str());

                                        // // Remove all "+EVT" strings.
                                        // Response->erase(0, std::string("+EVT:").length());
                                        // Response->erase(Response->find("+EVT"), std::string("+EVT").length());
                                    #endif

                                    // // Remove the "UNICAST" or the "MULCAST" from the message.
                                    // Response->erase(0, Response->find(":") + 1);

                                    // // Get the communication port.
                                    // Dummy = Response->substr(0, Response->find(":"));
                                    // Response->erase(Response->find(Dummy), std::string(Dummy + ":").length());
                                    // Received->Port = std::stoi(Dummy);

                                    // Get the payload.
                                    Received->Payload = *Response;

                                    RAK3172_LOGD(TAG, "RSSI: %i", Received->RSSI);
                                    RAK3172_LOGD(TAG, "SNR: %i", Received->SNR);
                                    RAK3172_LOGD(TAG, "Port: %u", Received->Port);
                                    RAK3172_LOGD(TAG, "Channel: %u", Received->Group);
                                    RAK3172_LOGD(TAG, "Payload: %s", Received->Payload.c_str());
                                    RAK3172_LOGD(TAG, "Multicast: %u", Received->isMulticast);

                                    xQueueSend(Device->Internal.ReceiveQueue, &Received, 0);
                                }

I get the +EVT:UNICAST and +EVT with the payload.

I need to figure out what is causing the the crash, for some reason Bytes = uart_read_bytes(Device->UART.Interface, &Data, 1, 10); always only returns one byte.

Kampi commented 1 month ago

That´s odd. Are you still using firmware 1.0.4?

Unfortunately, I can not test it because I only have 434 MHz versions of the RAK3172 which can be downgraded to 1.0.4, 868 MHz versions of the RAK3172-SiP which can not be downgraded to 1.0.4, and a 868 MHz gateway.

txf- commented 1 month ago

That´s odd. Are you still using firmware 1.0.4?

Yes, but I figured it out.

I had to increase the timeout on Uart_read_bytes(). Doing something like : Bytes = uart_read_bytes(Device->UART.Interface, &Data, 1,pdMS_TO_TICKS(200)); Fixes it. This must be primarily because the default baud rate on 1.04 is 9600, get data on uart one needs to wait more time.

Kampi commented 1 month ago

Great! I will add it as a change to 4.2. Thanks for your support!

txf- commented 1 month ago

No problem. Probably some better metrics need to be found, this issue likely could affect RUI too if a slower non-defaut baud is selected?

Kampi commented 1 month ago

Yes, you are right. Maybe I use a non const value or I use the same value for everything. If my guess is correct then a 200 ms timeout shouldn't affect higher baud rates.