Hallo,
versuch bei meinem Webserver, siehe Link
[Ascii daten an ESP32 Webserver übergeben]
mit dem Manager zu erweitern.
Dies funktioniert auch ganz gut, aber leider nur beim ersten Aufruf um mein Netzwerk einzurichten.
Beim erneutem Aufruf mit der Taste #define TRIGGER_PIN 0 wie beim Beispiel Advanced beschrieben wurde komme ich nicht mehr auf die Seite zum Einstellen des Netwerk.
Das Netz des AP wird im Handy angezeigt und kann auch angewählt werden nur kann man
die Seite 192.168.4.1 nicht öffnen.
Wenn man nun mit der Taste die Einstellungen löscht, funktioiert alles wieder normal.
Hatte schon jemand solch ein Problem und eine Lösung dazu
Ohne deinem Sketch wird nix, der ist ja anders aufgebaut.
So hab nun den Sketch vom Link mit dem WiFi Manager erweitert.
Vieleicht hat ja jemand eine Lösung für mich.
#include "WiFi.h"
#include "WebServer.h"
#include "SPIFFS.h"
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#define TRIGGER_PIN 0
// wifimanager can run in a blocking mode or a non blocking mode
// Be sure to know how to process loops with no delay() if using non blocking
bool wm_nonblocking = false; // change to true to use non blocking
WiFiManager wm; // global wm instance
WiFiManagerParameter custom_field; // global param ( for non blocking w params )
//const char* ssid = "????"; // Network name.
//const char* password = "12345"; // Password network.
uint32_t altzeit;
uint32_t wert1, wert2, wert3, wert4, wert5;
char lcdData1[16] = {0x64, 0x69, 0x65, 0x73, 0x20, 0x69, 0x73, 0x74, 0x20, 0x65, 0x69, 0x6E, 0x20, 0x54 , 0x65, 0x78}; //Beispiel Daten "dies ist ein Text!"
byte ledpin1 = 23;
byte ledpin2 = 22;
byte ledpin3 = 19;
bool btnstate1; // Status des HTLM Butons
bool btnstate2;
bool btnstate3;
// Server Instanz erstellen
WebServer server(80);
void setup()
{
Serial.begin(115200);
#ifdef DEBUG
Serial.println("start Manager");
#endif
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
pinMode(TRIGGER_PIN, INPUT);
if(wm_nonblocking) wm.setConfigPortalBlocking(false);
// test custom html(radio)
const char* custom_radio_str = "<br/><label for='customfieldid'>Custom Field Label</label><input type='radio' name='customfieldid' value='1' checked> One<br><input type='radio' name='customfieldid' value='2'> Two<br><input type='radio' name='customfieldid' value='3'> Three";
new (&custom_field) WiFiManagerParameter(custom_radio_str); // custom html input
wm.addParameter(&custom_field);
wm.setSaveParamsCallback(saveParamCallback);
std::vector<const char *> menu = {"wifi","info","restart","exit"};
wm.setMenu(menu);
// set dark theme
wm.setClass("invert");
//set static ip
// wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // set static ip,gw,sn
// wm.setShowStaticFields(true); // force show static ip fields
// wm.setShowDnsFields(true); // force show dns field always
// wm.setConnectTimeout(20); // how long to try to connect for before continuing
wm.setConfigPortalTimeout(60); // auto close configportal after n seconds
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
if(!res) {
Serial.println("Failed to connect or hit timeout");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("Connected to ");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
SPIFFS.begin(); // Filesystem starten
// --Server Handle einrichten---
server.serveStatic("/", SPIFFS, "/index.html");
server.serveStatic("/style.css", SPIFFS, "/style.css", "text/css");
server.on("/daten", sendeDaten);
//server.onNotFound(handleNotFound); // Fehler bearbeiten
server.begin();
Serial.println("HTTP server started");
char lcdData1[16] = {0x64, 0x69, 0x65, 0x73, 0x20, 0x69, 0x73, 0x74, 0x20, 0x65, 0x69, 0x6E, 0x20, 0x54 , 0x65, 0x78};
}
void checkButton(){
// check for button press
if ( digitalRead(TRIGGER_PIN) == LOW ) {
// poor mans debounce/press-hold, code not ideal for production
delay(50);
if( digitalRead(TRIGGER_PIN) == LOW ){
Serial.println("Button Pressed");
// still holding button for 3000 ms, reset settings, code not ideaa for production
delay(3000); // reset delay hold
if( digitalRead(TRIGGER_PIN) == LOW ){
Serial.println("Button Held");
Serial.println("Erasing Config, restarting");
wm.resetSettings();
ESP.restart();
}
// start portal w delay
Serial.println("Starting config portal");
wm.setConfigPortalTimeout(120);
if (!wm.startConfigPortal("OnDemandAP","password")) {
Serial.println("failed to connect or hit timeout");
delay(3000);
// ESP.restart();
} else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
}
}
String getParam(String name){
//read parameter from server, for customhmtl input
String value;
if(wm.server->hasArg(name)) {
value = wm.server->arg(name);
}
return value;
}
void saveParamCallback(){
Serial.println("[CALLBACK] saveParamCallback fired");
Serial.println("PARAM customfieldid = " + getParam("customfieldid"));
}
void loop()
{
server.handleClient();// hier passiert sonst nichts
if(wm_nonblocking) wm.process(); // avoid delays() in loop when non-blocking and other long running code
checkButton();
//Beispiel m Werte auf Internetseite zu simulieren
if (millis() - altzeit >= 400) { // Messwerte simulieren 400ms
altzeit = millis();
wert1++;
if (wert1 > 2000)
{
wert1 = 0;
wert5++;
}
wert2 = millis() / 1000;
wert3 = 50.0 + random(10) / 5.0;
wert4 = (wert2 + wert1);
}
}
void Datenzeigen()
{
String message = "Daten angekommen\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
Serial.println(message);
}
void sendeDaten()
{
char sendbuffer[60];
// JSON String als Array anlegen ["20.0","572.6","24.0"]
// sprintf(sendbuffer, "[\"%4.1f\",\"%4.1f\",\"%4.1f\",\"%1u\",\"%1u\",\"%1u\"]",
// wert1, wert2, wert3, wert4, wert5);
sprintf(sendbuffer, "[\"%4d\",\"%4d\",\"%4d\",\"%4d\",\"%4d\",\"%16c\"]", //Formatierung mit sprintf
wert1, wert2, wert3, wert4, wert5, lcdData1);
server.send(200, "application/json", sendbuffer);
#ifdef DEBUG
Serial.print(sendbuffer);
Serial.println(strlen(sendbuffer));
#endif
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.