ESP32 OVER THE WORLD
Turn on/off ESP32’s led in Sydney, for example, from ESP32’s button in Paris
- Connect with Wifi to GL-AR300M-xx with password « goodlife »
- Use your browser : http://192.168.8.1 (Be careful, the link isn’t httpS)
- Choose your language and change the password
- Connect with SSH : ssh root@192.168.8.1
--- Begin code -----------------------------------------------------------------------------------------------
- On your computer, format the USB key in FAT format.
- On the AR300, format :
--- End code -----------------------------------------------------------------------------------------------
--- Begin code -----------------------------------------------------------------------------------------------
--- End code -----------------------------------------------------------------------------------------------
- Switch to extroot :
--- End code -----------------------------------------------------------------------------------------------
--- Begin code -----------------------------------------------------------------------------------------------
- Check after reboot :
--- End code -----------------------------------------------------------------------------------------------
=> /dev/sda 14.3G 496.0K 13.6G 0% /overlay
- Change the Time Zone To avoid a conflict, later with Tailscale, change the ARM300 Sydney « RouteurIP Address » to « 192.168.10.1 »
- Wait and reconnect to « 192.169.10.1 »
- Change the SSID name : AR300M-Sydney (AR300M-Paris for the second’s) and the password (old was « goodlife »). You lost the connection.
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! => The command : ssh-keygen -R 192.168.10.1
- Download the Tailscale version :
--- End code -----------------------------------------------------------------------------------------------
--- Begin code -----------------------------------------------------------------------------------------------
=> ln: /usr/sbin/tailscaled: File exists
=> 1.102.2
--- Begin code -----------------------------------------------------------------------------------------------
--- End code -----------------------------------------------------------------------------------------------
- Copy the link to your browser and connect to your Taiscale
=> Your device GL-AR300M is logged
--- Begin code -----------------------------------------------------------------------------------------------
--- Begin code -----------------------------------------------------------------------------------------------
--- Begin code -----------------------------------------------------------------------------------------------
--- Begin code -----------------------------------------------------------------------------------------------
--- End code -----------------------------------------------------------------------------------------------
--- Begin code -----------------------------------------------------------------------------------------------
--- End code -----------------------------------------------------------------------------------------------
=> Section nat6 option 'reload' is not supported by fw4
=> Section gls2s option 'reload' is not supported by fw4
=> Section gls2s specifies unreachable path '/var/etc/gls2s.include', ignoring section
=> Section glblock option 'reload' is not supported by fw4
=> Section vpn_server_policy option 'reload' is not supported by fw4
=> Automatically including '/usr/share/nftables.d/chain-pre/mangle_output/01-process_mark.nft'
=> DROP all opt -- in * out * 0.0.0.0/0 -> 0.0.0.0/0 match-set GL_MAC_BLOCK src
--- Begin code -----------------------------------------------------------------------------------------------
// ESP32 Paris - interrupteur // Envoie un chiffre au hasard a l'ESP32 de Sydney : // - impair -> commande ON // - pair -> commande OFF // La LED de confirmation clignote pendant l'attente de la reponse. // Reponse recue : LED fixe (allumee = ON confirme, eteinte = OFF confirme). // Pas de reponse (timeout) : clignotement tres rapide.
#include <WiFi.h> #include <HTTPClient.h>
const char* ssid = "AR300M-Paris"; const char* password = "MOT_DE_PASSE_WIFI_PARIS";
const char* sydneyIP = "192.168.9.50"; // IP fixe de l'ESP32 Sydney const int switchPin = 4; // interrupteur (pull-up interne) const int confirmLed = 2; // LED de confirmation (LED integree)
volatile bool waitingForResponse = false; int lastSwitchState = HIGH;
// Tache de fond dediee au clignotement, pour que la LED bouge // pendant que loop() est bloque sur http.GET() void blinkTask(void *parameter) { for (;;) { if (waitingForResponse) { digitalWrite(confirmLed, HIGH); vTaskDelay(120 / portTICK_PERIOD_MS); digitalWrite(confirmLed, LOW); vTaskDelay(120 / portTICK_PERIOD_MS); } else { vTaskDelay(50 / portTICK_PERIOD_MS); } } }
void setup() { Serial.begin(115200); pinMode(switchPin, INPUT_PULLUP); pinMode(confirmLed, OUTPUT); digitalWrite(confirmLed, LOW);
WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.print("Connexion Wi-Fi Paris"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.print("IP locale Paris : "); Serial.println(WiFi.localIP());
randomSeed(esp_random());
xTaskCreatePinnedToCore(blinkTask, "blinkTask", 2048, NULL, 1, NULL, 0); }
void loop() { int currentState = digitalRead(switchPin);
if (lastSwitchState == HIGH && currentState == LOW) { // front descendant : interrupteur actionne sendCommandToSydney(); } lastSwitchState = currentState; delay(30); // anti-rebond simple }
void sendCommandToSydney() { if (WiFi.status() != WL_CONNECTED) { Serial.println("Wi-Fi non connecte, abandon."); fastFailBlink(); return; }
// Chiffre au hasard : impair = ON, pair = OFF int sentNumber = random(0, 100); bool wantOn = (sentNumber % 2 == 1); Serial.print("Envoi du chiffre "); Serial.print(sentNumber); Serial.println(wantOn ? " (impair -> ON)" : " (pair -> OFF)");
HTTPClient http; String url = String("http://") + sydneyIP + "/cmd?n=" + String(sentNumber); http.begin(url); http.setTimeout(5000); // marge pour la latence Paris-Sydney
waitingForResponse = true; // la tache de fond fait clignoter la LED int httpCode = http.GET(); waitingForResponse = false;
if (httpCode == 200) { String response = http.getString(); int returnedNumber = response.toInt(); bool confirmedOn = (returnedNumber % 2 == 1);
Serial.print("Reponse recue : "); Serial.print(returnedNumber); Serial.println(confirmedOn ? " (impair -> ON confirme)" : " (pair -> OFF confirme)");
digitalWrite(confirmLed, confirmedOn ? HIGH : LOW); } else { Serial.print("Pas de reponse valide, code HTTP : "); Serial.println(httpCode); fastFailBlink(); }
http.end(); }
void fastFailBlink() { for (int i = 0; i < 12; i++) { digitalWrite(confirmLed, HIGH); delay(50); digitalWrite(confirmLed, LOW); delay(50); } }
--- Begin code -----------------------------------------------------------------------------------------------
// ESP32 Sydney - LED // Recoit un chiffre au hasard depuis l'ESP32 de Paris via /cmd?n=... // - impair -> allume la LED // - pair -> eteint la LED // Renvoie un autre chiffre au hasard, dont la parite confirme l'etat // reellement applique (impair = confirmee ON, pair = confirmee OFF). // Exemple donne : recoit 1 (impair -> ON), renvoie 9 (impair -> confirme ON).
#include <WiFi.h> #include <WebServer.h>
const char* ssid = "AR300M-Sydney"; const char* password = "MOT_DE_PASSE_WIFI_SYDNEY";
WebServer server(80); const int ledPin = 2; // LED integree sur la plupart des cartes ESP32 bool ledState = false;
void handleCmd() { if (!server.hasArg("n")) { server.send(400, "text/plain", "Parametre n manquant"); return; }
int receivedNumber = server.arg("n").toInt(); bool wantOn = (receivedNumber % 2 == 1);
ledState = wantOn; digitalWrite(ledPin, ledState ? HIGH : LOW);
Serial.print("Recu "); Serial.print(receivedNumber); Serial.println(wantOn ? " (impair -> LED ON)" : " (pair -> LED OFF)");
// Chiffre de retour au hasard, dont on force la parite pour qu'elle // corresponde a l'etat reellement applique int returnNumber = random(0, 100); if (ledState && returnNumber % 2 == 0) returnNumber++; // forcer impair si ON if (!ledState && returnNumber % 2 == 1) returnNumber++; // forcer pair si OFF
Serial.print("Renvoi "); Serial.println(returnNumber);
server.send(200, "text/plain", String(returnNumber)); }
void handleRoot() { String html = "<h1>ESP32 Sydney</h1>"; html += "<p>IP locale : " + WiFi.localIP().toString() + "</p>"; html += "<p>Etat LED : " + String(ledState ? "ON" : "OFF") + "</p>"; server.send(200, "text/html", html); }
void setup() { Serial.begin(115200); pinMode(ledPin, OUTPUT);
WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.print("Connexion Wi-Fi Sydney"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.print("IP locale Sydney : "); Serial.println(WiFi.localIP());
randomSeed(esp_random());
server.on("/", handleRoot); server.on("/cmd", handleCmd); server.begin(); }
void loop() { server.handleClient(); }
Coming soon
Jennifer
Want to build a project?
Bring your design to life with the Elektor PCB Service, powered by Eurocircuits. Upload the project files and order professionally manufactured PCBs or assembled boards through a proven European production platform.
Supporting KiCad, Eagle, Gerber, and ODB++ formats, the service is suitable for everything from prototypes and validation builds to series production and volume manufacturing.
Made in Europe. Fast. Reliable. Professional.

Discussion (0 comments)