Control if your plant needs some water, iphone notification
Posted: Thu Mar 26, 2015 7:28 pm
Hello all,
I think the title is clear enough to discribe the project.
The ESP8266 is connected to a moisture sensor (GPIO2- less $1) a led(GPIO0)
Checks every 6 to 8h
send an iPhone notification thru Prowl (2,99€) and blinks the led.
Here is my code.
I get 2 last things to resolve. any help apprecied.
1/ the last tmr.alarm doesn't start.. ?? (tmr.alarm(2,1000,1,check_pin(4)); --GPIO2 )
2/ If the sensor is connected before to plug the battery or external power to ESP, I get a "crash". bad info...
NodeMCU 0.9.5 build 20150212 powered by Lua 5.1.4 -- ESP8266-01
I think the title is clear enough to discribe the project.
The ESP8266 is connected to a moisture sensor (GPIO2- less $1) a led(GPIO0)
Checks every 6 to 8h
send an iPhone notification thru Prowl (2,99€) and blinks the led.
Here is my code.
I get 2 last things to resolve. any help apprecied.
1/ the last tmr.alarm doesn't start.. ?? (tmr.alarm(2,1000,1,check_pin(4)); --GPIO2 )
2/ If the sensor is connected before to plug the battery or external power to ESP, I get a "crash". bad info...
NodeMCU 0.9.5 build 20150212 powered by Lua 5.1.4 -- ESP8266-01
Code: Select all
function send_prowl(_event,_description)
conn=net.createConnection(net.TCP, 0);
conn:on("receive", function(conn, payload) print(payload) end);
conn:connect(80,'209.20.89.148'); --prowl server : prowl.com
conn:send("POST /publicapi/add?apikey=3bbe4be8fb205c0cf918f6xxxxxxxxx&application=PLANTE&event=".._event.."&description=".._description.."&priority=1 HTTP/1.1\r\n");
conn:send("Host: prowl.weks.net\r\n");
conn:send("Accept: */*\r\n");
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n");
conn:send("\r\n");
print("send: ".._event);
tmr.delay(5000);
end;
--------------------------------------------------
local function check_wifi()
local ip = wifi.sta.getip();
if(ip==nil) then
print("Connecting...");
else
tmr.stop(0);
print("Connected to AP!");
print(ip);
send_prowl("connecté","Hello+from+your+ESP8266");
end;
end;
local function check_pin(pin)
print("check_pin avec l'état "..gpio.read(pin));
local pinValue = gpio.read(pin);
if pinValue == 1 then
send_prowl("check: j%27ai+soif!","la+plante+a+besoin+d%27eau");
print("need water");
blink=true;
else
blink=false;
end;
end;
-----------------------------------------------
function toggleLED ()
led=3;
if blink == true then
if gpio.read(led) == gpio.LOW then
gpio.write(led,gpio.HIGH);
else
gpio.write(led,gpio.LOW);
end;
end;
end;
------------------------------------------
--// connect to wifi
------------------------------------------
-- Your access point's SSID and password
local SSID = "myssid";
local SSID_PASSWORD = "mypswd";
-- configure ESP as a station
wifi.setmode(wifi.STATION);
wifi.sta.config(SSID,SSID_PASSWORD);
wifi.sta.autoconnect(1);
tmr.alarm(0,2000,1,check_wifi)
-------------------------------------------
--// check plant value and send prowl message
-------------------------------------------
--tmr.alarm(1,10000,1,loadfile("check.lua")) -- Another try to toggle and check moisture status
local pin = 4; --> GPIO2
local led = 3; --> GPIO0
print("hello world");
blink = false;
gpio.mode(pin, gpio.INPUT);
gpio.mode(led, gpio.OUTPUT);
gpio.write(led, gpio.LOW);
tmr.alarm(3,1000,1,toggleLED(3));
tmr.alarm(2,1000,1,check_pin(4)); --GPIO:2 // 8h 28800000