logo elektroda
logo elektroda
X
logo elektroda

ESP32 FreeRTOS: Connecting edp_http_client to UART with uart_echo Example

dondu 2400 32
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17981210
    dondu
    VIP Meritorious for electroda.pl
    Hi.

    I'm dabbling in ESP32 and starting to adopt FreeRTOS. My goal is to connect the edp_http_client examples to the UART. I am attaching the whole project below.

    For now, I've created a simple program based on uart_echo to see how to call several different processes (cutting out everything that involves uart). In other words, I used the uart_echo example template to test FreeRTOS.

    Unfortunately I had already fallen down on implementing the first process:

    Code: C / C++
    Log in, to see the code
    .

    The above program resets itself after a single correct execution as can be seen in this log:

    Code: HTML, XML
    Log in, to see the code
    .

    In the third from the end line you can see that my_task executed correctly once, but then there was a reboot due to:

    Code: HTML, XML
    Log in, to see the code
    .

    What am I doing wrong?
  • ADVERTISEMENT
  • Helpful post
    #2 17981248
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • Helpful post
    #3 17981260
    Anonymous
    Level 1  
  • #4 17981686
    dondu
    VIP Meritorious for electroda.pl
    After your comments, I added a delete shuffle and added a second task. Both increase the global variable while I moved the loop to the app_main() function:

    Code: C / C++
    Log in, to see the code
    .

    The result is:

    Quote:
    I (10441) RTOS_LOG: b=300
    I (10441) RTOS_LOG: c=300
    I (10541) RTOS_LOG: b=302
    I (10541) RTOS_LOG: c=302
    I (10641) RTOS_LOG: b=304
    I (10641) RTOS_LOG: c=304
    I (10741) RTOS_LOG: b=306
    I (10741) RTOS_LOG: c=306
    I (10841) RTOS_LOG: b=308
    I (10841) RTOS_LOG: c=308
    I (10941) RTOS_LOG: b=310
    I (10941) RTOS_LOG: c=310
    .
    Why is it that although the variable length is global the results are every 2?
  • #5 17981783
    Anonymous
    Level 1  
  • #6 17981879
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #7 17981917
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #8 17982242
    dondu
    VIP Meritorious for electroda.pl
    Is everything OK now?

    Code: C / C++
    Log in, to see the code
    .

    The result is correct because my_task runs every second and my_task_2 runs every 5 seconds:

    Code: HTML, XML
    Log in, to see the code
    .
  • #9 17982270
    Anonymous
    Level 1  
  • #10 17982304
    dondu
    VIP Meritorious for electroda.pl
    khoam wrote:
    Code should also be therefore correct ;)
    .
    I meant whether it complies with FreeRTOS rules :) .

    khoam wrote:
    Delete(NULL) is currently redundant, unless you exit the while(1) loop with e.g. some break.

    Yes, yes, I read the link you pointed to vTaskDelete().

    If I needed one task to pause the other for a while, what would need to be done?
  • #11 17982328
    Anonymous
    Level 1  
  • Helpful post
    #12 17982329
    Anonymous
    Level 1  
  • #13 17982353
    Anonymous
    Level 1  
  • #14 17982381
    dondu
    VIP Meritorious for electroda.pl
    I reworked app_main() adding a handle when creating my_task_2 and in my_task I added pausing my_task_2 and restarting it.

    Code: C / C++
    Log in, to see the code
    .

    Result correct:

    Code: HTML, XML
    Log in, to see the code
    .

    The next step is to integrate the UARTU and WiFi client.
  • #15 17982383
    Anonymous
    Level 1  
  • #16 17982387
    Anonymous
    Level 1  
  • #17 17982391
    Anonymous
    Level 1  
  • #18 17982542
    Anonymous
    Level 1  
  • #19 17982690
    Anonymous
    Level 1  
  • #20 17982782
    dondu
    VIP Meritorious for electroda.pl
    Thanks to your help, currently:
    - one task receives data from UART1 while showing what it has received on the same UART,
    - a second task sends data to the database via http request using the POST method, showing one by one what it does in the monitor,
    - the third test increments the variable by 1 and shows its value also in the monitor.
    I deactivate the other two tasks for the duration of the http request service.

    Now I need to add timekeeping. With FreeRTOS, can xTaskGetTickCount() be used for this task, or something else?

    PS. I have changed the topic title as it no longer corresponds to its content :) .
  • #21 17982785
    Anonymous
    Level 1  
  • #22 17982790
    Anonymous
    Level 1  
  • #23 17982793
    dondu
    VIP Meritorious for electroda.pl
    Yes, of course I know there are timers in ESP32, but for now I'm concentrating on getting to know FreeRTOS hence the reason I'm asking about it.
    I'm currently using xTaskGetTickCount(), but will familiarise myself with what you've provided.
  • #24 17982808
    Anonymous
    Level 1  
  • #25 17982820
    dondu
    VIP Meritorious for electroda.pl
    For the time being, I want to count down time intervals of about 15 minutes. This is needed because every such time the data is to be sent to the database. I wrote "approximately" because the tolerance can be as short as ±1 minute.
  • #26 17982825
    Anonymous
    Level 1  
  • #27 17982863
    Anonymous
    Level 1  
  • #28 17982869
    Anonymous
    Level 1  
  • #29 17982871
    dondu
    VIP Meritorious for electroda.pl
    Around the clock measurements are taken and averaged, and sent to the base every 15 minutes.
    I will also use Software Timers to get to know them :) .
  • #30 17982912
    Anonymous
    Level 1  

Topic summary

The discussion revolves around integrating the edp_http_client with UART on the ESP32 platform using FreeRTOS. The user initially faced challenges in task management and synchronization while implementing a simple program based on the uart_echo example. Responses highlighted the importance of maintaining tasks in an infinite loop, using vTaskDelete for task cleanup, and employing semaphores for safe access to shared variables. The user successfully created multiple tasks that increment a global variable and log its value, while also managing task suspension and resumption. The conversation also touched on using FreeRTOS software timers for timekeeping and data transmission intervals, with suggestions to utilize queues for task synchronization.
Summary generated by the language model.
ADVERTISEMENT