mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #1236] How to use push button interruupts with wifi manager #1058
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#1058
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 @vxplore on GitHub (Apr 3, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1236
I am successfully using wifi manager in esp 01 board.
But now i want to add a push button for extra functionaliry like reset, manual operation etc.
But could not figure out how to use both(wifimanager and push button).
My current code is following
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <EEPROM.h>
WiFiServer server(80);
String header;
int outputState = LOW;
const int outputPin = 2;
void setSavedState(int value)
{
outputState = value;
EEPROM.begin(4);
EEPROM.write(0, value?'1':'0');
EEPROM.write(1, 's');
EEPROM.write(2, 'e');
EEPROM.write(3, 't');
EEPROM.commit();
EEPROM.end();
}
int getSavedState()
{
EEPROM.begin(4);
if(
EEPROM.read(1)=='s'&&
EEPROM.read(2)=='e'&&
EEPROM.read(3)=='t'
)
{
return EEPROM.read(0)=='1'?HIGH:LOW;
}
else
{
return LOW;
}
EEPROM.end();
}
WiFiManager wifiManager;
void setup() {
outputState = getSavedState();
Serial.begin(115200);
pinMode(outputPin, OUTPUT);
digitalWrite(outputPin, outputState);
wifiManager.autoConnect("VXSS000000001");
Serial.println("Connected.");
server.begin();
}
String getStateText()
{
if(outputState==LOW)
{
return "off";
}
else
{
return "on";
}
}
bool erase_requested = false;
void loop(){
WiFiClient client = server.available();
if (client)
{
Serial.println("New Client.");
String currentLine = "";
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
header += c;
if (c == '\n')
{
if (currentLine.length() == 0)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
if (header.indexOf("GET /load/on") >= 0)
{
Serial.println("Load On");
setSavedState(HIGH);
digitalWrite(outputPin, outputState);
}
else if (header.indexOf("GET /load/off") >= 0)
{
Serial.println("Load Off");
setSavedState(LOW);
digitalWrite(outputPin, outputState);
}
else if (header.indexOf("GET /reset") >= 0)
{
Serial.println("Erasing");
erase_requested = true;
break;
}
client.println("<html>");
client.println("<head><meta name="viewport" content="width=device-width, initial-scale=1">");
client.println("<link rel="icon" href="data:,">");
client.println("</head>");
client.println("
VXSS000000001
");client.println("
Load - State " + getStateText() + "
");if (getStateText()=="off")
{
client.println("
<a href="/load/on"><button class="button">ON
");}
else
{
client.println("
<a href="/load/off"><button class="button button2">OFF
");}
}
if(erase_requested)
{
erase_requested = false;
wifiManager.resetSettings();
Serial.println("Erased");
delay(100);
wifiManager.disconnect();
Serial.println("Disconnected");
delay(100);
ESP.restart();
delay(1000);
}
}
So what will be the solution
@EgHubs commented on GitHub (Apr 4, 2021):
Will, a push-button requires an input pin to read its state, not an output pin,
if outputPin is the pin you are going to request a reset with then you should assign it as a digital input pin then use digitalRead to read its value.
I would recommend that you use this example and justify it for your needs.
@EgHubs commented on GitHub (Apr 4, 2021):
Here is the code for you, connect the TRIGGER_PIN to the ground through a push-button.
if you want to do a reset then click on the button for a second.
@tablatronix commented on GitHub (Apr 4, 2021):
Since wm is blocking you will want to use the new non blocking it will be easier
@audiofill42 commented on GitHub (May 31, 2021):
Hello,
I am having same situation with the Wifi Manager.
I am trying to create a project based on ESP8266 & Blynk to use a button and relay to command something.
I would like to have implemented the function of On demand using the reet button if possible or the project button (D0).
Did you solded your problem?
And if Yes, how? Can you share to me the result/solution?
Thanks in advance.