Re: Le réseau modulaire de Likiki
Posté : 09 sept. 2025, 19:07
SUPER !!!
Attention de ne pas prendre toutes les épingles à linge de Madame..

Attention de ne pas prendre toutes les épingles à linge de Madame..
Le forum des passionnés de trains miniature, de petites autos etc etc
https://forum-passionnement.eu/
Code : Tout sélectionner
#include <ESP8266WiFi.h>
#include <espnow.h>
#include <ESP8266WebServer.h>
// Adresses MAC des autres cartes ESP
// uint8_t macESP2[] = {0xec, 0x64, 0xc9, 0xc0, 0x4b, 0x71}; // Carte relais ESP8266 4 Relais
uint8_t macESP2[] = {0x08, 0xa6, 0xf7, 0x6a, 0xa8, 0xb8}; // Carte relais 8 Relais ESP 32 DEV Module
uint8_t macESP3[] = {0x24, 0x6F, 0x28, 0xDD, 0xEE, 0xFF}; // En attente Carte relais 8 Relais ESP 32 DEV Module
uint8_t macESP4[] = {0x24, 0x6F, 0x28, 0x11, 0x22, 0x33}; // En attente
ESP8266WebServer server(80);
/* ===============================
PAGE WEB
=============================== */
void handleRoot() {
String html = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { font-family: Arial; text-align: center; background: #f0f0f0; }
h1 { color: #333; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; max-width: 300px; margin: auto; }
button { padding: 20px; font-size: 20px; font-weight: bold; border: none; border-radius: 12px; cursor: pointer; color: white; transition: transform 0.1s; }
button:active { transform: scale(0.9); }
.b0 { background: #4CAF50; }
.b1 { background: #2196F3; }
.b2 { background: #FF9800; }
.b3 { background: #9C27B0; }
.b4 { background: #F44336; }
.b5 { background: #795548; }
.bp { background: #3F51B5; }
.br { background: #009688; }
</style>
</head>
<body>
<h1>Controle Ascenseur</h1>
<div class="grid">
<button class="b0" onclick="sendCmd('0')">0</button>
<button class="b1" onclick="sendCmd('-1')">-1</button>
<button class="b2" onclick="sendCmd('-2')">-2</button>
<button class="b3" onclick="sendCmd('-3')">-3</button>
<button class="b4" onclick="sendCmd('-4')">-4</button>
<button class="b5" onclick="sendCmd('-5')">-5</button>
<button class="bp" onclick="sendCmd('P')">P</button>
<button class="br" onclick="sendCmd('R')">R</button>
</div>
<p id="status"></p>
<script>
function sendCmd(cmd) {
fetch('/mega?cmd=' + cmd)
.then(r => r.text())
.then(t => { document.getElementById('status').innerText = t; });
}
</script>
</body>
</html>
)rawliteral";
server.send(200, "text/html", html);
}
/* ===============================
TRAITEMENT COMMANDE WEB
=============================== */
void handleMegaCmd() {
String cmd = server.arg("cmd");
if (cmd.length() > 0) {
// ✅ Envoyer uniquement la commande brute à la MEGA
Serial.println(cmd);
server.send(200, "text/plain", "Commande envoyée à MEGA: " + cmd);
} else {
server.send(400, "text/plain", "Commande vide");
}
}
/* ===============================
CALLBACK RECEPTION ESP-NOW
=============================== */
void OnDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len) {
String msg = String((char*)incomingData);
// Serial.println("Reçu via ESP-NOW: " + msg);
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP_STA);
WiFi.softAP("ASCTRAIN", "1704"); // problème à régler ici car non visible
// Serial.println("WiFi: ASCTRAIN / 1704");
// Serial.println("Ouvrir http://192.168.4.1"); // Adresse à taper dans le navigateur
// Serveur web
server.on("/", handleRoot);
server.on("/mega", handleMegaCmd);
server.begin();
// ESP-NOW
if (esp_now_init() != 0) {
// Serial.println("Erreur init ESP-NOW");
return;
}
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
esp_now_register_recv_cb(OnDataRecv);
esp_now_add_peer(macESP2, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
esp_now_add_peer(macESP3, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
esp_now_add_peer(macESP4, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
}
void loop() {
server.handleClient();
// Lecture depuis le port série (venant de la MEGA) le Wemos servant de passerelle de répétition
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
// Serial.println("Commande reçue de MEGA: " + cmd);
// ✅ Ici ESP1 joue son rôle de routeur vers ESP2/3/4
if (cmd.indexOf("ESP2:") == 0) {
String sub = cmd.substring(5);
esp_now_send(macESP2, (uint8_t*)sub.c_str(), sub.length() + 1);
}
else if (cmd.indexOf("ESP3:") == 0) {
String sub = cmd.substring(5);
esp_now_send(macESP3, (uint8_t*)sub.c_str(), sub.length() + 1);
}
else if (cmd.indexOf("ESP4:") == 0) {
String sub = cmd.substring(5);
esp_now_send(macESP4, (uint8_t*)sub.c_str(), sub.length() + 1);
}
}
}

Hé bien t'as d'la chance ! ! !


ramasoft a écrit : 17 sept. 2025, 16:47 Tu peux peut-être faire un système qui se relève d'un côté avec des charnières.
Et éventuellement le motoriser avec une commande par un détecteur de passage à cellule photo électrique à l'entrée de la pièce, le tout commandé par un Arduino![]()
Il faudra prévoir une sécurité pour que ça ne se relève que si le courant est coupé sur le réseau.![]()
herwat a écrit : 17 sept. 2025, 16:58 Oui, il faut faire une passerelle qui se relève . Ce n'est pas très compliqué .
Bon, c'est du boulot en plus .![]()
![]()
![]()

3 épaisseurs de quoi Christian ?likiki a écrit : 17 sept. 2025, 16:25 Voici une approche pour le bouclage, C'est du provisoire juste pour voir (il y a 3 épaisseurs différente).
La première chose que j'ai compris, c'est que passer dessous est pour moi très très difficile.![]()
![]()