I'm using two header file, SoftwareSerial.h
and ESP8266WiFi.h
. When I compile and upload programs, with ESP8266WiFi.h
, it had an error "Failed to connect to ESP8266: Timed out waiting for packet header". I tried it with only ESP8266WiFi.h
, but it had an same error. To use this header file, what should I do?
Here's my circuit and code.
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char *ssid = "circuits4you";
const char *pass = "password";
unsigned int localPort = 2000; // local port to listen for UDP packets
IPAddress ServerIP(192,168,4,1);
IPAddress ClientIP(192,168,4,2);
WiFiUDP udp;
char packetBuffer[9]; //Where we get the UDP data
void setup()
{
Serial.begin(9600);
Serial.println();
WiFi.softAP(ssid, pass); //Create Access point
Serial.println("Starting UDP");
udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(udp.localPort());
}
void loop()
{
int cb = udp.parsePacket();
if (!cb)
{
if(Serial.available()>0)
{
udp.beginPacket(ClientIP, 2000);
char a[1];
a[0]=char(Serial.read()); //Serial Byte Read
udp.write(a,1); //Send one byte to ESP8266
udp.endPacket();
}
}
else {
udp.read(packetBuffer, 1);
Serial.print(packetBuffer);
delay(20);
}
}