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.
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 :
//#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