Hotspot WireClaw, reconnexion WiFi auto, CLAUDE.md reseau
This commit is contained in:
61
src/CLAUDE.md
Normal file
61
src/CLAUDE.md
Normal file
@ -0,0 +1,61 @@
|
||||
# WireClaw ESP32 — Relais MAVLink WiFi↔UART
|
||||
|
||||
## Rôle
|
||||
Relais bidirectionnel entre le réseau WiFi (Jetson) et l'UART série
|
||||
(Pi Zero 2W puis Matek H743). Pont de communication du drone embarqué.
|
||||
|
||||
## Hardware
|
||||
- ESP32 DevKitV4 WROOM-32E
|
||||
- Framework : Arduino (PlatformIO)
|
||||
- UART2 : RX=GPIO16, TX=GPIO17, 57600 baud
|
||||
- LED status : GPIO2 (si disponible)
|
||||
|
||||
## Réseau
|
||||
### Hotspot drone (réseau principal)
|
||||
- WiFi : hotspot WireClaw créé par le Jetson (nmcli)
|
||||
- Interface Jetson : wlP1p1s0
|
||||
- Sous-réseau : 10.42.0.0/24
|
||||
- IP Jetson hotspot : 10.42.0.1
|
||||
- IP ESP32 : 10.42.0.77 (DHCP)
|
||||
- Ports UDP 14550-14553 ouverts dans iptables
|
||||
|
||||
### Réseau local (développement)
|
||||
- WiFi : Freebox-642534
|
||||
- IP ESP32 : 192.168.1.122 (DHCP — peut changer)
|
||||
- IP Jetson WiFi : 192.168.1.143
|
||||
- IP Jetson Ethernet : 192.168.1.84
|
||||
|
||||
### Ports UDP
|
||||
- 14550 : ESP32 écoute + source heartbeats
|
||||
- 14551 : Jetson MAVSDK
|
||||
- 14552 : Jetson pymavlink
|
||||
- 14553 : port de test libre
|
||||
|
||||
## Fichiers
|
||||
- src/main.cpp : firmware principal
|
||||
- include/credentials.h : WiFi + IP Jetson (gitignore — ne jamais committer)
|
||||
- include/credentials.h.example : template vide (commité)
|
||||
- platformio.ini : config PlatformIO
|
||||
|
||||
## Règles importantes
|
||||
- Ne jamais modifier credentials.h dans le code
|
||||
- Toujours désactiver le modem sleep : WiFi.setSleep(false)
|
||||
- Tester avec le moniteur série (115200 baud) après chaque flash
|
||||
- La LED clignote vite (100ms) = attente WiFi, lentement (500ms) = connecté
|
||||
- Après chaque modification réseau, vérifier sur le Jetson :
|
||||
python3 -c "import socket; s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM); s.bind(('0.0.0.0',14551)); print(s.recvfrom(1024))"
|
||||
|
||||
## Comportement actuel
|
||||
- Relais WiFi→UART : paquets UDP reçus → envoyés sur UART2
|
||||
- Relais UART→WiFi : octets UART reçus → envoyés UDP vers Jetson 14551 et 14552
|
||||
- Heartbeat texte toutes les 5s vers Jetson:14551 (test — à remplacer par MAVLink réel)
|
||||
|
||||
## Prochaines évolutions
|
||||
1. Reconnexion WiFi automatique si perte signal
|
||||
2. Heartbeat MAVLink réel (remplacer texte par message HEARTBEAT)
|
||||
3. Watchdog hardware (reboot si blocage)
|
||||
4. Vérifier réception côté Jetson — tester que les paquets UDP
|
||||
arrivent bien sur 192.168.1.143:14551 après reconnexion WiFi
|
||||
|
||||
## Gitea
|
||||
- Repo : git.syoul.fr/nicoboy/wireclaw-esp32
|
||||
37
src/main.cpp
37
src/main.cpp
@ -26,6 +26,8 @@ unsigned long lastBlink = 0;
|
||||
bool ledState = false;
|
||||
int blinkInterval = LED_WIFI_WAIT;
|
||||
unsigned long lastHeartbeat = 0;
|
||||
unsigned long lastReconnectAttempt = 0;
|
||||
const unsigned long RECONNECT_INTERVAL = 10000;
|
||||
|
||||
// ── Blink non bloquant ──────────────────────────────────
|
||||
void updateLED() {
|
||||
@ -36,6 +38,34 @@ void updateLED() {
|
||||
}
|
||||
}
|
||||
|
||||
void checkWiFi() {
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
if (!wifiConnected) {
|
||||
wifiConnected = true;
|
||||
blinkInterval = LED_WIFI_OK;
|
||||
WiFi.setSleep(false);
|
||||
Serial.println("WiFi reconnecte !");
|
||||
Serial.print("IP ESP32: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
udp.begin(LOCAL_PORT);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (wifiConnected) {
|
||||
wifiConnected = false;
|
||||
blinkInterval = LED_WIFI_WAIT;
|
||||
Serial.println("WiFi perdu !");
|
||||
}
|
||||
|
||||
if (millis() - lastReconnectAttempt >= RECONNECT_INTERVAL) {
|
||||
lastReconnectAttempt = millis();
|
||||
Serial.println("Tentative reconnexion WiFi...");
|
||||
WiFi.disconnect();
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
@ -86,15 +116,16 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
updateLED();
|
||||
checkWiFi();
|
||||
|
||||
// ── Heartbeat test → Jetson toutes les 5s ──
|
||||
if (millis() - lastHeartbeat > 5000) {
|
||||
if (wifiConnected && millis() - lastHeartbeat > 5000) {
|
||||
lastHeartbeat = millis();
|
||||
const char* msg = "WireClaw-ESP32-heartbeat";
|
||||
udp.beginPacket(JETSON_IP, JETSON_PORT_MAVSDK);
|
||||
udp.beginPacket(JETSON_IP, 14553);
|
||||
udp.write((const uint8_t*)msg, strlen(msg));
|
||||
udp.endPacket();
|
||||
Serial.println("Heartbeat envoyé → Jetson:14551");
|
||||
Serial.println("Heartbeat envoyé → Jetson:14553");
|
||||
}
|
||||
|
||||
if (!wifiConnected) return;
|
||||
|
||||
Reference in New Issue
Block a user