-
Notifications
You must be signed in to change notification settings - Fork 1
/
socketio-client.ino
48 lines (43 loc) · 1.18 KB
/
socketio-client.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 <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <SocketIoClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
SocketIoClient webSocket;
String inputString;
void event(const char * payload, size_t length) {
USE_SERIAL.printf("got message: %s\n", payload);
}
void setup() {
USE_SERIAL.begin(115200);
USE_SERIAL.setDebugOutput(true);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFiMulti.addAP("SSID", "p4sw00rd$");
while(WiFiMulti.run() != WL_CONNECTED) {
delay(100);
}
webSocket.on("message", event);
//webSocket.begin("yourserver-socketio", PORT);
webSocket.begin("socketio-simple.bangjii.repl.co");
}
void loop() {
webSocket.loop();
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
inputString.trim();
String asd = "\"" + inputString + "\"";
webSocket.emit("message", asd.c_str());
inputString = "";
}
}
}