Chat freely about anything...

User avatar
By Exitras
#90939 Hi, I am using a NodeMCU (ESP8266) as a garage opener. When I come close to my garage, I automatically connect to the Wifi of my ESP and can open the garage by entering a webpage (which is an "app" on my iPhone.
This actually works rather well. However, the time to connect to the wifi varies from 1-100 seconds which can be a pain when I am already late.
When I open system settings on my iPhone, I can already see that the WiFi is connected to my iPhone but it sometimes takes a minute to fully connect and be visible in the top bar of my iPhone which is needed to open the garage.

- The design is build to never restart the ESP.
- The WiFi provides only the connection for the garage, no internet or anything else.
- We are only using this with a limited number of phones (2). So using a static IP for these phones would be no problem.
- The code has been written and uploaded using the Arduino IDE

Is anyone having an idea for a quick fix?

I provide my code below. It is rather messy but might help for clarification.

Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
 
String html1 = "<!DOCTYPE html>\r\n<html>\r\n\
<head>\r\n<meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">\r\n\
<title>Webr</title>\r\n\
<form action=\"";

// String((val)?"/1.html":"/0.html")
String html2 = "\">\r\n<input value=\"GO!\" style=\"";
String html3 = " width:15em;height:7em; font-size: 50px;\" type=\"submit\">\
</form>\r\n</head>\r\n<body>\r\n</body>\r\n</html>";
 
ESP8266WebServer server(80);    // Server Port
int val = 1;                    //Initial value (off)
String Temp = "";
bool TurnOn = false;
int timerValue = 1000;
int timer = timerValue;
int startTimer = 3000;
bool started = true;
const int outputpin = 4;

void Turn_ON()       // When calling "http://<ip address>/1.html"
{
  val = 0;                      // Relais Aus
  digitalWrite(outputpin, 1);         // GPIO0
  Temp = html1 + String((val) ? "/1.html" : "/0.html");
  Temp += html2 + String((val) ? "BACKGROUND-COLOR: DarkGray;" : "BACKGROUND-COLOR: Chartreuse;") + html3;
  server.send(200, "text/html", Temp);
  TurnOn = true;
}
 
void Turn_OFF()  // when calling "http://<ip address>//0.html"
{
  val = 1;                      // Relais Ein
  digitalWrite(outputpin, 0);         // GPIO0
  Temp = html1 + String((val) ? "/1.html" : "/0.html");
  Temp += html2 + String((val) ? "BACKGROUND-COLOR: DarkGray;" : "BACKGROUND-COLOR: Chartreuse;") + html3;
  server.send(200, "text/html", Temp);
}
 
void Turn_Index()           // when calling "http://<ip address>/"
{
  Temp = html1 + String((val) ? "/1.html" : "/0.html");
  Temp += html2 + String((val) ? "BACKGROUND-COLOR: DarkGray;" : "BACKGROUND-COLOR: Chartreuse;") + html3;
  server.send(200, "text/html", Temp);
}
 
void setup()
{
  //digitalWrite(outputpin, 0);           // Relay off
  pinMode(outputpin, OUTPUT);           // GPIO0 out
//  pinMode(2, INPUT_PULLUP);     // GPIO2 Pullup
//  digitalWrite(outputpin,0);           // Relay off
 
  Serial.begin(115200);         // Serial connection
  Serial.println("");           // print empty line
  WiFi.mode(WIFI_AP);           // access point modus
  WiFi.softAP("XXXXX", "XXXXX");    // Name and PW of WiFi
  delay(500);                   //Wait 0.5s
  Serial.print("IP Adresse ");  //Current server IP
  Serial.println(WiFi.softAPIP());
 
  //  Bechandlung der Turnsen anschlissen
  server.on("/", Turn_Index);
  server.on("/1.html", Turn_ON);
  server.on("/0.html", Turn_OFF);
 
  server.begin();               // Server start
  Serial.println("HTTP Server gestartet");
}
 
void loop()
{
 /*
  * 
  *if(started == true){
  startTimer --;
        Serial.println(startTimer);

  }

  if(startTimer < 0){
      digitalWrite(0, 0);
              Serial.println("Relais aus");
   started = false;

    }
    */
 

  if(TurnOn == true)
    {
    timer --;
      Serial.println(timer);

  }

   
  if(timer < 0){
          Serial.println("switch off");

    Turn_OFF();
    TurnOn = false;
    timer = timerValue;
  }
 
  server.handleClient();

  /*
  if (!digitalRead(2))          //GPIO2 press
  {
    val = !val;                 // change
    digitalWrite(0, val);
    while (!digitalRead(2))server.handleClient(); // button release.
  }
  */
 
 
}
User avatar
By QuickFix
#90965
Exitras wrote:Is anyone having an idea for a quick fix?

Moi? :lol:

Though not a solution to the problem, but have you tried to narrow it down by using other devices (an Android phone, an iPad, a PC running Windows/Linux/iOS/...) to rule out whether it's the ESP or the phone/OS?
User avatar
By jankop
#90968 This is your HTML page:
Code: Select all<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Webr</title>
<form action="/0.html">
<input value="GO!" style="BACKGROUND-COLOR: Chartreuse; width:15em;height:7em; font-size: 50px;" type="submit"></form>
</head>
<body>
</body>
</html>

Shouldn't the form be in the body of HTML?
Here is valid HTML file:
Code: Select all<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <title>Webr</title>
  </head>
  <body>
<form action="/1.html">
<input value="GO!" style="BACKGROUND-COLOR: DarkGray; width:15em;height:7em; font-size: 50px;" type="submit"></form>
  </body>
</html>