-
Notifications
You must be signed in to change notification settings - Fork 2
/
firmware.ino
96 lines (78 loc) · 2.84 KB
/
firmware.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* Simple Web Server for ESP8266-12E by Tiago
alterado do exemplo de NattyFido 2015
www.nattyfido.co.uk (shameless plug!)
https://esp8266.ru/forum/threads/umnyj-dom-dlja-chajnika.1581/page-9#post-22893
*/
#include <ESP8266WiFi.h>
#include <Ticker.h> //https://github.com/esp8266/Arduino/tree/master/libraries/Ticker
#include "OTA.h" // executa a aba OTA
#include "server.h" // recupera dados da aba server
/******************** LibSimpleTIMER *******************//
#include <SimpleTimer.h>// substitui o delay que trava funções do esp8266
SimpleTimer timer;
//******************** Conexão Wifi*******************//
IPAddress ip(192, 168, 1, 101); //NodeMCU static IP
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
const char* ssid = "SuaSSID"; // SSID of LAN/WLAN
const char* password = "SuaSenha"; // password
//******************** WTD *******************//
Ticker secondtick;
volatile int watchdogCount = 0;
void restart(){
ESP.restart();//
}
void reset_config(void) {
// Serial.println("*WifiRTC: O ESP ira resetar agora");
delay(1500);
ESP.reset();
}
void ISRWatchdog() {
watchdogCount++;
if (watchdogCount > 70) {
// Serial.println("*WifiRTC: Watchdog bite! Reiniciando");
ESP.reset();
}
}
//******************** Setup *******************//
void setup() {
WiFi.persistent(false);
Serial.begin(115200); // start serial for debug
delayMicroseconds(250);
pinMode(BUILTIN_LED, OUTPUT);
pinMode(D5, OUTPUT); // all outputs for LEDs
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);
// pinMode(led3, OUTPUT);
digitalWrite(BUILTIN_LED, 1); // all LEDs off to start
digitalWrite(D5, 0);
digitalWrite(D7, 0);
digitalWrite(D8, 0);
//Define conexão direta
WiFi.config(ip, gateway, subnet);// ip fixo
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(BUILTIN_LED, 0);
delay(500);
digitalWrite(BUILTIN_LED, 1);
Serial.print(".");
}
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println(F("*WifiRTC: Falha na conexão! Reiniciando..."));
timer.setTimeout((5000L), restart); // aciona depois de X segundos
}
Serial.println(F("*WifiRTC: Conectado"));
server.begin();
OTA(); // executa a função OTA na setup
Eeprom();//recupera os dados da eeprom
ntp(); //recupera valores do horaNTP
Serial.print("IP: ");
Serial.println(WiFi.localIP());
}
//******************** Loop *******************//
void loop() {
watchdogCount = 0; //Zera Watchdog
webpage(); //carrega o webserver
TimedAction(); // verifica que o o botão auto esta ativado
ArduinoOTA.handle(); // aciona arduino OTA colar no loop
}