mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-26 16:45:55 +03:00
[GH-ISSUE #1632] *wm:[ERROR] parameter IDs can only contain alpha numeric chars #1391
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#1391
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @woodenplastic on GitHub (Jul 5, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1632
Hi, im not a programmer and im just triyin to use the wifi manager. The additional definitions for ethernet is for the specific board. Error messages are with and without the ethernet part.
Hardware
WiFimanager Branch/Release: 2.0.16-rc.2
ESP32 OLIMEX ESP32-PoE-ISO
Description
*wm:[ERROR] parameter IDs can only contain alpha numeric chars
Sketch
// DEFINITION ETHERNET
////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 12
#include <ETH.h>
static bool eth_connected = false;
// DEFINITION WIFI MANAGER
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ESP_DRD_USE_SPIFFS true
#include <WiFi.h>
#include <FS.h>
#include <SPIFFS.h>
#include <WiFiManager.h>
#include <ESP_DoubleResetDetector.h>
#include <ArduinoJson.h>
const int PIN_LED = 32;
#define JSON_CONFIG_FILE "/stompcs_config.json"
// Number of seconds after reset during which a
// subseqent reset will be considered a double reset.
#define DRD_TIMEOUT 10
// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0
DoubleResetDetector* drd;
//flag for saving data
bool shouldSaveConfig = false;
char stringbutton1[50] = "Enter OSC Message for Button 1 here";
char stringbutton2[50] = "Enter OSC Message for Button 2 here";
char stringbutton3[50] = "Enter OSC Message for Button 3 here";
char stringbutton4[50] = "Enter OSC Message for Button 4 here";
int testNumber = 1500;
bool testBool = true;
int mode = 0; // 0 == Monmode etc
char* modesofconnection[] = { "Ethernet", "WIFI", "Bluetooth" };
void saveConfigFile() {
Serial.println(F("Saving config"));
StaticJsonDocument<512> json;
json["stringone"] = stringbutton1;
json["stringtwo"] = stringbutton2;
json["stringthree"] = stringbutton3;
json["stringfour"] = stringbutton4;
json["testNumber"] = testNumber;
json["testBool"] = testBool;
json["mode"] = mode;
File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w");
if (!configFile) {
Serial.println("failed to open config file for writing");
}
serializeJsonPretty(json, Serial);
if (serializeJson(json, configFile) == 0) {
Serial.println(F("Failed to write to file"));
}
configFile.close();
}
bool loadConfigFile() {
//clean FS, for testing
// SPIFFS.format();
//read configuration from FS json
Serial.println("mounting FS...");
// May need to make it begin(true) first time you are using SPIFFS
// NOTE: This might not be a good way to do this! begin(true) reformats the spiffs
// it will only get called if it fails to mount, which probably means it needs to be
// formatted, but maybe dont use this if you have something important saved on spiffs
// that can't be replaced.
if (SPIFFS.begin(false) || SPIFFS.begin(true)) {
Serial.println("mounted file system");
if (SPIFFS.exists(JSON_CONFIG_FILE)) {
//file exists, reading and loading
Serial.println("reading config file");
File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r");
if (configFile) {
Serial.println("opened config file");
StaticJsonDocument<512> json;
DeserializationError error = deserializeJson(json, configFile);
serializeJsonPretty(json, Serial);
if (!error) {
Serial.println("\nparsed json");
} else {
Serial.println("failed to mount FS");
}
//end read
return false;
}
//callback notifying us of the need to save config
void saveConfigCallback() {
Serial.println("Should save config");
shouldSaveConfig = true;
}
// This gets called when the config mode is launced, might
// be useful to update a display with this info.
void configModeCallback(WiFiManager* myWiFiManager) {
Serial.println("Entered Conf Mode");
Serial.print("Config SSID: ");
Serial.println(myWiFiManager->getConfigPortalSSID());
Serial.print("Config IP Address: ");
Serial.println(WiFi.softAPIP());
}
void WiFiEvent(WiFiEvent_t event) {
switch (event) {
case SYSTEM_EVENT_ETH_START:
Serial.println("ETH Started");
//set eth hostname here
ETH.setHostname("stompcs_lan");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.print("ETH MAC: ");
Serial.print(ETH.macAddress());
Serial.print(", IPv4: ");
Serial.print(ETH.localIP());
if (ETH.fullDuplex()) {
Serial.print(", FULL_DUPLEX");
}
Serial.print(", ");
Serial.print(ETH.linkSpeed());
Serial.println("Mbps");
eth_connected = true;
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case SYSTEM_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void testClient(const char* host, uint16_t port) {
Serial.print("\nconnecting to ");
Serial.println(host);
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available())
;
while (client.available()) {
Serial.write(client.read());
}
Serial.println("closing connection\n");
client.stop();
}
void setup() {
Serial.begin(115200); // Start Serial Monitor
WiFi.onEvent(WiFiEvent); // Start WIFI Manager
ETH.begin(); // Start Ethernet
pinMode(PIN_LED, OUTPUT);
bool forceConfig = false;
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
if (drd->detectDoubleReset()) {
Serial.println(F("Forcing config mode as there was a Double reset detected"));
forceConfig = true;
}
bool spiffsSetup = loadConfigFile();
if (!spiffsSetup) {
Serial.println(F("Forcing config mode as there is no saved config"));
forceConfig = true;
}
//WiFi.disconnect();
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
delay(10);
// wm.resetSettings(); // wipe settings
WiFiManager wm;
//wm.resetSettings(); // wipe settings
//set config save notify callback
wm.setSaveConfigCallback(saveConfigCallback);
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wm.setAPCallback(configModeCallback);
//--- additional Configs params ---
// Text box (String)
WiFiManagerParameter customtextbox1("Button 1", "Button 1", stringbutton1, 50); // 50 == max length
WiFiManagerParameter customtextbox2("Button 2", "Button 2", stringbutton2, 50); // 50 == max length
WiFiManagerParameter customtextbox3("Button 3", "Button 3", stringbutton3, 50); // 50 == max length
WiFiManagerParameter customtextbox4("Button 4", "Button 4", stringbutton4, 50); // 50 == max length
// Text box (Number)
char convertedValue[6];
sprintf(convertedValue, "%d", testNumber); // Need to convert to string to display a default value.
WiFiManagerParameter customnum("key_num", "Enter your number here", convertedValue, 7); // 7 == max length
//Check Box
char* customHtml;
if (testBool) {
customHtml = "type="checkbox" checked";
} else {
customHtml = "type="checkbox"";
}
WiFiManagerParameter customcheckbox("key_bool", "Checkbox", "T", 2, customHtml); // The "t" isn't really important, but if the
// box is checked the value for this field will
// be "t", so we can check for that.
//Select menu (custom HTML)
// The custom html options do not get handled the same way as other standard ones
// but im using some javascript trickery here to save the output of the drop down
// into a standard WM field that im hiding
// Not sure if it's better or worse than the standard way
const char* mode_select_str = R"(
Ethernet WIFI Bluetooth
)";
char bufferStr[700];
// The sprintf is so we can input the value of the current selected mode
// If you dont need to do that, then just pass the const char* straight in.
sprintf(bufferStr, mode_select_str, mode);
Serial.print(bufferStr);
WiFiManagerParameter customfield(bufferStr);
sprintf(convertedValue, "%d", mode); // Need to convert to string to store a default value.
WiFiManagerParameter customhidden("key_custom", "Will be hidden", convertedValue, 2);
//add all your parameters here
wm.addParameter(&customtextbox1);
wm.addParameter(&customtextbox2);
wm.addParameter(&customtextbox3);
wm.addParameter(&customtextbox4);
wm.addParameter(&customnum);
wm.addParameter(&customcheckbox);
wm.addParameter(&customhidden);
wm.addParameter(&customfield);
Serial.println("hello");
digitalWrite(PIN_LED, LOW);
if (forceConfig) {
if (!wm.startConfigPortal("STOMPCS", "administrator")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(5000);
}
} else {
if (!wm.autoConnect("STOMPCS", "administrator")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
// if we still have not connected restart and try all over again
ESP.restart();
delay(5000);
}
}
// If we get here, we are connected to the WiFi
digitalWrite(PIN_LED, HIGH);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Lets deal with the user config values
// Copy the string value
strncpy(stringbutton1, customtextbox1.getValue(), sizeof(stringbutton1));
Serial.print("stringbutton1: ");
Serial.println(stringbutton1);
strncpy(stringbutton2, customtextbox2.getValue(), sizeof(stringbutton2));
Serial.print("StringButton2: ");
Serial.println(stringbutton2);
strncpy(stringbutton3, customtextbox3.getValue(), sizeof(stringbutton3));
Serial.print("StringButton3: ");
Serial.println(stringbutton3);
strncpy(stringbutton4, customtextbox4.getValue(), sizeof(stringbutton4));
Serial.print("StringButton4: ");
Serial.println(stringbutton4);
//Convert the number value
testNumber = atoi(customnum.getValue());
Serial.print("testNumber: ");
Serial.println(testNumber);
//Handle the bool value
testBool = (strncmp(customcheckbox.getValue(), "T", 1) == 0);
Serial.print("testBool: ");
if (testBool) {
Serial.println("true");
} else {
Serial.println("false");
}
//The custom one
mode = atoi(customhidden.getValue());
Serial.print("Selected mode: ");
Serial.println(modesofconnection[mode]);
//save the custom parameters to FS
if (shouldSaveConfig) {
saveConfigFile();
}
}
void loop() {
drd->loop();
}
#END
SERIAL MONITOR MESSAGES: