mirror of
https://github.com/0x1d/esp8266-laser.git
synced 2025-12-16 10:44:30 +01:00
added /readwifi and /readvalues
changed holding values in ram after sending to laserspiro
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
|||||||
/data-dev/maincontrols.txt
|
|
||||||
|
|||||||
18
README.md
18
README.md
@@ -2,16 +2,18 @@
|
|||||||
Wifi Host for the Arduino-Laser-Spirograph
|
Wifi Host for the Arduino-Laser-Spirograph
|
||||||
|
|
||||||
#usage:
|
#usage:
|
||||||
/motor/{motorNr}/{value}
|
/motor/{motorNr}/{value}
|
||||||
/laser/{value}
|
/laser/{value}
|
||||||
/ssid/{ssidname}
|
/ssid/{ssidname}
|
||||||
/pwd/{password}
|
/pwd/{password}
|
||||||
/apmode/1 -> SofAP (default), 0 -> client
|
/apmode/1 -> SofAP (default), 0 -> client
|
||||||
/saveconf -> write wificonfig to file
|
/saveconf -> write wificonfig to file
|
||||||
/resetwifi -> reconnect wifi with the new settings (this will work)
|
/resetwifi -> reconnect wifi with the new settings
|
||||||
|
/readwifi -> returns wifi settings
|
||||||
|
/readvalues -> return laser and motor values
|
||||||
|
|
||||||
#install
|
#install
|
||||||
- install arduino ide (1.8.5)
|
- install arduino ide (1.8.5)
|
||||||
|
|
||||||
- follow this instruction
|
- follow this instruction
|
||||||
https://github.com/esp8266/Arduino#installing-with-boards-manager
|
https://github.com/esp8266/Arduino#installing-with-boards-manager
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ int apMode = 1; // 0: client, 1: AP (default) // will be overwriten
|
|||||||
int apModeRuntime = 0;
|
int apModeRuntime = 0;
|
||||||
int wifiTimeout = 10000; //ms
|
int wifiTimeout = 10000; //ms
|
||||||
|
|
||||||
|
|
||||||
|
// [0] laser[1] m1 [2] m2 [3] m3
|
||||||
|
byte lmValues[4] = {0,0,0,0};
|
||||||
|
|
||||||
|
|
||||||
/* Soft AP network parameters */
|
/* Soft AP network parameters */
|
||||||
char *ssidAP = "laserAp";
|
char *ssidAP = "laserAp";
|
||||||
IPAddress apIP(192, 168, 4, 1); // note: update metaRefreshStr string if ip change!
|
IPAddress apIP(192, 168, 4, 1); // note: update metaRefreshStr string if ip change!
|
||||||
@@ -114,7 +119,8 @@ void handleFileList() {
|
|||||||
void handleLaser(String uri)
|
void handleLaser(String uri)
|
||||||
{
|
{
|
||||||
String laserValue = uri.substring(7);
|
String laserValue = uri.substring(7);
|
||||||
|
lmValues[0] = laserValue.toInt();
|
||||||
|
|
||||||
String msg = "AT SLV ";
|
String msg = "AT SLV ";
|
||||||
msg += laserValue;
|
msg += laserValue;
|
||||||
|
|
||||||
@@ -133,7 +139,8 @@ void handleMotor(String uri)
|
|||||||
{
|
{
|
||||||
String motorNr = uri.substring(7, 8);
|
String motorNr = uri.substring(7, 8);
|
||||||
String motorValue = uri.substring(9);
|
String motorValue = uri.substring(9);
|
||||||
|
lmValues[motorNr.toInt()] = motorValue.toInt();
|
||||||
|
|
||||||
String msg = "AT SMS ";
|
String msg = "AT SMS ";
|
||||||
msg += motorNr;
|
msg += motorNr;
|
||||||
msg += " ";
|
msg += " ";
|
||||||
@@ -151,6 +158,27 @@ void handleMotor(String uri)
|
|||||||
json = String();
|
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)
|
void handleSsid(String uri)
|
||||||
{
|
{
|
||||||
ssid = uri.substring(6);
|
ssid = uri.substring(6);
|
||||||
@@ -160,6 +188,7 @@ void handleSsid(String uri)
|
|||||||
server.send(200, "text/json", json);
|
server.send(200, "text/json", json);
|
||||||
json = String();
|
json = String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handlePwd(String uri)
|
void handlePwd(String uri)
|
||||||
{
|
{
|
||||||
password = uri.substring(5);
|
password = uri.substring(5);
|
||||||
@@ -328,6 +357,8 @@ void setup(void) {
|
|||||||
server.on("/listFiles", HTTP_GET, handleFileList);
|
server.on("/listFiles", HTTP_GET, handleFileList);
|
||||||
server.on("/saveconf", HTTP_GET, handleSaveConf);
|
server.on("/saveconf", HTTP_GET, handleSaveConf);
|
||||||
server.on("/resetwifi", HTTP_GET, setupWifi);
|
server.on("/resetwifi", HTTP_GET, setupWifi);
|
||||||
|
server.on("/readwifi", HTTP_GET, handleReadWifi);
|
||||||
|
server.on("/readvalues", HTTP_GET, handleReadValues);
|
||||||
server.on("/heap", HTTP_GET, []() {
|
server.on("/heap", HTTP_GET, []() {
|
||||||
String json = "{";
|
String json = "{";
|
||||||
json += "\"heap\":" + String(ESP.getFreeHeap());
|
json += "\"heap\":" + String(ESP.getFreeHeap());
|
||||||
|
|||||||
Reference in New Issue
Block a user