Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Ralf Smit
#41491 Dear all,

It has been a while since i have started working with the ESP8266 , but after trying and trying i keep running into a specific problem. For the system im designing the structure is as followed

I have one ESP12-E which runs as a AP and runs a sever , the other ESP(s) should connect to the AP and connect to the running TCP server. Initially the first time i tried it was running and i recieved my "Hello World" message without any failures. I disconected power, the module restarted , but since then i cant seem to make any connection with the webserver anymore, the ESPclient does connect to the AP but fails to connect to the webserver. My phone however does connect to the webserver running on the ESP-ap

Code of ESP-ap running the webserver.
Code: Select all extern "C" {
#include "user_interface.h"
}

#include <ESP8266WiFi.h>
char Name[32] = "Pluk-O-Trak_";//{'P','l','u','k','_'}; // Standard name
char ID[8] ; // buffer of ID of the ESP8266 ID
const char *ssid = "ERROR_NAME";
const char *password = "123456789";
IPAddress myIP; // store your ID

#define MAX_SRV_CLIENTS 10
WiFiServer server(23); // Create the  TCP server on Port23
WiFiClient serverClients[MAX_SRV_CLIENTS]; // Set max clients of the webServer
WiFiClient client;
char packetBuffer[255]; //buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged";

void wifi_Setup()
{

  itoa(ESP.getChipId(), ID, 10); // get ID
  // Convert ID to constant Char
  for (int i = 0; i < 8; i ++)
  {
    Name[i + 12] = ID[i];

  }
  const char *ssid = Name;
  WiFi.softAP(ssid, password, 8, 0); // start the AP
  delay(10000);

  Serial.println("");
  myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.begin();
  server.setNoDelay(true);
  Serial.println("TCP Server Setup done");


}

void setup() {
  Serial.begin(115200);
  Serial.println("Configuring Wifi");
  wifi_Setup();
  delay(2000);
  Serial.println("Setup_Completed");
}

void loop() {
  if (!client.connected()) {
        // try to connect to a new client
        client = server.available();
    } else {
        // read data from the connected client
        if (client.available() > 0) {
            Serial.write(client.read());
        }
    }
 
}


Code of the ESPclient :
Code: Select all//#include <Wire.h>
//#include "Adafruit_MCP23017.h"
#include <ESP8266WiFi.h>
#include <WiFiClient.h>


const char *ssid = "Pluk-O-Trak_13728607";//"Pluk-O-Trak_318664";
const char *password = "123456789"; //"123456789";


IPAddress host(192,168,4,1);
WiFiClient client;
 void setup() {
  Serial.begin(115200);

 
 
   WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Connect to TCP sever on port 23, with ip 192.168.4.1
  if (!client.connect(host, 23)) {
    Serial.println("connection failed");
     
  }
  else
  {
   
     Serial.println("connection Succes");
     delay(10000);
  }
 
 }
 

void loop() {
 
  client.println("HELLO WORLD");
  delay(1000);

 
 
}



There is a connection between the ESP-ap and the ESP-client, the WIFI connection is correct.
However it fails to connect to the sever.

I also tried using just the home network, then the sever is always connected to. Any suggestions? on my code or another principle to use for direct communitcation between 2 - 5 ESPmodules without the need of external devices

Thanks in Advance,
Kind Regards,
Ralf Smit
User avatar
By mrburnette
#41540 When faced with weird, I go to standard examples to verify tbe units work properly.

If you cannot get a published example to work, then the issue is hardware. Remember too, once a client has connected to an AP, it attempts this repeatedly on power-on.

I have one AP snd several clients on UDP, works great - tested to 3 ESP8266s... the AP has not been rebooted in 6 months! (Which is very good as it is up in the attic for best GPS reception.)


Ray
User avatar
By Ralf Smit
#41796 Thanks Ray,

Well that's kind of the problem it doesn't run the standard programs,
the UDP randomly assigns a port to send too, so ones a while i do receive some data.
This suppose to be a problem that was resolved however for me it didn't.

Also the weirdest part was that is was running correctly as TCP connection, until i restarted both the modules,
no hardware or software changes in the main time.

Could you maybe provide me with the UDP code you are using?

Kind regards,
Ralf Smit