Open a-h opened 1 year ago
arduino-pico
has a good HTTP API that's borrowed from the ESP8266, but all the Arduino libraries are LGPL licensed.
// Error checking is left as an exercise for the reader...
HTTPClient https;
https.setInsecure(); // Use certs, but do not check their authenticity
if (https.begin("https://my.secure.server/url")) {
if (https.GET() > 0) {
String data = https.getString();
}
https.end();
}
I too would like some examples specificall for the Pico in C with HTTP and HTTPS GET/POST requestes for this as I have attempted to use the httpc_get_file function from #include "lwip/apps/http_client.h", but this seems to fall over after a number of repeated requests with memory issues.
I wrote a minimum working HTTPS client example in C which might be useful as a starting point for an example.
It's currently in it's own repo, but would be happy to migrate it here if desired. Might require some refactoring though.
Looks like @peterharperuk is also working on adding some HTTP and HTTPS examples though which might be ready to merge soon.
I want to post data from sensors over HTTPS in JSON format, and ideally, also using MQTT.
This seems very difficult with the C API, but is trivial with the
urequests
API in MicroPython.On the ESP32, the included
WiFiClientSecure
type makes the same task simple too.So far, I've spent hours trying to get something up and running on the Pico W without success.
Reading through https://www.i-programmer.info/programming/hardware/15838-the-picow-in-c-simple-web-client.html got me up and running with a HTTP request, but that's not very useful, since a lot of cloud infrastructure doesn't support unencrypted transports. Regardless, I think it would be a good addition to the examples.
I've looked at https://github.com/cniles/picow-iot but couldn't get it to build. It seems outdated, since the Pico SDK seems to have some support for mbedTLS now. The author didn't get any help on his questions about performance at https://forums.raspberrypi.com/viewtopic.php?t=339620 so I'm not sure if it works anyway.
This unmerged PR seems like it's starting to get to the right place, but it's still very much at the TCP side, rather than higher level. https://github.com/raspberrypi/pico-examples/pull/305 - it doesn't make use of the httpc_get_file_dns function, for example.
Reading through this blog post makes it look like it's possible to do HTTPS, but I don't know how to connect the pieces - https://www.unshiu.com/posts/pico-http-client-part-iii-mbedtls/ - Finally, it seems that the author gave up on the Pico SDK, and switched to try out FreeRTOS (https://www.unshiu.com/posts/pico-with-freertos/)
I think there's two things that would help the developer experience here: