-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_interfacer.h
61 lines (53 loc) · 1.57 KB
/
serial_interfacer.h
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
void ser_config(String confstring) {
int d = confstring.indexOf(':');
if(d != -1) {
confstring.substring(0, d).toCharArray(ssid, 32);
confstring.substring(d+1).toCharArray(password, 32);
Serial.println(ssid);
Serial.println(password);
saveCredentials();
Serial.println(MSG_SAVED);
} else {
Serial.println(MSG_FAIL);
}
}
void get_functions(String querystring) {
if(querystring == "ip") {
Serial.println(WiFi.localIP());
} else if (querystring == "disconnect") {
Serial.println(MSG_DISCONNECTED);
WiFi.disconnect();
} else if (querystring == "server") {
startserver();
} else if (querystring == "closeserver") {
closeserver();
} else {
Serial.println(MSG_FAIL);
}
}
//Serial Event function, is called, wehen serial data is received
void serialEvent() {
String input = Serial.readStringUntil('\n');
//output small command reference
if(input == "help") {
Serial.println("Command reference");
Serial.println("Set wifi-config: $<SSID>:<PASSWORD>");
Serial.println("Get ip-address &ip");
Serial.println("Reconnect WiFi &disconnect");
Serial.println("Begin udp server &server");
Serial.println("Close udp server &closeserver");
}
switch(input.charAt(0)) {
//switch to config parser
case '$': ser_config(input.substring(1)); break;
//switch to command parser
case '&': get_functions(input.substring(1)); break;
default: Serial.println(MSG_FAIL); break;
}
}
void serial_loop() {
if(Serial.available() > 0) {
//run serialEvent() if data is detected
serialEvent();
}
}