Hey guys! You helped me a lot, I could create a Tcp server/client. And it is working pretty well. Except there is one serious problem with my server. It works great after I upload my sketch to it. But when I reset it or plug it off and then on , it does not even enter setup.
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
const int back=D8;
const int go=D7;
const int left=D6;
const int right=D5;
const char *ssid = "MyESPAP";
const char *password = "MyPassword";
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
Serial.println("Test4");
pinMode(go,OUTPUT);
pinMode(back,OUTPUT);
pinMode(right,OUTPUT);
pinMode(left,OUTPUT);
digitalWrite(go,HIGH);
digitalWrite(back,LOW);
digitalWrite(left,LOW);
digitalWrite(right,HIGH);
//WiFi.disconnect();
delay(100);
WiFi.mode(WIFI_AP);
Serial.println("Configuring Access Point ...");
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print(myIP);
server.begin();
}
WiFiClient client;
char c;
int count=0;
void loop()
{
Serial.println("I am in loop...");
if (!client.connected()) {
Serial.println("Waiting client...");
client = server.available();
}
while(client.connected()) {
if (client.available() > 0) {
c = (char)client.read();
Serial.println(c);
if(c=='F')
{
digitalWrite(back,LOW);
digitalWrite(go,LOW);
}
if(c=='B')
{
digitalWrite(go,HIGH);
digitalWrite(back,HIGH);
}
if(c=='S')
{
digitalWrite(back,LOW);
digitalWrite(go,HIGH);
}
if(c=='R')
{
digitalWrite(left,LOW);
digitalWrite(right,LOW);
}
if(c=='L')
{
digitalWrite(right,HIGH);
digitalWrite(left,HIGH);
}
if(c=='M')
{
digitalWrite(right,HIGH);
digitalWrite(left,LOW);
}
}
while(!(client.available()>0))
{
delay(50);
count++;
if(count>60)
{
client.stop();
return;
}
}
count=0;
}
client.stop();
digitalWrite(go,HIGH);
digitalWrite(back,LOW);
digitalWrite(left,LOW);
digitalWrite(right,HIGH);
}
You see that "Test4" there in the setup. I don't see it when I reset or switch device on.
Some part of the code may seem really beginner level
. You might guess that I am working on a RCCar project. But it works pretty well except that problem I mentioned.