let gpio2 be input control button

superme55557
Posts: 1
Joined: Mon Apr 17, 2017 4:01 pm

let gpio2 be input control button

Postby superme55557 » Fri Apr 21, 2017 5:07 pm

i'm using esp8266 E-01, i let gpio2 to be a input get button's status
it's will work but without long press
when long press the button it will come out like this
is there any suggest for me or how to avoid it ran out to be ,thanks all
========================================================
Soft WDT reset

ctx: cont
sp: 3ffef380 end: 3ffef590 offset: 01b0

>>>stack>>>
3ffef530: 3fffdad0 00000000 3ffee53c 40201e20
3ffef540: 3ffe84f0 00000000 000003e8 40202af6
3ffef550: 3ffee410 3fff04c4 00000000 402010a3
3ffef560: 00000000 00000000 00000001 40203499
3ffef570: 3fffdad0 00000000 3ffee560 402034c4
3ffef580: feefeffe feefeffe 3ffee570 40100718
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(1,6)
========================================================


it's for bootloader
usb->ttL esp8266
********************************************
TX -> RX
RX -> TX
VCC -> VCC , CH_PD
GND -> GND, gpio0
*********************************************
it's for work

********************************************
TX -> RX
RX -> TX
VCC -> VCC , CH_PD
GND -> GND






Code: Select all

#include<WiFiClient.h>
#include<ESP8266WiFi.h>
const char* ssid = "";
const char* pass = "";
char thisChar = 0;
unsigned long int timer = 0;
boolean alreadyConnected = false;
WiFiServer Server(8087);
WiFiClient client;
void setup()
{
  pinMode(0,OUTPUT);
  digitalWrite(0,LOW);
  pinMode(2,INPUT);
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  Serial.println("Connecting");
  // wifi connecting
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(500);
  }
  printout();
 
  Server.begin();
}

void loop() {
  //wait for new client
  WiFiClient client = Server.available();
  if (!client) {
    return ;
  }
  Serial.println("Client connected");
  client.println("connected");
  while (client.connected()) {
    if(client.available()){
    String req = client.readStringUntil('\r');
    Serial.println(req);
    client.flush();
    int val;
    if(req.indexOf("0"))
      val=0;
    if(req.indexOf("1"))
      val=1;   
    if((req=="OFF")||(req=="off"))
    {
      Serial.println("Stop");
      client.println("Stop");
      client.stop();
      return;
    }     
   
    //digitalWrite(0,val);
    client.println(val);
    }   
    if(digitalRead(2)==1)
    {
      client.println("DOWN");
      Serial.println("DOWN");
      while(digitalRead(2)==1){
          if(digitalRead(2)==0){
             break;
            }         
        }
         client.println("UP");
         Serial.println("UP");
      }
  }
}



void printout() {
  Serial.println("");
  Serial.print("connected to SSID:  ");
  Serial.println(WiFi.SSID()); 
  Serial.print("Server status:  ");
  Serial.println(Server.status());
  IPAddress ip = WiFi.localIP();
  Serial.print("localIP:  ");
  Serial.println(ip);
  long rssi = WiFi.RSSI();
  Serial.print("signal strength:  ");
  Serial.print(rssi);
  Serial.println(" dBm");

}


Attachments
未命名.png
未命名.png (6.13 KiB) Viewed 6641 times

pratik

Re: let gpio2 be input control button

Postby pratik » Wed Apr 26, 2017 1:33 pm

Do not use long delays on the ESP8266 - otherwise it will produce a WDT reset (watchdog timer reset).
I am not familiar with Arduino interface for ESP8266, but you should try to reload the WDT between every few milliseconds of delay, rather than add a long delay with no WDT reload.

Who is online

Users browsing this forum: No registered users and 3 guests