K
K
kagoyashi2022-03-28 19:43:38
Arduino
kagoyashi, 2022-03-28 19:43:38

Why doesn't it always connect to esp01 server?

there is a code for esp

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "ssid"
#define STAPSK  "pass"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;
WiFiServer server(80);

void setup() {
  Serial.begin(9600);
 
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  server.begin();
}
void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  else
  {
    client.println(F("OK"));
  }
  client.setTimeout(5000); 
  byte* buf;
  while (client)
    while (client.available()) {
     char c = client.read();
     Serial.write(c);
   }
}


I am writing on arduino, because I spit with pluses to mess around, and so I can’t figure it out.
in the router settings, I reserved ip, which was always given locally.
but tcp clients connect every other time and in general everything is unstable.
As far as I know, you don't need a white ip to connect to an esp server on the local network.
what's wrong with him?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question