Files

57 lines
1.6 KiB
C++

#include <ESP8266WiFiMulti.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#include "credentials.h"
#include "webserver.h"
#include "socketserver.h"
#include "util.h"
static ESP8266WiFiMulti wifiMulti;
static SocketServer socketServer;
void setup() {
// serial console, for use via USB (also exposed to TXD0/RXD0 GPIOs)
Serial.begin(115200);
// transmit-only UART port, used for communication with the LED sign
// the BAUD rate was deducued from the communication sent to the USB 12V UART adapter by the available Windows
// software
Serial1.begin(9600);
// configure WiFi and connect to the network
wifiMulti.addAP(credentials::ssid.c_str(), credentials::psk.c_str());
Serial.println("Connecting to Wi-Fi network...");
while (wifiMulti.run() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println();
Serial.print("Connected to ");
Serial.print(WiFi.SSID());
Serial.print(", IP address: ");
Serial.println(WiFi.localIP());
// might be handy to have the IP written on the sign
sendTextToSign(WiFi.localIP().toString());
// publish this service using mDNS so that it's easy to find it in the LAN
if (MDNS.begin(credentials::mdnsHostname)) {
Serial.println("mDNS started up successfully");
} else {
Serial.println("Error: failed to start mDNS");
}
// configure HTTP endpoints
configureWebServer();
// don't forget to start all the services
webServer.begin();
socketServer.begin();
}
void loop() {
webServer.handleClient();
socketServer.handleClient();
}