-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-network.ino
55 lines (40 loc) · 1019 Bytes
/
01-network.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
#include "WebSocketClientMod.h"
#include <ESP8266WiFi.h>
const char *ssid = "foo"; // replace with your wifi ssid and wpa2 key
const char *pass = "bar";
WiFiClient client;
// @see https://platformio.org/lib/show/6123/ESP8266%20Websocket%20Client/examples
WebSocketClientMod ws(false);
unsigned long websocketAliveLast = 0;
uint16_t websocketInterval = 3000;
void setupNetwork()
{
}
void connectWlan() {
//debug("Connecting to ");
//debug(ssid);
WiFi.begin(ssid, pass);
WiFi.setAutoReconnect (true);
}
void reconnectWlan() {
if(WiFi.status() == WL_CONNECTED) {
WiFi.disconnect(true);
delay(500);
}
connectWlan();
}
void loopNetwork() {
if (!ws.isConnected()) {
//debug("connecting to websocket...");
ws.connect("10.0.1.124", "/", 80);
return;
}
String msg;
if (ws.getMessage(msg)) {
handleIncomingMixerMessage(msg);
}
if(millis() - websocketAliveLast >= websocketInterval) {
ws.send("3:::ALIVE");
websocketAliveLast = millis();
};
}