-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic.ino
78 lines (61 loc) · 1.8 KB
/
Basic.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
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <AsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include <RemoteSerial.h>
// The following colour codes are just example, more can be found here:
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
#define ANSI_RED "\x1B[0;91m"
#define ANSI_GREEN "\x1B[0;92m"
#define ANSI_YELLOW "\x1B[0;93m"
#define ANSI_BLUE "\x1B[0;94m"
#define ANSI_MAGENTA "\x1B[0;95m"
#define ANSI_CYAN "\x1B[0;96m"
#define ANSI_WHITE "\x1B[0;97m"
AsyncWebServer server(80);
const char* ssid = "YOUR_SSID"; // Your WiFi SSID
const char* password = "YOUR_PASSWORD"; // Your WiFi Password
bool connected = false;
// Handle any incoming messages
void messageReceived(const uint8_t *data, size_t len){
char str[len];
for(uint16_t i = 0; i < len; i++){
str[i] = data[i];
}
str[len] = 0;
Serial.print("Received: ");
Serial.println(str);
}
void setup() {
Serial.begin(115200);
Serial.println();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed!");
return;
}
connected = true;
Serial.println("WiFi connected");
Serial.print("http://");
Serial.print(WiFi.localIP().toString());
Serial.println("/remoteserial");
RemoteSerial.setIncomingMessageHandler(messageReceived);
RemoteSerial.begin(&server); // You can also add a custom url, e.g. /remotedebug
server.begin();
}
void loop() {
if (!connected){
return;
}
Serial.println("Outputing a message");
RemoteSerial.printf("%s IP address: %s\n", ANSI_WHITE, WiFi.localIP().toString().c_str());
RemoteSerial.printf("%s Millis: %lu\n", ANSI_MAGENTA, millis());
RemoteSerial.printf("%s Heap: %u\n", ANSI_CYAN, ESP.getFreeHeap());
RemoteSerial.cleanupClients();
delay(2000);
}