Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created March 22, 2021 21:46
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Hermann-SW/e945a78e8a460a5335058bc679f48b03 to your computer and use it in GitHub Desktop.
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
#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();
}
}
}
}
@Hermann-SW
Copy link
Author

Hermann-SW commented Mar 23, 2021

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

@Hermann-SW
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment