-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp-cnc.ino
48 lines (43 loc) · 1 KB
/
esp-cnc.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
#include "wifi.h"
#include "socketio.h"
void setup() {
Serial.begin(115200);
Serial.println("lixo");
delay(250);
init_wifi();
init_socket();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
//Conexão do wi-fi
unsigned long previousmillis = 0;
void loop()
{
connection_socket();
unsigned long currentmillis = millis();
if(WiFi.status() != WL_CONNECTED){
digitalWrite(LED_BUILTIN, HIGH);
}else{
digitalWrite(LED_BUILTIN, LOW);
}
if ((WiFi.status() != WL_CONNECTED) && (currentmillis - previousmillis >= 1000))
{
//Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
// WiFi.reconnect();
init_wifi();
previousmillis = currentmillis;
}
else if (currentmillis - previousmillis >= 1000)
{
if ((WiFi.status() != WL_CONNECTED))
{
Serial.println("Sem internet");
}
else
{
previousmillis = currentmillis;
}
}
}