diff --git a/Esp8266EasyIoT/examples/esp8266_leak/esp8266_leak.ino b/Esp8266EasyIoT/examples/esp8266_leak/esp8266_leak.ino new file mode 100644 index 0000000..e27d7ae --- /dev/null +++ b/Esp8266EasyIoT/examples/esp8266_leak/esp8266_leak.ino @@ -0,0 +1,53 @@ + /* + V1.0 - first version + + Created by Igor Jarc + See http://iot-playground.com for details + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + */ +#include +#include + +Esp8266EasyIoT esp; + +SoftwareSerial serialEsp(10, 11); + +#define LEAK_PIN 2 // Arduino Digital I/O pin number +#define CHILD_ID_LEAK 0 + +Esp8266EasyIoTMsg msgLeak(CHILD_ID_LEAK, V_DIGITAL_VALUE); +//Esp8266EasyIoTMsg msgHum(CHILD_ID_LEAK, V_LEAK); // supported in esp >= V1.1 lib + +int lastLeakValue = -1; + +void setup() +{ + serialEsp.begin(9600); + Serial.begin(115200); + + Serial.println("EasyIoTEsp init"); + esp.begin(NULL, 3, &serialEsp, &Serial); + + pinMode(LEAK_PIN, INPUT); + + esp.present(CHILD_ID_LEAK, S_LEAK); +} + +void loop() +{ + esp.process(); + + // Read digital pin value + int leakValue = digitalRead(LEAK_PIN); + // send if changed + if (leakValue != lastLeakValue) { + Serial.println(leakValue); + esp.send(msgLeak.set(leakValue==0?0:1)); + lastLeakValue = leakValue; + } +} + + diff --git a/external_libraries/MySensors/MyMessage.cpp b/external_libraries/MySensors/MyMessage.cpp index 286b111..9bf6a76 100644 --- a/external_libraries/MySensors/MyMessage.cpp +++ b/external_libraries/MySensors/MyMessage.cpp @@ -177,10 +177,10 @@ MyMessage& MyMessage::set(void* value, uint8_t length) { MyMessage& MyMessage::set(const char* value) { - uint8_t length = strlen(value); + uint8_t length = min(strlen(value), MAX_PAYLOAD); miSetLength(length); miSetPayloadType(P_STRING); - strncpy(data, value, min(length, MAX_PAYLOAD)); + strncpy(data, value, length); return *this; }