Hola a todos.
Me he hecho. Me he hecho un programador de riego con un NodeMCU. Abajo os pongo el código Que he utilizado junto con la app iOS Blynk. Todo me funciona de categoría.
Ahora estoy pensando en ponerle un Rain Delay que me permita poner en sleep todo el programador según los días que ponga en el Virtual Pin 33. El problema es que no se por donde empezar. Si alguien me puede echar una mano se agradecería.
Adjunto código y foto de GUI.
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on ESP8266 chip.
Note: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right ESP8266 module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define WIFI_LED 10
// define configuration (number of switches and number of timers)
#define SWITCH_CNT 4
#define TIME_CNT 4
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXXXXX";
char pass[] = "XXXXXXXXXXXXXX";
byte switch_pins[] = {14 , 12 , 16 , 13}; // number of gpio to be used as switch/relay control
bool switch_default[] = {LOW,LOW,LOW,LOW}; // switches that use reverse polarity should be set to HIGH here
////////////////////////////////////////////////////////////////////////////////////////
// This code can control up to 4 switches //
// For each switch up to 4 schedule start and end times can be configured - (V0..V15) //
// A default duration can be defined per switch - (V16..V19)//
// If an end time is not defined at the app the default duration is used //
// default duration is also used when manually activating the switch - (V20..V23)//
// for each switch when start time is reached the switch turns on for the duration //
// //
// maximum duration is used for safety (to limit activation time) - (V24..V27)//
////////////////////////////////////////////////////////////////////////////////////////
int start_time_sec[SWITCH_CNT][TIME_CNT]; // array of 4 start times (in seconds) for 4 switches [switch number][schedual timer number]
bool start_valid[SWITCH_CNT][TIME_CNT]; // is the start time valid ?
bool weekdays[SWITCH_CNT][TIME_CNT][8]; // array of 8 days (day 0 not used) for each schedual time
int active_duration[SWITCH_CNT][TIME_CNT+1]; // duration per switch per time(in sec)
bool end_valid[SWITCH_CNT][TIME_CNT]; // is the end time valid ?
int max_duration[SWITCH_CNT]; // max duration per switch
int auto_off = 1; // 1 is auto or on
// when activating a switch a timer is set for the configured duration
// when the duration ends the switch is turned off by the timer
// the id of the timer is saved using end_timer_id
// if switch is manually turned off the end_timer_id is used to stop the timer.
// end_timer_id is initialized to 32 (per entry) at the setup section
int end_timer_id[SWITCH_CNT];
// timer object declaration
BlynkTimer timer;
// this code use Real Time Clock widget in the blynk app to keep the clock updated from net
WidgetRTC rtc;
BLYNK_CONNECTED() {
// Synchronize time on connection
rtc.begin();
Blynk.syncAll();
}
WidgetLED led1(V55);
bool ledStatus = auto_off;
// V55 LED Widget is ON or OFF
void LedWidget()
{ledStatus = auto_off;
if (ledStatus) {
led1.on();
} else {
led1.off();
}
}
Gracias