diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index fd381e3dc0e665149daa9be43d7541a002518c5e..b464ddd133b30b06faa4f2d0ac4e47af689e0ab5 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -2,7 +2,7 @@ * Example: Shell commands * Description: * This example is a modified IotWebConf01Minimal.ino, with added shell commands. - * + * * Simply type "help" via Serial in order to see the available commands: > help @@ -17,31 +17,51 @@ wifi 0/1 (Enables/disables WiFi). wifi_pwd abc (Sets WiFi password to abc). - * The commands allow you to setup the thing directly via Serial: + * The commands allow you to setup the thing directly via Serial, + * without the need to type long passwords on a smartphone. + * + * You can copy-paste multiple commands at once, separated by a newline. + * They will be executed one after the other. > name my_thing Calling : name('my_thing') Setting Thing name to my_thing - > ssid my_wifi - Calling : ssid('my_wifi') - Setting WiFi ssid to my_wifi - > wifi_pwd my_wifi_password Calling : wifi_pwd('my_wifi_password') Setting WiFi password to my_wifi_password + > ssid my_wifi + Calling : ssid('my_wifi') + Setting WiFi ssid to my_wifi + > ap_pwd p4ssw0rd Calling : ap_pwd('p4ssw0rd') Setting AP password to p4ssw0rd - State changing from: 1 to 3 + > save_config + Calling : save_config() + + Config version: init + Config size: 165 + Saving configuration + [iwcAll] + |-- [iwcSys] + | |-- 'iwcThingName' with value: 'my_thing' + | |-- 'iwcApPassword' with value: <hidden> + | |-- [iwcWifi0] + | | |-- 'iwcWifiSsid' with value: 'my_wifi' + | | \-- 'iwcWifiPassword' with value: <hidden> + | \-- 'iwcApTimeout' with value: '30' + |-- [iwcCustom] + \-- [hidden] + + State changing from: 2 to 3 Connecting to [my_wifi] (password is hidden) WiFi timeout (ms): 30000 - State changed from: 1 to 3 ... ... - * + * */ #include <IotWebConf.h> @@ -60,9 +80,11 @@ WebServer server(80); IotWebConf iotWebConf(thingName, &dnsServer, &server, wifiInitialApPassword); -/*** - * Shell interface. Could be moved to shell.h - */ +/***************************************************************************** + * Shell interface. + * + * (Could be moved to shell.h) + ****************************************************************************/ namespace shell { void defineCommand(const char *name, void (*function)(), const __FlashStringHelper *doc_fstring); void defineIntCommand(const char *name, void (*function)(int32_t), const __FlashStringHelper *doc_fstring); @@ -130,6 +152,9 @@ void wifiOnOff(int onOff){ /***************************************************************************** * Define shell commands with name, function and documentation. * The commands accept either 0 argument, one string or one integer. + * + * Feel free to add other commands, e.g. to set custom parameters. + * The second argument can be either a function name or a lambda. ****************************************************************************/ void defineShellCommands() { @@ -146,14 +171,16 @@ void defineShellCommands() { shell::defineIntCommand("wifi", wifiOnOff, F("0/1 (Enables/disables WiFi)")); } -void setup() +/***************************************************************************** + * Arduino sketch + ****************************************************************************/ + +void setup() { Serial.begin(115200); Serial.println(); Serial.println("Starting up..."); -// iotWebConf.getApTimeoutParameter()->defaultValue = "600"; - // -- Initializing the configuration. iotWebConf.init(); @@ -164,10 +191,10 @@ void setup() defineShellCommands(); - Serial.println("Ready."); + Serial.println(F("Ready.")); } -void loop() +void loop() { iotWebConf.doLoop(); shell::checkSerialInput(); @@ -192,9 +219,11 @@ void handleRoot() server.send(200, "text/html", s); } -/*** - * Shell logic. Could be moved to shell.cpp - */ +/***************************************************************************** + * Shell logic. + * + * (Could be moved to shell.cpp) + ****************************************************************************/ namespace shell { const uint8_t MAX_COMMANDS = 10;