code-sammler-flat-room-group-B3.7.x — 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.7.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

#define WDT_TIMEOUT_SECONDS 5
#define SKETCH_CODE_VERSION "B3.7.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)

struct MsgFingerprint { uint16_t srcId; uint32_t seqNum; };
#define MESH_HISTORY_SIZE 512
MsgFingerprint meshHistory[MESH_HISTORY_SIZE];
uint16_t meshHistoryIdx = 0;

unsigned long lastWifiCheckTime = 0;
const unsigned long wifiCheckInterval = 10000; 

// Forward declarations fuer Arduino automatisch erzeugte Funktionsprototypen.
// Die vollstaendige Definition wird hier benoetigt, weil Velxio/Arduino
// Funktionsprototypen vor spaeteren Struct-Definitionen erzeugen kann.
struct SourceRecognitionState;
struct LogicState {
    uint16_t id;
    ScaledValue value;
    bool valid;
};
extern LogicState logicStates[20];
extern uint8_t logicStateCount;

// ===================================================================
// B3.6 - CONTEXT
// ===================================================================
// Context liefert allgemeine Umgebungs-/Zeitinformationen fuer die Logic.
// Context ist read-only fuer Conditions: Regeln lesen den aktuellen Kontext,
// veraendern ihn aber nicht. Feiertag wird bis zur spaeteren Config-Schicht
// als Laufzeitflag gefuehrt; dadurch bleibt B3.6 unabhaengig von Persistenz.
enum LogicContextId : uint16_t {
    CONTEXT_HOUR = 1,
    CONTEXT_MINUTE = 2,
    CONTEXT_WEEKDAY = 3,     // Montag=1 ... Sonntag=7
    CONTEXT_DAY = 4,         // Tag des Monats 1...31
    CONTEXT_MONTH = 5,       // Monat 1...12
    CONTEXT_HOLIDAY = 6,     // 0/1
    CONTEXT_NIGHT_MODE = 7   // 0/1
};

struct LogicContext {
    bool valid;
    uint8_t hour;
    uint8_t minute;
    uint8_t weekday;
    uint8_t day;
    uint8_t month;
    bool holiday;
    bool nightMode;
};

LogicContext logicContext = {false, 0, 0, 1, 1, 1, false, false};

// B3.6 Standard-Nachtfenster: 22:00 bis 05:59.
uint8_t contextNightStartHour = 22;
uint8_t contextNightEndHour = 6;
unsigned long contextLastUpdateMs = 0;
bool contextTimeSyncStarted = false;

// B3.6.1: Nicht blockierende SNTP-Initialisierung. Der Context darf erst
// dann al

More projects by bmw550i