Commit 00750138 authored by Eric Duminil's avatar Eric Duminil
Browse files

Defining ssid and password via console

parent ac8ed954
Pipeline #5865 passed with stage
in 2 minutes and 18 seconds
#include "sensor_console.h" #include "sensor_console.h"
namespace sensor_console { namespace sensor_console {
const uint8_t MAX_COMMANDS = 25; const uint8_t MAX_COMMANDS = 26;
const uint8_t MAX_COMMAND_SIZE = 20; // Should be enough for "set_time 1618829570\n" const uint8_t MAX_COMMAND_SIZE = 20; // Should be enough for "set_time 1618829570\n"
uint8_t commands_count = 0; uint8_t commands_count = 0;
......
...@@ -164,10 +164,7 @@ namespace web_config { ...@@ -164,10 +164,7 @@ namespace web_config {
iotWebConf->setWifiConnectionFailedHandler(fail_and_return_null); iotWebConf->setWifiConnectionFailedHandler(fail_and_return_null);
} }
void initialize() { void defineStructure() {
iotWebConf = new IotWebConf(strlen(AMPEL_NAME) == 0 ? ampel.sensorId : AMPEL_NAME, &dnsServer, &http, "",
config_version);
iotWebConf->setHtmlFormatProvider(&optionalGroupHtmlFormatProvider); iotWebConf->setHtmlFormatProvider(&optionalGroupHtmlFormatProvider);
iotWebConf->addSystemParameter(&ampelWifiParam); iotWebConf->addSystemParameter(&ampelWifiParam);
...@@ -219,10 +216,9 @@ namespace web_config { ...@@ -219,10 +216,9 @@ namespace web_config {
#if defined(ESP32) #if defined(ESP32)
iotWebConf->addParameterGroup(&loraParams); iotWebConf->addParameterGroup(&loraParams);
#endif #endif
}
//TODO: Add "ap" command? void defineCommands() {
//TODO: Add "wifi_ssid" command?
//TODO: Add "wifi_password" command?
sensor_console::defineCommand("save_config", config::save, F("(Saves the config to EEPROM)")); sensor_console::defineCommand("save_config", config::save, F("(Saves the config to EEPROM)"));
sensor_console::defineCommand("reset_config", []() { sensor_console::defineCommand("reset_config", []() {
...@@ -232,12 +228,35 @@ namespace web_config { ...@@ -232,12 +228,35 @@ namespace web_config {
Serial.println(F("Done!")); Serial.println(F("Done!"));
}, F("(Resets the complete IotWeb config)")); }, F("(Resets the complete IotWeb config)"));
sensor_console::defineStringCommand("ssid", [](char *ssid) {
Serial.print(F("Setting WiFi ssid to "));
Serial.println(ssid);
strncpy(iotWebConf->getWifiSsidParameter()->valueBuffer, ssid, iotWebConf->getWifiSsidParameter()->getLength());
iotWebConf->saveConfig();
}, F(" name (Sets SSID to name)"));
sensor_console::defineStringCommand("pwd", [](char *ssid) {
Serial.print(F("Setting WiFi password to "));
Serial.println(ssid);
strncpy(iotWebConf->getWifiPasswordParameter()->valueBuffer, ssid, iotWebConf->getWifiPasswordParameter()->getLength());
iotWebConf->saveConfig();
}, F(" abc (Sets WiFi password to abc)"));
sensor_console::defineIntCommand("wifi", [](int32_t onOff) { sensor_console::defineIntCommand("wifi", [](int32_t onOff) {
config::is_wifi_on = onOff; config::is_wifi_on = onOff;
iotWebConf->saveConfig(); iotWebConf->saveConfig();
Serial.print(F("WiFi - ")); Serial.print(F("WiFi - "));
Serial.println(onOff ? F("On!") : F("Off!")); Serial.println(onOff ? F("On!") : F("Off!"));
}, F("0/1 (Turns Wifi on/off)")); }, F("0/1 (Turns Wifi on/off)"));
}
void initialize() {
iotWebConf = new IotWebConf(strlen(AMPEL_NAME) == 0 ? ampel.sensorId : AMPEL_NAME, &dnsServer, &http, "",
config_version);
defineStructure();
defineCommands();
iotWebConf->loadConfig(); iotWebConf->loadConfig();
...@@ -246,6 +265,12 @@ namespace web_config { ...@@ -246,6 +265,12 @@ namespace web_config {
return; return;
} }
//NOTE: Can only work if wifi is on.
sensor_console::defineCommand("ap!", []() {
Serial.println(F("Forcing AP mode!"));
iotWebConf->forceApMode(true);
}, F("(Forces access point mode)"));
const int ONBOARD_LED_PIN = 2; const int ONBOARD_LED_PIN = 2;
# ifdef ESP8266 # ifdef ESP8266
iotWebConf->setStatusPin(ONBOARD_LED_PIN, LOW); iotWebConf->setStatusPin(ONBOARD_LED_PIN, LOW);
......
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