Commit 8ba21e5a authored by Eric Duminil's avatar Eric Duminil
Browse files

Some more doc

parent 53398ba9
Pipeline #5996 failed with stage
in 20 seconds
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Example: Shell commands * Example: Shell commands
* Description: * Description:
* This example is a modified IotWebConf01Minimal.ino, with added shell commands. * This example is a modified IotWebConf01Minimal.ino, with added shell commands.
* *
* Simply type "help" via Serial in order to see the available commands: * Simply type "help" via Serial in order to see the available commands:
> help > help
...@@ -17,31 +17,51 @@ ...@@ -17,31 +17,51 @@
wifi 0/1 (Enables/disables WiFi). wifi 0/1 (Enables/disables WiFi).
wifi_pwd abc (Sets WiFi password to abc). 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 > name my_thing
Calling : name('my_thing') Calling : name('my_thing')
Setting Thing name to 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 > wifi_pwd my_wifi_password
Calling : wifi_pwd('my_wifi_password') Calling : wifi_pwd('my_wifi_password')
Setting WiFi password to 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 > ap_pwd p4ssw0rd
Calling : ap_pwd('p4ssw0rd') Calling : ap_pwd('p4ssw0rd')
Setting AP password to 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) Connecting to [my_wifi] (password is hidden)
WiFi timeout (ms): 30000 WiFi timeout (ms): 30000
State changed from: 1 to 3
... ...
... ...
* *
*/ */
#include <IotWebConf.h> #include <IotWebConf.h>
...@@ -60,9 +80,11 @@ WebServer server(80); ...@@ -60,9 +80,11 @@ WebServer server(80);
IotWebConf iotWebConf(thingName, &dnsServer, &server, wifiInitialApPassword); IotWebConf iotWebConf(thingName, &dnsServer, &server, wifiInitialApPassword);
/*** /*****************************************************************************
* Shell interface. Could be moved to shell.h * Shell interface.
*/ *
* (Could be moved to shell.h)
****************************************************************************/
namespace shell { namespace shell {
void defineCommand(const char *name, void (*function)(), const __FlashStringHelper *doc_fstring); void defineCommand(const char *name, void (*function)(), const __FlashStringHelper *doc_fstring);
void defineIntCommand(const char *name, void (*function)(int32_t), 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){ ...@@ -130,6 +152,9 @@ void wifiOnOff(int onOff){
/***************************************************************************** /*****************************************************************************
* Define shell commands with name, function and documentation. * Define shell commands with name, function and documentation.
* The commands accept either 0 argument, one string or one integer. * 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() { void defineShellCommands() {
...@@ -146,14 +171,16 @@ void defineShellCommands() { ...@@ -146,14 +171,16 @@ void defineShellCommands() {
shell::defineIntCommand("wifi", wifiOnOff, F("0/1 (Enables/disables WiFi)")); shell::defineIntCommand("wifi", wifiOnOff, F("0/1 (Enables/disables WiFi)"));
} }
void setup() /*****************************************************************************
* Arduino sketch
****************************************************************************/
void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
Serial.println(); Serial.println();
Serial.println("Starting up..."); Serial.println("Starting up...");
// iotWebConf.getApTimeoutParameter()->defaultValue = "600";
// -- Initializing the configuration. // -- Initializing the configuration.
iotWebConf.init(); iotWebConf.init();
...@@ -164,10 +191,10 @@ void setup() ...@@ -164,10 +191,10 @@ void setup()
defineShellCommands(); defineShellCommands();
Serial.println("Ready."); Serial.println(F("Ready."));
} }
void loop() void loop()
{ {
iotWebConf.doLoop(); iotWebConf.doLoop();
shell::checkSerialInput(); shell::checkSerialInput();
...@@ -192,9 +219,11 @@ void handleRoot() ...@@ -192,9 +219,11 @@ void handleRoot()
server.send(200, "text/html", s); server.send(200, "text/html", s);
} }
/*** /*****************************************************************************
* Shell logic. Could be moved to shell.cpp * Shell logic.
*/ *
* (Could be moved to shell.cpp)
****************************************************************************/
namespace shell { namespace shell {
const uint8_t MAX_COMMANDS = 10; const uint8_t MAX_COMMANDS = 10;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment