forked from sq6sfo/espBode
-
Notifications
You must be signed in to change notification settings - Fork 4
/
espBode.ino
97 lines (78 loc) · 1.91 KB
/
espBode.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
#include <ESP8266WiFi.h>
#include "esp_network.h"
#include "esp_config.h"
#include "ESPTelnet.h"
#if AWG == FY6800
#include "esp_fy6800.h"
#elif AWG == FY6900
#include "esp_fy6900.h"
#else
#error "Please select an AWG in esp_config.h"
#endif
WiFiServer rpc_server(RPC_PORT);
WiFiServer lxi_server(LXI_PORT);
ESPTelnet telnet;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
// We start by connecting to a WiFi network
DEBUG("Connecting to ");
DEBUG(WIFI_SSID);
#if defined(STATIC_IP)
IPAddress ip(ESP_IP);
IPAddress mask(ESP_MASK);
IPAddress gateway(ESP_GW);
WiFi.config(ip, gateway, mask);
#endif
#if defined(WIFI_MODE_CLIENT)
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PSK);
#elif defined(WIFI_MODE_AP)
WiFi.softAP(WIFI_SSID, WIFI_PSK);
#else
#error PLEASE SELECT WIFI_MODE_AP OR WIFI_MODE_CLIENT!
#endif
while (WiFi.status() != WL_CONNECTED) {
delay(500);
DEBUG(".");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
DEBUG("WiFi connected");
DEBUG("IP address: ");
DEBUG(WiFi.localIP().toString());
telnet.begin();
rpc_server.begin();
lxi_server.begin();
}
void loop() {
WiFiClient rpc_client;
WiFiClient lxi_client;
lxi_client.setTimeout(1000);
do
{
rpc_client = rpc_server.available();
}
while(!rpc_client);
DEBUG("RPC CONNECTION.");
handlePacket(rpc_client);
rpc_client.stop();
do
{
lxi_client = lxi_server.available();
}
while(!lxi_client);
DEBUG("LXI CONNECTION.");
while(1)
{
telnet.loop();
if(0 != handlePacket(lxi_client))
{
lxi_client.stop();
DEBUG("RESTARTING");
return;
}else{
// Lets give the user some feedback
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
}