Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Last active March 12, 2025 10:04
Show Gist options
  • Save tranchausky/6df23d77af1aff8fc39430631d48ad9e to your computer and use it in GitHub Desktop.
Save tranchausky/6df23d77af1aff8fc39430631d48ad9e to your computer and use it in GitHub Desktop.
esp32 test connect server internet
{
"version": 1,
"author": "Tran Chau",
"editor": "wokwi",
"parts": [ { "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} } ],
"connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ],
"dependencies": {}
}
#include <Arduino.h>
#include <WiFi.h> // Use <WiFi.h> for ESP32
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = ""; // Wokwi WiFi has no password
const char* serverUrl = "https://www.google.com"; // Replace with your server URL
void fetchHTML() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverUrl); // Specify the URL
int httpCode = http.GET(); // Send the request
if (httpCode > 0) { // Check for a valid response
Serial.println("Server Response:");
String payload = http.getString();
Serial.println(payload);
} else {
Serial.print("HTTP request failed: ");
Serial.println(httpCode);
}
http.end(); // Close the connection
} else {
Serial.println("WiFi not connected!");
}
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
fetchHTML();
}
void loop() {
// Your code here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment