PsychicHttp icon indicating copy to clipboard operation
PsychicHttp copied to clipboard

Plain support for C++ for esp-idf? (without Arduino framework)

Open gnalbandian opened this issue 9 months ago • 17 comments

Hi! Well done for the porting of the library! It looks really nice. Are the any plan to make a plain C++ version for esp-idf (without Arduino framework)? After searching around, and having used ESPAsyncWebServer in the past, I haven't found a good/complete http(s) library that compares to. Any recommendations?

gnalbandian avatar Mar 28 '25 11:03 gnalbandian

Are the any plan to make a plain C++ version for esp-idf?

PsychicHttp is backed by the esp-idf http_server, which is already in esp-idf

After searching around, and having used ESPAsyncWebServer in the past, I haven't found a good/complete http(s) library that compares to.

FYI, ESPAsyncWebServer has now moved to an org (https://github.com/ESP32Async) and is deployed in esp-idf component registry.

mathieucarbou avatar Mar 28 '25 11:03 mathieucarbou

Thanks @mathieucarbou. I have already peek inside both libraries and both make use of Arduino framework beneath (#include "Arduino.h").

And make use of Arduino classes such as:

  • String
  • IPAddress
  • File

gnalbandian avatar Mar 28 '25 12:03 gnalbandian

I have started porting the library to remove all Arduino framework dependencies.

Its a WIP. You can collaborate here: https://github.com/gnalbandian/PsychicHttp

gnalbandian avatar Apr 08 '25 23:04 gnalbandian

I have started porting the library to remove all Arduino framework dependencies.

Its a WIP. You can collaborate here: https://github.com/gnalbandian/PsychicHttp

Do you port the V2 branch?

zekageri avatar Apr 09 '25 06:04 zekageri

No, just v1. Can you please tell me some improvements that v2 offers over v1? Maybe I can consider doing the port. The issue is that as v2 is actively being developed I will for sure fall behind every update they make. Firstly, are people interested in a library that just works in esp-idf without Arduino framework? Are there any collaborators willing to keep the code updated?

gnalbandian avatar Apr 09 '25 11:04 gnalbandian

V2 is not so frequently updated these days. V2 has middleware support and a lot of other bug fixes V1 had. I also wanted to continue to develop the v2 but iam considering to switch to ESPAsync. I dont need https and @hoeken is pretty much vanished.

zekageri avatar Apr 09 '25 11:04 zekageri

@zekageri do you think that ESP32Async is more stable that the PsychicHttp v1?

I am asking you because I used the ESPAsyncWebServer some time ago and it was almost unsable (crashes frequently) at that time.

Thanks.

johnnytolengo avatar Apr 09 '25 12:04 johnnytolengo

@johnnytolengo : yes it is. I am a contributor of this project but also Espasyncwebserver. We resurrected it under an org with 3 people. It is really stable and has a few features psychic does not have.

We had plans to make it not depend on Arduino: this is actually possible, except for the String class that is heavily used and a few others. If you want to work on that you are more than welcomed to help!

mathieucarbou avatar Apr 09 '25 12:04 mathieucarbou

@mathieucarbou that sounds very promising, I'll try it.

Will be SSL possible with the ESP32Async lib?

thanks

johnnytolengo avatar Apr 09 '25 13:04 johnnytolengo

Will be SSL possible with the ESP32Async lib?

No... No SSL support. Too many downsides with SSL as experienced by those who activated it. But that's still something we would like to add one day.

mathieucarbou avatar Apr 09 '25 14:04 mathieucarbou

@mathieucarbou do you think a ESPAyncwebserver version using iwip and esp-idf http-server functions underneath such as:

  • httpd_register_uri_handler
  • httpd_req_get_hdr_value_len
  • httpd_req_get_hdr_value_str
  • etc.

The idea behind is trying to avoid dependencies over Arduino Framework.

@johnnytolengo : yes it is. I am a contributor of this project but also Espasyncwebserver. We resurrected it under an org with 3 people. It is really stable and has a few features psychic does not have.

We had plans to make it not depend on Arduino: this is actually possible, except for the String class that is heavily used and a few others. If you want to work on that you are more than welcomed to help!

What do you think about replacing Arduino String class with std::string? I've done it in the port of PsychicHttp v1 and it seems to be working fine. I am not depending on sstream, stringstream, istream, ostream, iomanip, etc. Just

gnalbandian avatar Apr 09 '25 14:04 gnalbandian

ESPAyncwebserver version using iwip and esp-idf http-server functions underneath

I do not think so. We discussed that in the team and the way esp-idf http server works, it is not lightweight at all and consumes a lot of resources (heap, stack, etc). Also take more flash. We much more would like to improve AsyncTCP and its queuing system to have a queue per client to improve concurrency. AsyncTCP is really asynchronous. The esp-idf layer has a message queue for async, this is a bit different. There are also things that cannot be done yet, like getting all request headers. Only the ones you know about can be retrieved.

What do you think about replacing Arduino String class with std::string?

not replacing but provide a way to switch, like I did in ESP-DASH v5, where we can add a compile flag saying we want to use std::string.

That's in our plans yes, for a future version.

mathieucarbou avatar Apr 09 '25 15:04 mathieucarbou

@zekageri do you think that ESP32Async is more stable that the PsychicHttp v1?

You got your answer already but my take is that I think Psychic has a really sneaky memory leak somewhere. I also had crashes due to sse client cleanup. Iam not sure if it was actually Psychic but I scanned my code multiple times and found nothing which would realte to the crash.

Also i did not tried Async web in a large scale app yet.

zekageri avatar Apr 09 '25 17:04 zekageri

@mathieucarbou just to continue with the conversation regarding a proper and maintained async web server without Arduino Framework, I've already ported AsyncTCP with some macros and minorcode changes to allow it to compile when no Arduino framework is found. Can you please take a look and see is this is the right approach so as to go on and try to port ESPAsycwebserver? Would you be willing to merge such changes? Let me know in order to open a proper issue with this topics to discuss in the right repository. Thanks

gnalbandian avatar Apr 10 '25 16:04 gnalbandian

@mathieucarbou just to continue with the conversation regarding a proper and maintained async web server without Arduino Framework, I've already ported AsyncTCP with some macros and minorcode changes to allow it to compile when no Arduino framework is found. Can you please take a look and see is this is the right approach so as to go on and try to port ESPAsycwebserver? Would you be willing to merge such changes? Let me know in order to open a proper issue with this topics to discuss in the right repository. Thanks

You should definitely send a PR because I am pretty sure this PR will get a lots of interests. I would even go further and have the normal code use the esp IDF struct for up and just have methods that forwards to them using Arduino IP address. Also, I think the macro is not necessary because I think Arduino could be detected another way, like with __has_include maybe ? Anyway... This is a good pr that will bring interests and that can be further improved I think!

Thanks a lot!

Note: let's continue this conversation in an Asynctcp PR...

mathieucarbou avatar Apr 10 '25 17:04 mathieucarbou

@gnalbandian I like this too, what it the status of your port? I have some project defend on Arduino using ESP IDF and now want to remove Arduino, because some time it cause conflict with IDF. I also using ESPAsyncWebServer in the past but it is not very stable and does not support https.

dzungpv avatar May 25 '25 10:05 dzungpv

I continue it here: https://github.com/dzungpv/PsychicHttp/tree/dev now only PsychicStreamResponse and TemplatePrinter is missing

dzungpv avatar Jun 21 '25 14:06 dzungpv

Coming back to this after a long break and cleaning up issues. Please re-open if its still a problem.

hoeken avatar Nov 28 '25 03:11 hoeken