Question:
I’m trying to connect my ESP32C3 XIAO to a python http server. On the microntroller side, I’m using the WiFi library from Arduino, and I’m just using the python http server template on replit. I keep getting a 308 permanent redirect response. (I’m expecting to get the content in templates/index.html).
HTTP/1.1 308 Permanent Redirect
Content-Type: text/html; charset=utf-8
Location: https://server.joshuabas.repl.co/
Replit-Cluster: global
Date: Sun, 26 Feb 2023 03:05:13 GMT
Content-Length: 69
Via: 1.1 google
<a href="https://server.joshuabas.repl.co/">Permanent Redirect</a>.
I then tried using the WIFiClientSecure library to use https, but then it just wouldn’t receive anything at all.
Is connecting a microcontroller to an http server possible on replit? If so, why exactly am I getting the redirect response?
Here’s the link to the python server replit:
Repl link: https://replit.com/@joshuabas/server#templates/index.html
Here’s my Arduino code that is running on the ESP3C23 XIAO (you’d need to follow the Arduino setup instruction from Getting Started with Seeed Studio XIAO ESP32C3 - Seeed Wiki if you want to run this):
#include <WiFi.h>
WiFiClient client;
const char* ssid = "ssid";
const char* password = "pass";
const char* server = "server.joshuabas.repl.co";
const uint8_t port = 80;
void connectNetwork(const char* ssid, const char* password) {
WiFi.begin(ssid, password);
// wait until connected
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void connectServer(const char* server, uint8_t port) {
while (!client.connect(server, port)) {
delay(500);
}
}
void setup() {
Serial.begin(115200);
delay(10);
connectNetwork(ssid, password);
connectServer(server, port);
client.println("GET / HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: disconnect");
client.println();
}
void loop() {
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println("Disconnecting from server.");
client.stop();
// do nothing forevermore:
while (true);
}
}
I appreciate any help!