diff --git a/.gitignore b/.gitignore index 926f983..8b13789 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/data-dev/maincontrols.txt + diff --git a/README.md b/README.md index 89506ef..8188dbe 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,18 @@ Wifi Host for the Arduino-Laser-Spirograph #usage: - /motor/{motorNr}/{value} - /laser/{value} - /ssid/{ssidname} - /pwd/{password} - /apmode/1 -> SofAP (default), 0 -> client - /saveconf -> write wificonfig to file - /resetwifi -> reconnect wifi with the new settings (this will work) + /motor/{motorNr}/{value} + /laser/{value} + /ssid/{ssidname} + /pwd/{password} + /apmode/1 -> SofAP (default), 0 -> client + /saveconf -> write wificonfig to file + /resetwifi -> reconnect wifi with the new settings + /readwifi -> returns wifi settings + /readvalues -> return laser and motor values #install -- install arduino ide (1.8.5) +- install arduino ide (1.8.5) - follow this instruction https://github.com/esp8266/Arduino#installing-with-boards-manager diff --git a/esp8266-laser.ino b/esp8266-laser.ino index f59c4d4..ba7f5ec 100644 --- a/esp8266-laser.ino +++ b/esp8266-laser.ino @@ -20,6 +20,11 @@ int apMode = 1; // 0: client, 1: AP (default) // will be overwriten int apModeRuntime = 0; int wifiTimeout = 10000; //ms + +// [0] laser[1] m1 [2] m2 [3] m3 +byte lmValues[4] = {0,0,0,0}; + + /* Soft AP network parameters */ char *ssidAP = "laserAp"; IPAddress apIP(192, 168, 4, 1); // note: update metaRefreshStr string if ip change! @@ -114,7 +119,8 @@ void handleFileList() { void handleLaser(String uri) { String laserValue = uri.substring(7); - + lmValues[0] = laserValue.toInt(); + String msg = "AT SLV "; msg += laserValue; @@ -133,7 +139,8 @@ void handleMotor(String uri) { String motorNr = uri.substring(7, 8); String motorValue = uri.substring(9); - + lmValues[motorNr.toInt()] = motorValue.toInt(); + String msg = "AT SMS "; msg += motorNr; msg += " "; @@ -151,6 +158,27 @@ void handleMotor(String uri) json = String(); } +void handleReadValues() +{ + String json = "{ \"handledReadValues\":"; + json += "{\"laser\":\"" + (String)lmValues[0] + "\","; + json += "\"motors\": {\"1\":\"" + (String)lmValues[1] + "\","; + json += "\"2\":\"" + (String)lmValues[2] + "\","; + json += "\"3\":\"" + (String)lmValues[3] + "\"}}}"; + server.send(200, "text/json", json); + json = String(); +} + +void handleReadWifi() +{ + String json = "{ \"handledReadWifi\":"; + json += "{\"apMode\":\"" + (String)apMode + "\","; + json += "\"ssid\":\"" + (String)ssid + "\","; + json += "\"password\":\"***\"}}"; //(String)password + server.send(200, "text/json", json); + json = String(); +} + void handleSsid(String uri) { ssid = uri.substring(6); @@ -160,6 +188,7 @@ void handleSsid(String uri) server.send(200, "text/json", json); json = String(); } + void handlePwd(String uri) { password = uri.substring(5); @@ -328,6 +357,8 @@ void setup(void) { server.on("/listFiles", HTTP_GET, handleFileList); server.on("/saveconf", HTTP_GET, handleSaveConf); server.on("/resetwifi", HTTP_GET, setupWifi); + server.on("/readwifi", HTTP_GET, handleReadWifi); + server.on("/readvalues", HTTP_GET, handleReadValues); server.on("/heap", HTTP_GET, []() { String json = "{"; json += "\"heap\":" + String(ESP.getFreeHeap());