Created
March 22, 2021 21:46
-
-
Save Hermann-SW/e945a78e8a460a5335058bc679f48b03 to your computer and use it in GitHub Desktop.
ESP01 sketch taking HTTPS GET URLs from Pico over serial, returning response to Pico
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <ESP8266WiFi.h> | |
#include <ESP8266WiFiMulti.h> | |
#include <ESP8266HTTPClient.h> | |
#include <WiFiClientSecureBearSSL.h> | |
ESP8266WiFiMulti WiFiMulti; | |
void setup() { | |
Serial.begin(115200); | |
WiFi.mode(WIFI_STA); | |
WiFiMulti.addAP("ssid", "password"); | |
} | |
void loop() { | |
if ((WiFiMulti.run() == WL_CONNECTED)) { | |
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure); | |
client->setInsecure(); // client->setFingerprint(fingerprint); | |
HTTPClient https; | |
String url = Serial.readStringUntil('\n'); | |
if (url.length()>1) | |
{ | |
if (https.begin(*client, url)) { | |
int httpCode = https.GET(); | |
if ((httpCode > 0) && | |
(httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY)) { | |
Serial.println(https.getString()); | |
} | |
else { | |
Serial.println(); | |
} | |
https.end(); | |
} else { | |
Serial.println(); | |
} | |
} | |
} | |
} |
Now works with Pico C-SDK as well:
https://github.com/Hermann-SW/C-SDK_HTTPS_GET_through_ESP01#c-sdk-https-get-through-esp01-wifi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just connect Pico 3V3/GND/GP0/GP1/3V3 to ESP01 3V3/GND/RX/TX/EN.
Allows Pico HTTPS GET internet access through the ESP01:
https://www.raspberrypi.org/forums/viewtopic.php?f=146&t=307704#p1840946