-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNuevo-documento-de-texto-2.txt
146 lines (145 loc) · 3.98 KB
/
Nuevo-documento-de-texto-2.txt
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
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include <Time.h>
//yeeeeey perro
ESP8266WebServer server(80);
void inicializar()
{
configAP(1); //1 indica AP activado, 0 AP desactivado
}
void configAP(int i) //1 indica AP activado, 0 AP desactivado
{
if (i == 1)
{
if (EEPROM.read(0) != 1)
{
Serial.println(); Serial.println();
Serial.println("Inicia_ AP");
char c_ApSsid[14], c_ApPass[8];
int i_ApSsid = 0, i_ApPass = 0;
String s_ApSsid = "Wiicoon_";
s_ApSsid = s_ApSsid + WiFi.softAPmacAddress()[9]
+ WiFi.softAPmacAddress()[10]
+ WiFi.softAPmacAddress()[12]
+ WiFi.softAPmacAddress()[13]
+ WiFi.softAPmacAddress()[15]
+ WiFi.softAPmacAddress()[16];
i_ApSsid = s_ApSsid.length() + 1;
s_ApSsid.toCharArray(c_ApSsid, i_ApSsid);
String s_ApPass = getApPass(WiFi.softAPmacAddress());
i_ApPass = s_ApPass.length() + 1;
s_ApPass.toCharArray(c_ApPass, i_ApPass);
server.begin();
WiFi.softAP(c_ApSsid, c_ApPass);
EEPROM.write(0, 1); //1 indica AP activado, 0 AP desactivado
EEPROM.commit();
}
}
else
{
if (EEPROM.read(0) == 1)
{
Serial.println(); Serial.println();
Serial.println("Termina_ AP");
WiFi.softAPdisconnect(true);
EEPROM.write(0, 0); //1 indica AP activado, 0 AP desactivado
EEPROM.commit();
}
}
}
String getApPass(String s_macAddress)
{
String s_pass = "";
int i_indice;
char c_caracteres[4];
i_indice = s_macAddress.lastIndexOf(":");
c_caracteres[0] = s_macAddress.charAt(i_indice - 2);
c_caracteres[1] = s_macAddress.charAt(i_indice - 1);
c_caracteres[2] = s_macAddress.charAt(i_indice + 1);
c_caracteres[3] = s_macAddress.charAt(i_indice + 2);
for (int i = 0; i < 4; i++)
{
switch (c_caracteres[i])
{
case '0': s_pass = s_pass + "00"; break;
case '1': s_pass = s_pass + "01"; break;
case '2': s_pass = s_pass + "02"; break;
case '3': s_pass = s_pass + "03"; break;
case '4': s_pass = s_pass + "04"; break;
case '5': s_pass = s_pass + "05"; break;
case '6': s_pass = s_pass + "06"; break;
case '7': s_pass = s_pass + "07"; break;
case '8': s_pass = s_pass + "08"; break;
case '9': s_pass = s_pass + "09"; break;
case 'A': s_pass = s_pass + "10"; break;
case 'B': s_pass = s_pass + "11"; break;
case 'C': s_pass = s_pass + "12"; break;
case 'D': s_pass = s_pass + "13"; break;
case 'E': s_pass = s_pass + "14"; break;
case 'F': s_pass = s_pass + "15"; break;
default:
break;
}
}
return s_pass;
}
void entregaDatos()
{
Serial.println(); Serial.println();
Serial.println("Entrega_datos");
StaticJsonBuffer<500> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
String s_ApMacAddress = WiFi.softAPmacAddress();
String s_IpLocal = String(WiFi.localIP()[0]) + "."
+ String(WiFi.localIP()[1]) + "."
+ String(WiFi.localIP()[2]) + "."
+ String(WiFi.localIP()[3]);
Serial.println(s_IpLocal);
Serial.println(s_ApMacAddress);
root["macAddress"] = s_ApMacAddress;
if (WiFi.isConnected() == true)
root["ipAddress"] = s_IpLocal;
root["numSalidas"] = 6;
JsonArray& focos = root.createNestedArray("focos");
JsonObject& foco1 = focos.createNestedObject();
foco1["estado"];
foco1["numDeSalida"];
String s_myString;
root.prettyPrintTo(s_myString);
server.send(200, "application/json", s_myString);
}
void limpiaEeprom()
{
entregaDatos();
for (int i = 0; i < 999; i++)
EEPROM.write(i, 255);
EEPROM.commit();
}
void leeprom()
{
entregaDatos();
for (int i = 0; i < 999; i++)
{
Serial.print(i);
Serial.print(" ");
Serial.println(EEPROM.read(i));
}
}
void setup()
{
Serial.begin(115200);
EEPROM.begin(2048);
limpiaEeprom();
server.begin();
inicializar();
server.on("/data_info", entregaDatos);
server.on("/leeprom", leeprom);
}
void loop()
{
server.handleClient();
delay(100);
}