ESP32 - IDF - HTTP request

kurtwerbrouck
Posts: 10
Joined: Tue Feb 16, 2021 2:37 pm

ESP32 - IDF - HTTP request

Postby kurtwerbrouck » Mon Aug 02, 2021 9:15 am

Hello

I used the example in the doc for creating a HTTP request for openweathermap.
When i used the the http request in the setup() and in the loop(), all seems to be running OK
When i used only the http request in the loop() (delete the http request part in the setup), the esp32 keeps on rebooting.
any ideas what is wrong?
Attachments
ESP-32-IDF-HTTP-REQUEST-2.txt
(4.37 KiB) Downloaded 245 times

User avatar
mbratch
Posts: 298
Joined: Fri Jun 11, 2021 1:51 pm

Re: ESP32 - IDF - HTTP request

Postby mbratch » Mon Aug 02, 2021 1:25 pm

Your code has a very peculiar structure. You've included "Arduino.h" and are using `setup` and `loop`, which tells me you're intending to use the Arduino framework. In fact, you're checking wifi status by calling the `Wifi` Arduino library. But then you're using ESP-IDF to do your Http server work. I assume you're looking at an ESP-IDF example for http client, not an Arduino library example. Why not use the Arduino library for an http client?

kurtwerbrouck
Posts: 10
Joined: Tue Feb 16, 2021 2:37 pm

Re: ESP32 - IDF - HTTP request

Postby kurtwerbrouck » Mon Aug 02, 2021 1:36 pm

hello mbratch
I assume you're looking at an ESP-IDF example for http client
, Yes indeed

i used the wifi arduino in other programs, but i am converting them all to the idf API, with the help of the APi reference.
now i am trying to use the idf HTTP, I will try this evening with removing the wifi.h.

the mqtt and I2C api examples did work very well, and easier to understand 8-) .

I am trying to convert my arduino sketch that uses a ds1307 display - bme280 sensor - http request openweather - http request sma solar converter and upload all data via mqtt to raspoberry node-red.


Kurt

User avatar
mbratch
Posts: 298
Joined: Fri Jun 11, 2021 1:51 pm

Re: ESP32 - IDF - HTTP request

Postby mbratch » Mon Aug 02, 2021 3:27 pm

If you want to use ESP-IDF framework, then you should start with the correct program structure. ESP-IDF doesn't use `setup` and `loop`. It uses `app_main`. Currently, your code is an odd mix of both worlds. Perhaps the best thing to do is start with the complete ESP-IDF example code, get that working, then put in the changes you need for your specific application. The `app_main` is, in the ESP-IDF world, a FreeRTOS task itself. It would do all the initialization you need (as `setup` would have done), then could either have its own loop, or kick off a separate FreeRTOS task to perform base-level functions while event handlers do what they do. (Note that although `app_main` is a FreeRTOS task, in the latest ESP-IDF it is allowed to just exit, unlike a typical FreeRTOS task.)

User avatar
fasani
Posts: 195
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: ESP32 - IDF - HTTP request

Postby fasani » Sun Aug 15, 2021 5:28 am

I also find odd to mix both arduino-ESP32 and IDF but I know some projects do. Here there is a demo of parsing open weather that compiles in IDF and uses arduino “as a component”
https://github.com/vroland/epdiy/tree/m ... es/weather
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

Who is online

Users browsing this forum: Baidu [Spider] and 122 guests