diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index b8fe1e57..f8e9a4e2 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -3,16 +3,16 @@ /* ------------------------------ Config -------------------------------- */ #ifndef LORA_FREQ - #define LORA_FREQ 915.0 + #define LORA_FREQ 869.618 #endif #ifndef LORA_BW - #define LORA_BW 250 + #define LORA_BW 62.5 #endif #ifndef LORA_SF - #define LORA_SF 10 + #define LORA_SF 8 #endif #ifndef LORA_CR - #define LORA_CR 5 + #define LORA_CR 8 #endif #ifndef LORA_TX_POWER #define LORA_TX_POWER 20 @@ -443,6 +443,14 @@ void SensorMesh::handleCommand(uint32_t sender_timestamp, char* command, char* r board.setGpio(val); } sprintf(reply, "%x", board.getGpio()); + } else if (memcmp(command, "readpin ", 8) == 0) { + uint8_t pin = atoi(&command[8]); // Pin-Nummer extrahieren + if (pin < 32) { + bool pin_state = board.readPin(pin); // Zustand des Pins auslesen + sprintf(reply, "%s", pin_state ? "ON" : "OFF"); + } else { + strcpy(reply, "Err - invalid pin"); + } } else{ _cli.handleCommand(sender_timestamp, command, reply); // common CLI commands } diff --git a/examples/simple_sensor/main.cpp b/examples/simple_sensor/main.cpp index 330adcc2..f8b2c02e 100644 --- a/examples/simple_sensor/main.cpp +++ b/examples/simple_sensor/main.cpp @@ -102,6 +102,9 @@ void setup() { command[0] = 0; + // Konfiguriere GPIO 2 als Eingang mit Pull-Up + pinMode(2, INPUT_PULLUP); + sensors.begin(); the_mesh.begin(fs); diff --git a/src/helpers/ESP32Board.h b/src/helpers/ESP32Board.h index c2d78ae0..70f05ed9 100644 --- a/src/helpers/ESP32Board.h +++ b/src/helpers/ESP32Board.h @@ -48,6 +48,25 @@ public: #endif } + // Implement an actual getGpio for ESP32 boards + uint32_t getGpio() override { + uint32_t state = 0; + for (int pin = 0; pin < 32; pin++) { + if (digitalRead(pin) == HIGH) { + state |= (1 << pin); + } + } + return state; + } + + // Read the state of a single pin + public: + // Liest den Zustand eines einzelnen Pins (0-31) + bool readPin(uint8_t pin) { + if (pin >= 32) return false; // Ungültiger Pin + return digitalRead(pin) == HIGH; + } + // Temperature from ESP32 MCU float getMCUTemperature() override { uint32_t raw = 0;