From a234eba8fe289411e14ee70bd59dc862b41aa23c Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Wed, 29 Jun 2022 23:46:06 +0200 Subject: [PATCH 1/4] added static parse argument into quotes. --- SerialTerminal.hpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/SerialTerminal.hpp b/SerialTerminal.hpp index 833e17e..36b71fe 100644 --- a/SerialTerminal.hpp +++ b/SerialTerminal.hpp @@ -57,7 +57,7 @@ namespace maschinendeck { class SerialTerminal { private: - Command* commands[64]; + Command* commands[256]; uint8_t size_; bool firstRun; String message; @@ -183,6 +183,26 @@ namespace maschinendeck { return Pair(keyword, message); } + + static String ParseArgument(String message) { + String keyword = ""; + for (auto& car : message) { + if (car == '"') + break; + keyword += car; + } + if (keyword != "") + message.remove(0, keyword.length()); + keyword.trim(); + message.trim(); + int msg_len = message.length(); + if (msg_len > 0) { + message.remove(0,1); + message.remove(msg_len-2); + } + + return message; + } }; } From ea6b8886d189d11161ee383925ce5a1a36db0e61 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 30 Jun 2022 00:25:47 +0200 Subject: [PATCH 2/4] added new example using the new quotes argument parser --- examples/wifi_setup/wifi_setup.ino | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 examples/wifi_setup/wifi_setup.ino diff --git a/examples/wifi_setup/wifi_setup.ino b/examples/wifi_setup/wifi_setup.ino new file mode 100644 index 0000000..9a5b57a --- /dev/null +++ b/examples/wifi_setup/wifi_setup.ino @@ -0,0 +1,80 @@ + +/********************************************************************* + This sample file is part of the Serial Terminal Library: + Copyright (c) 2022, @hpsaturn, Antonio Vanegas + https://hpsaturn.com, All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + *********************************************************************/ + +#include +#include +#include "WiFi.h" + +maschinendeck::SerialTerminal* term; + +String ssid; +String pasw; + +void printWifiSettings() { + Serial.print("\nWiFi Connect To : "); + Serial.println(WiFi.SSID()); //Output Network name. + Serial.print("IP address \t: "); + Serial.println(WiFi.localIP()); //Output IP Address. + Serial.print("RSSI\t\t: "); + Serial.println(WiFi.RSSI()); //Output signal strength. +} + +void printHelp(String opts) { + Serial.println("\nUsage:\n"); + Serial.println("setSSID \"YOUR SSID\""); + Serial.println("setPassword \"YOUR PASSWORD\""); + Serial.println("connect"); +} + +void setSSID(String opts) { + ssid = maschinendeck::SerialTerminal::ParseArgument(opts); + Serial.println("\n\tsaved ssid to \t: " + ssid); +} + +void setPassword(String opts) { + pasw = maschinendeck::SerialTerminal::ParseArgument(opts); + Serial.println("\n\tsaved password to \t: " + pasw); +} + +void connect(String opts) { + WiFi.begin(ssid.c_str(), pasw.c_str()); + while (WiFi.status() != WL_CONNECTED) { // M5Atom will connect automatically + delay(500); + Serial.print("."); + } + M5.dis.fillpix(0x00ff00); // set LED to green + printWifiSettings(); +} + +void setup() { + M5.begin(true,false,true); //Init Atom(Initialize serial port, LED) + M5.dis.fillpix(0xfff000); //Light LED with the specified RGB color. + delay(1000); + Serial.flush(); + Serial.println("\n\n"); + term = new maschinendeck::SerialTerminal(115200); + term->add("help", &printHelp, "\tshow help and usage information"); + term->add("setSSID", &setSSID, "\tset the Wifi SSID"); + term->add("setPassword", &setPassword, "set the Wifi password"); + term->add("connect", &connect, "\tconnect to the wifi station"); +} + +void loop() { + term->loop(); +} \ No newline at end of file From 89a7ecbcb001d1a3c7d39b3f20438d8e4b69121f Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 30 Jun 2022 00:48:47 +0200 Subject: [PATCH 3/4] updated license header --- examples/wifi_setup/wifi_setup.ino | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/wifi_setup/wifi_setup.ino b/examples/wifi_setup/wifi_setup.ino index 9a5b57a..194a59f 100644 --- a/examples/wifi_setup/wifi_setup.ino +++ b/examples/wifi_setup/wifi_setup.ino @@ -1,6 +1,9 @@ /********************************************************************* - This sample file is part of the Serial Terminal Library: + This sample file is part of the Serial Terminal Library + esp32-wifi-cli implementation: + https://github.com/hpsaturn/esp32-wifi-cli + Copyright (c) 2022, @hpsaturn, Antonio Vanegas https://hpsaturn.com, All rights reserved. @@ -77,4 +80,4 @@ void setup() { void loop() { term->loop(); -} \ No newline at end of file +} From 8b9ff4164ec26d190793fb7ffdaa09cd5e0712f4 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 30 Jun 2022 16:18:47 +0200 Subject: [PATCH 4/4] removed unnecesary trim on local variable --- SerialTerminal.hpp | 1 - examples/wifi_setup/wifi_setup.ino | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/SerialTerminal.hpp b/SerialTerminal.hpp index 36b71fe..677f199 100644 --- a/SerialTerminal.hpp +++ b/SerialTerminal.hpp @@ -193,7 +193,6 @@ namespace maschinendeck { } if (keyword != "") message.remove(0, keyword.length()); - keyword.trim(); message.trim(); int msg_len = message.length(); if (msg_len > 0) { diff --git a/examples/wifi_setup/wifi_setup.ino b/examples/wifi_setup/wifi_setup.ino index 194a59f..f3037bf 100644 --- a/examples/wifi_setup/wifi_setup.ino +++ b/examples/wifi_setup/wifi_setup.ino @@ -1,7 +1,7 @@ /********************************************************************* - This sample file is part of the Serial Terminal Library - esp32-wifi-cli implementation: + This sample file is part of the esp32-wifi-cli + Source code: https://github.com/hpsaturn/esp32-wifi-cli Copyright (c) 2022, @hpsaturn, Antonio Vanegas