-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESP8266-indice-uv6.ino
193 lines (150 loc) · 4.92 KB
/
ESP8266-indice-uv6.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <ESP8266HTTPClient.h>
#include "uvi_vars.h"
///////vars///////
int actCycle = 0;
int maxCycle = 20;
String AP_NameString;
const char *AP_Password = "adminadmin";
const char *ssid = "";
const char *password = "";
char bufssid[64];
char bufsspass[64];
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
String uviPayload;
String remoteUVI="0";
String remoteFechaMax="";
String remoteFechaUlt="";
String remoteUVIMx="0";
String localUVI="0";
//String localFechaMax="";
String localFechaUlt="";
String tipo;
unsigned int localPort = 2390; // local port to listen for UDP packets
/* Don't hardwire the IP address or we won't get the benefits of the pool.
* Lookup the IP address for the host name instead */
//IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server
IPAddress timeServerIP; // time.nist.gov NTP server address
const char* ntpServerName = "time.nist.gov";
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
// A UDP instance to let us send and receive packets over UDP
WiFiUDP udp;
const int timeZone = -3; // Ch
String formatedDate;
///////////////////////////
struct Location {
char addr[100];
};
Location default_location = {0};
Location stored_location = {0};
struct Credential {
char uname[20];
char upass[50];
};
String defaultUserName="admin";
String defaultUserPass="admin";
Credential default_credential = {0,0};
Credential stored_credential = {0,0};
struct Estacion {
char id[20];
char nombre[100];
};
Estacion stored_estacion = {0,0};
struct Display {
char dmode[50];
char dpriority[50];
};
char default_dmode = {'Solo local'};
char default_dpriority = {'Principal local - secundario remoto'};
Display stored_display = {0,0};
int defaultPort = 8089;
int port = defaultPort;
///////vars///////
ESP8266WebServer server(port);
void setup() {
Serial.begin(115200);
EEPROM.begin(512);
delay(10);
Serial.println();
Serial.println("Inicio");
mientrasConecta();
//WiFi.disconnect(true);
//WiFi.mode(WIFI_AP_STA);
lee_credenciales();
lee_ubicacion();
lee_estacion();
lee_display();
Alarm.timerRepeat(300, lee_uvi_estacion);
lee_uvi_estacion();
if (WiFi.status() == WL_CONNECTED) {
Serial.println("WiFi connected");
Serial.print("STA IP address: "); Serial.print(WiFi.localIP());Serial.print(":");Serial.println(port);
}else{
Serial.print("Configuring access point...");
configureAP();
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");Serial.print(myIP);Serial.print(":");Serial.println(port);
}
server.on("/", handleRoot);
server.on("/indice-uv", handleAcercaDeIndiceUV);
server.on("/ubicacion", handleUbicacion);
server.on("/obtiene-uvi",handleJSON);
server.on("/change-to-sta", handleSta);
server.on("/kill-sta", handleKillSta);
server.on("/configuracion/kill-sta", handleKillSta2);
server.on("/configuracion/kill-sta2", handleKillSta3);
server.on("/configuracion/kill-ap", handleKillAP);
server.on("/login", handleLogin);
server.on("/configuracion/estado", handleAppStatus);
server.on("/configuracion", handleConfiguracion);
server.on("/configuracion/formulario-admin",handleAdminForm);
server.on("/configuracion/coneccion-ap", handleSetStation);
server.on("/configuracion/set-ubicacion", handleSetLocation);
server.on("/configuracion/set-estacion", handleSetEstacion);
server.on("/configuracion/set-display", handleSetDisplay);
server.on("/css/esp8266-pezGordo.css",handleCss);
server.on("/scripts/general.js",handleJSGeneral);
server.on("/scripts/inicio.js",handleJSInicio);
server.on("/scripts/admin.js",handleJSAdmin);
server.on("/scripts/redirect.js",handleJSRedirect);
server.on("/scripts/kill-sta.js",handleJSKillSta);
server.on("/scripts/kill-sta2.js",handleJSKillSta2);
server.onNotFound(handleNotFound);
//here the list of headers to be recorded
const char * headerkeys[] = {"User-Agent","Cookie"} ;
size_t headerkeyssize = sizeof(headerkeys)/sizeof(char*);
//ask server to track these headers
server.collectHeaders(headerkeys, headerkeyssize );
server.begin();
setSyncInterval(60);
setSyncProvider(haceUDP);
}
void loop() {
server.handleClient();
if (stringComplete) {
//Serial.println(inputString);
inputString.replace("\n","");
inputString.replace("\r","");
if(inputString=="solIP|"){
envia_data();
}
//if(inputString=="solIUVR|"){
if(tipo=="solIUVR"){
envia_indice_remoto();
//Serial.print("indice local ");Serial.println(localUVI);
}
// clear the string:
inputString = "";
stringComplete = false;
}
serialEvent();
Alarm.delay(0);
}