Skip to content

Commit

Permalink
Added ESP8266 water leak sensor
Browse files Browse the repository at this point in the history
Added ESP8266 water leak sensor
  • Loading branch information
iot-playground committed Jan 23, 2015
1 parent e3c5490 commit 23ba3c8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
53 changes: 53 additions & 0 deletions Esp8266EasyIoT/examples/esp8266_leak/esp8266_leak.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
V1.0 - first version
Created by Igor Jarc <[email protected]>
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 <Esp8266EasyIoT.h>
#include <SoftwareSerial.h>

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;
}
}


4 changes: 2 additions & 2 deletions external_libraries/MySensors/MyMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 23ba3c8

Please sign in to comment.