// Arduino sketch which outputs PWM for a set of channels based on serial input.
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiClient.h>
#include <SC.h>
#include <PrintLevel.h>
//WIFI PASS
const char* ssid = "touchametron";
const char* password = "superduper";
// TCP server at port 80 will respond to HTTP requests
WiFiServer server(1337);
const int timeout = 30;
/////////////////////////////////////////////////////////////////////////////////////////
// Command Manager and forward declarations for commands accessible from text interface
/////////////////////////////////////////////////////////////////////////////////////////
void cmdUnrecognized(const char *cmd);
void cmdRed();
SerialCommand::Entry CommandsList[] = {
{"red", cmdRed},
{NULL, NULL}
};
SerialCommand CmdMgr(CommandsList, cmdUnrecognized);
/////////////////////////////////////////////////////////////////////////////////////////////
// helpers
/////////////////////////////////////////////////////////////////////////////////////////////
void cmdUnrecognized(const char *cmd) {
printlnError("unrecognized command");
}
void cmdRed() {
// Turn the LED red
printlnError("hellooo");
// delay(30);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// setup & loop
///////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
delay(10);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
int i = 0;
while (WiFi.status() != WL_CONNECTED ) {
if (i < timeout) {
delay(500);
Serial.print(".");
i++;
}
else {
Serial.println(" ");
break;
}
}
if (WiFi.status() == WL_CONNECTED ) {
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Set up mDNS responder:
// - first argument is the domain name, in this example
// the fully-qualified domain name is "esp8266.local"
// - second argument is the IP address to advertise
// we send our IP address on the WiFi network
if (!MDNS.begin("esp32")) {
Serial.println("Error setting up MDNS responder!");
while (1) {
delay(1000);
}
}
Serial.println("mDNS responder started");
// Start TCP (HTTP) server
server.begin();
Serial.println("TCP server started");
// Add service to MDNS-SD
MDNS.addService("telnet", "tcp", 1337);
}
Serial.println("Done setting up");
}
void loop() {
CmdMgr.readSerial();
WiFiClient client = server.available();
if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
CmdMgr.handleChar(c);
Serial.write(c); // print it out the serial monitor
}
}
}
}