code-sammler-flat-room-group-B3.14xB — ESP32 simulation

Web-Log-Terminal: vollständige h-Ausgabe (Puffer 64), größere Anzeige und Stick-to-Bottom-Scroll-Logik.

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by bmw550i.

Components

Sketch code

// Version: B3.14.0

// ===================================================================
// SKETCH.INO - TEIL 1 (Definitionen, Variablen & Prototypen)
// ===================================================================
#include <WiFi.h>
#include <WebServer.h>
WebServer server(80);

#include <esp_now.h>
#include <ArduinoJson.h>
#include <esp_task_wdt.h> 
#include "esp_mac.h" 
#include "config.h"
#include "webpage.h"
#include <stdarg.h> 
#include <time.h>
#include <ArduinoOTA.h>  // ✅ Neu für drahtlose Updates

// B3.5.1: Muss vor den von Arduino/Velxio erzeugten Funktionsprototypen
// vollstaendig definiert sein. ActionTargetType kommt aus config.h.
struct ResolvedActionTarget {
    bool valid;
    ActionTargetType type;
    uint16_t targetId;
    int16_t index;
    uint8_t deviceType;
};

// ===================================================================
// B3.11.0: TEMPORAL RULE GATES
// ===================================================================
// Zeitfenster gehoeren zur Rule-Eignung, bleiben aber von den bestehenden
// Condition-Baeumen getrennt. Dieses Overlay ist bewusst runtime-only; die
// Config-/JSON-Struktur wird in B3.11.0 noch nicht erweitert.
struct RuleTemporalGate {
    bool valid;
    uint16_t ruleId;
    bool enabled;
    uint16_t startMinute;
    uint16_t endMinute;
    uint8_t weekdayMask;
};

#define MAX_RULE_TEMPORAL_GATES 32
RuleTemporalGate ruleTemporalGates[MAX_RULE_TEMPORAL_GATES];
uint8_t ruleTemporalGateCount = 0;


#define WDT_TIMEOUT_SECONDS 5
#define SKETCH_CODE_VERSION "B3.14.0"


uint32_t myLocalSequenceNumber = 0;
uint32_t simSequenceCounter = 0; 

bool logToSerialActive = true;    
bool logToEspNowActive = false;   
bool logToWebActive = true;
bool logEspNowTransmitInProgress = false; // Schutz gegen Log->TX->Log Rekursion    

#define WEB_LOG_MAX_LINES 512
String webLogBuffer[WEB_LOG_MAX_LINES];
uint16_t webLogBufferIdx = 0;
uint32_t webLogSequence = 0;   // Monotone Sequenznummer je Logzeile (fuer Browser-Inkrement-Abgleich)

// ===================================================================
// B3.8.2i - CHUNKED CONFIG IMPORT
// ===================================================================
// Der Browser zerlegt grosse JSON-Dateien in kleine HTTP-Requests.
// Der ESP32 sammelt die Chunks in einer temporaeren LittleFS-Datei und
// uebernimmt die Config erst nach erfolgreicher Vollstaendigkeits- und
// JSON-Pruefung beim COMMIT. Der Chunk-Index macht Wiederholungen eines
// bereits akzeptierten Chunks idempotent, falls der Proxy die Antwort
// verliert und der Browser denselben Chunk erneut sendet.
#define IMPORT_CHUNK_SIZE 400
#define IMPORT_TEMP_FILE "/config.import.tmp"
#define IMPORT_SESSION_ID_MAX 48

static bool importChunkActive = false;
static String importChunkSessionId;
static uint16_t importChunkExpected = 0;
static uint16_t importChunkTotal = 0;
static uint32_t importChunkTotalBytes = 0;
static uint32_t importChunkReceivedBytes = 0;
static uint16_t importChunkLastIndex = 

More projects by bmw550i