#include #include const char* AP_SSID = "Modellbahn_Steuerung"; const char* AP_PASS = "12345678"; ESP8266WebServer server(80); // Befehl und Antwort für die spätere Steuerung uint8_t sendByteValue = 0; uint8_t receivedByteValue = 0; bool commandPending = false; bool responseAvailable = false; // Zustände bool blockState[6] = {false}; bool turnoutState[3] = {false}; // Befehlszuordnung const uint8_t blockCommand[6] = {31, 32, 33, 34, 35, 36}; const uint8_t turnoutInside[3] = {10, 12, 14}; const uint8_t turnoutOutside[3] = {11, 13, 15}; const uint8_t extraCommand[6] = {20, 21, 22, 23, 24, 25}; const char PAGE[] PROGMEM = R"MODELBAHN( Modellbahn-Steuerung
🚂 Modellbahn-Steuerung ESP8266 · WLAN

Gleisbild

Rot = aus · Grün = eingeschaltet · Raster als Zeichenhilfe
Kleine Punkte: Grün = Anfang · Rot = Ende
0 100 200 300 400 500 600 700 800 900 0 100 200 300 400 500 600 700 G02 G09 G10 G11 G12 G13 G14 G15 G16 G17 G18 G19 G20 BL1 BL2 BL3 BL4 BL5 BL6 V R E A W1 W2 W3 20 21 22 23 24 25 Byte: —

Byte-Anzeige

—
Binär: —
Antwortbyte: —
Bereit

Gleisabschnitte

Weichen – innen / außen

Fahren / Steuerung

Sechs Zusatztasten

)MODELBAHN"; void setup() { Serial.begin(115200); WiFi.mode(WIFI_AP); WiFi.softAP(AP_SSID, AP_PASS); server.on("/", HTTP_GET, []() { server.send_P(200, "text/html; charset=utf-8", PAGE); }); server.on("/cmd", HTTP_GET, []() { if (!server.hasArg("b")) { server.send(400, "text/plain", "Parameter b fehlt"); return; } String input = server.arg("b"); if (input.length() == 0) { server.send(400, "text/plain", "Byte fehlt"); return; } long value = input.toInt(); if (value < 0 || value > 255) { server.send(400, "text/plain", "Byte ungueltig"); return; } sendByteValue = (uint8_t)value; commandPending = true; responseAvailable = false; Serial.printf("Befehl gespeichert: %u (0x%02X)\n", sendByteValue, sendByteValue); server.send(200, "text/plain", "OK"); }); server.on("/state", HTTP_GET, []() { String json = "{"; json += "\"sendByte\":" + String(sendByteValue) + ","; json += "\"receivedByte\":" + String(receivedByteValue) + ","; json += "\"commandPending\":"; json += commandPending ? "true" : "false"; json += ",\"responseAvailable\":"; json += responseAvailable ? "true" : "false"; json += "}"; server.send(200, "application/json", json); }); server.begin(); Serial.println(); Serial.println("Modellbahn-Steuerung bereit"); Serial.print("WLAN: "); Serial.println(AP_SSID); Serial.println("Adresse: http://192.168.4.1"); } void loop() { server.handleClient(); // Später hier: // - sendByteValue an die Steuerung übertragen // - Antwortbyte empfangen und in receivedByteValue speichern // - responseAvailable = true setzen // - commandPending = false setzen }