Giter VIP home page Giter VIP logo

wifiesp's People

Contributors

arvindell avatar bportaluri avatar bryant1410 avatar grahamcobb avatar jiribilek avatar joysfera avatar paolop74 avatar piit79 avatar riccardobrue avatar sukkopera avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wifiesp's Issues

Older ESP-01 Firmware Support

I see that most ESP-01 modules come with v.0.9.2 loaded. I noticed that WifiEsp rejects that. Any reason you need a higher version? Are there some features that depend on it?

I tried flashing to no avail using every tutorial on the entire web, including and especially this one: http://yaab-arduino.blogspot.it/2015/12/flashing-esp8266-firmware-arduino.html.

My ESP-01 devices refuse to work with v1.x. I can flash them with NodeMCU and it works fine, so I know my hardware and wiring for programming are good.

I also read through this post #9, but my issue is different, in that flashing succeeds, no errors, but the device will NOT respond to AT commands (acts as though it's dead or without firmware). Any tips are appreciated. But in the meantime, if WifiESP didn't have this requirement, that would also be helpful. I've looked at about 10 other wifi libraries and WifiESP is the only one that actually has activity and changes more recently than a full year ago.

Buffer overflow in UDP.read()

In the official Ethernet library's UDP.read(unsigned char* buffer, size_t len), len is the buffer size, so care should be taken not to write more than len bytes to buffer.

This does not happen in WifiEsp, where the len parameter is basically ignored and the buffer is overflowed if more bytes are received than can fit into the buffer.

See: https://www.arduino.cc/en/Reference/EthernetUDPRead

Compiling Errors

I am receiving the following errors while using your code.

This is the webserver example code. I'm using Arduino IDE 1.6.5

This is the code, i've added in my ssid and pass and some other stuff to work with my 8266...

`/*
WiFiEsp example: WebServer

A simple web server that shows the value of the analog input
pins via a web page using an ESP8266 module.
This sketch will print the IP address of your ESP8266 module (once connected)
to the Serial monitor. From there, you can open that address in a web browser
to display the web page.
The web page will be automatically refreshed each 20 seconds.

For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/

include <PLDuino.h>

include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present

ifndef HAVE_HWSERIAL1

include "SoftwareSerial.h"

SoftwareSerial Serial1(14, 15); // RX, TX

endif

char ssid[] = "Linksys2"; // your network SSID (name)
char pass[] = "6046146090"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
int reqCount = 0; // number of requests received

WiFiEspServer server(80);

void setup()
{
using namespace PLDuino;

PLDuino::init();
enableESP();
// initialize serial for debugging
Serial.begin(9600);
// initialize serial for ESP module
Serial1.begin(115200);
// initialize ESP module
WiFi.init(&Serial1);

// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}

// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}

Serial.println("You're connected to the network");
printWifiStatus();

// start the web server on port 80
server.begin();
}

void loop()
{
// listen for incoming clients
WiFiEspClient client = server.available();
if (client) {
Serial.println("New client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
Serial.println("Sending response");

      // send a standard http response header
      // use \r\n instead of many println statements to speedup data send
      client.print(
        "HTTP/1.1 200 OK\r\n"
        "Content-Type: text/html\r\n"
        "Connection: close\r\n"  // the connection will be closed after completion of the response
        "Refresh: 20\r\n"        // refresh the page automatically every 20 sec
        "\r\n");
      client.print("<!DOCTYPE HTML>\r\n");
      client.print("<html>\r\n");
      client.print("<h1>Hello World!</h1>\r\n");
      client.print("Requests received: ");
      client.print(++reqCount);
      client.print("<br>\r\n");
      client.print("Analog input A0: ");
      client.print(analogRead(0));
      client.print("<br>\r\n");
      client.print("</html>\r\n");
      break;
    }
    if (c == '\n') {
      // you're starting a new line
      currentLineIsBlank = true;
    }
    else if (c != '\r') {
      // you've gotten a character on the current line
      currentLineIsBlank = false;
    }
  }
}
// give the web browser time to receive the data
delay(10);

// close the connection:
client.stop();
Serial.println("Client disconnected");

}
}

void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print where to go in the browser
Serial.println();
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
Serial.println();
}`

I get the following error.

Arduino: 1.6.5 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

WebServer.ino: In function 'void setup()':
WebServer:64: error: 'printWifiStatus' was not declared in this scope
'printWifiStatus' was not declared in this scope

`
Even though it is in the code. So i then comment it out and get a compiling error...

Arduino: 1.6.5 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

\GAS1\RedirectedFolders\AndrewC\My Documents\Arduino\libraries\WiFiEsp-master\src\utility\EspDrv.cpp: In static member function 'static bool EspDrv::getNetmask(IPAddress&)':
\GAS1\RedirectedFolders\AndrewC\My Documents\Arduino\libraries\WiFiEsp-master\src\utility\EspDrv.cpp:516:8: error: 'class IPAddress' has no member named 'fromString'
mask.fromString (buf);
^
\GAS1\RedirectedFolders\AndrewC\My Documents\Arduino\libraries\WiFiEsp-master\src\utility\EspDrv.cpp: In static member function 'static bool EspDrv::getGateway(IPAddress&)':
\GAS1\RedirectedFolders\AndrewC\My Documents\Arduino\libraries\WiFiEsp-master\src\utility\EspDrv.cpp:530:6: error: 'class IPAddress' has no member named 'fromString'
gw.fromString (buf);
^
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Any ideas?

Buffer overflow with ESP8266 firmware 0.60

I am using this library with an ESP-12E with firmware 0.60, recently released. This replies to AT+GMR with a firmware version of 1.5.2(80914727), which is longer than the library expects, leading to memory corruption.

The solution is to set in EspDrv.h:
#define WL_FW_VER_LENGTH 16

Memory usage is high

I wonder what is using over 540 bytes of precious Global Variable space.
A basic program gives me the following ...

            code size   Global Vars
+WiFiEsp        4854        357
+init           7114        905 (548 bytes more)

The basic program

#include "WiFiEsp.h"

// Emulate Serial1 on pins 2/3 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
//#define _SS_MAX_RX_BUFF 256 // RX buffer size //BEFORE WAS 64
SoftwareSerial Serial1(2, 3); // RX, TX
#endif


void setup() {
    Serial.begin(9600);
    Serial1.begin(9600);
//  WiFi.init(&Serial1);

// check for the presence of the shield:
//  if (WiFi.status() == WL_NO_SHIELD) {
//    Serial.println("WiFi shield not present");
//   don't continue:
//   while (true);
//  }
  }

void loop() {

}

Bad constant in EspDrv::getScanNetworks

is: if(ssidListNum==WL_SSID_MAX_LENGTH-1) break;
to be: if(ssidListNum==WL_NETWORKS_LIST_MAXNUM-1) break;

or
comment if(ssidListNum==WL_SSID_MAX_LENGTH-1) break;
and change
while (idx == NUMESPTAGS)
to
while ((idx == NUMESPTAGS) && (ssidListNum < WL_NETWORKS_LIST_MAXNUM))

Large Mutli-block GET requests

Thanks for making this work previously.
I have provided code to demonstrate the next little quirk.
You should be able to run this with only your AP change needed.
The GET returns 4 blocks 3 are the full TCP packet and the last on is a partial packet.
When I do this manually via AT commands the 4 blocks come back one after the one with no delays.
When i do this via the arduino code below, there is often a 2 to 10 second break between the 2nd and 3rd blocks. i cant figure out why.

Any ideas?

/*
 WiFiEsp example: WebClient



 Circuit: http://yaab-arduino.blogspot.com/2015/03/esp8266-wiring-schemas.html
*/

#include "WiFiEsp.h"

// Emulate Serial1 on pins 2/3 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
//#define _SS_MAX_RX_BUFF 256 // RX buffer size //BEFORE WAS 64
SoftwareSerial esp8266(2, 3); // RX, TX
#endif



  int result;
  int InvertCount;
  int k;
  char c;
  int totalW =0;
  float tempA =0;
  float ACVoltsA =0;
  float DailyWatts= -1.0;
char dstr1[9] ;
char dstr2[9] ;
char lasttime[9] ;



char ssid[] = "nilfilum";            // your network SSID (name)
char pass[] = "";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "mancave.space";
byte serverPORT = 80;

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiEspClient client;

void setup() {
  // initialize serial and wait for port to open:
  Serial.begin(9600);
//  Serial.begin(115200);
  while (!Serial); // wait for serial port to connect. Needed for Leonardo only

  esp8266.begin(9600);
  // initialize ESP module
  WiFi.init(&esp8266);
//  WiFi.init(9600);  // initialize ESP serial port with default baud rate 9600

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, serverPORT)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /parameters.php HTTP/1.1");
    client.print("Host: "); client.println(server);
//    client.println("Connection: keep-alive");
    client.println("Connection: close");
    client.println();
  }


InvertCount=0; totalW=0;tempA=0;ACVoltsA=0;

}




void loop() {
 ECURealTimeData_RAW_CRLF();


  // if there are incoming bytes available
  // from the server, read them and print them:
//  while (client.available()) {    char c = client.read();    Serial.write(c);  }




  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();


    Terminal(); // nice way to finish

  }
}


void ECURealTimeData_RAW_CRLF()
{ 
  char c;
  char b;
  char a;
  char d;
while (client.available()) 
      { 
       a=b;
       b=c;
       c=d;
       d = client.read();    
       Serial.write(d);  
       if ((a =='/')&& (b =='t') && (c == 'r')&& (d == '>') ) Serial.println();
      }

}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}


void Terminal()
{
  Serial.println("Terminal Mode Forever");

 while(1)
{ 
  if(esp8266.available())  // check if the ESP is sending a message
  {
    while(esp8266.available())
    {
      char c = esp8266.read();  // read the next character.
      Serial.write(c);  // writes data to the serial monitor
    }
  }

  if(Serial.available())
  {
    delay(10);  // wait to let all the input command in the serial buffer

    // read the input command in a string
    String cmd = "";
    while(Serial.available())
    {
      cmd += (char)Serial.read();
    }

    // print the command and send it to the ESP
    Serial.println("---------------------");
    Serial.print(">> ");
    Serial.println(cmd);
    Serial.println("---------------------");
    esp8266.println(cmd); // send the read character to the esp8266
  }
}
}






try webclient example , got that error .

C:\Users\wchen\Documents\Arduino\libraries\WiFiEsp\src\utility\EspDrv.cpp: In static member function 'static bool EspDrv::getNetmask(IPAddress&)':
C:\Users\wchen\Documents\Arduino\libraries\WiFiEsp\src\utility\EspDrv.cpp:503:10: error: 'class IPAddress' has no member named 'fromString'
mask.fromString (buf);
^
C:\Users\wchen\Documents\Arduino\libraries\WiFiEsp\src\utility\EspDrv.cpp: In static member function 'static bool EspDrv::getGateway(IPAddress&)':
C:\Users\wchen\Documents\Arduino\libraries\WiFiEsp\src\utility\EspDrv.cpp:516:8: error: 'class IPAddress' has no member named 'fromString'
gw.fromString (buf);
^
Error compiling.

Changing mode 1 to 2

Hello, I am able to connect as a user to a router and as a SoftAP independently, however i can not change the mode in the middle of the program. I need to know how to got from a AP to a normal user. other sample using AT commands works fine but it is better to learn how to use this library.
Can you run both at the same time like in AT mode 3?
if you need more clarifications please let me know.
Also i wonder why the parameters for connection wifi.begin ssid and pass are Char array. it is harder to manipulate, do substring search etc in Arrays than in Strings type.
Thanks in advance.

ESP hangs on Timeout

At first here is the buggy code block -

` WiFiEspClient client = myserver.available();
if (client)
{Serial.println("Incoming connection...");
String readString = "";
char c;

 boolean currentLineIsBlank = true;

while(client.connected() )//&& millis()>(clienttimerecall+5000))
{if(client.available()){
c=client.read();
readString+=c;

if ((c == '\n' && currentLineIsBlank)){

k = statefinder(readString); ////////THIS BLOCK IS ENTIRELY WORK BASED
String printz=""; //////// AND DOES NOT USE ANY ESP BASED
worker(k,readString); //////// FUNCTIONS OR CALLS!
printz= clientprinter(k); ///////

Serial.print(" What came is this = ");
Serial.println(readString);
Serial.print("What I sent is this = ");
Serial.println(printz);

client.print("HTTP/1.1 200 OK\r\n");
client.print("\r\n");
client.print(printz);
client.print("\r\n");
break;}
if (c == '\n') { currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;}

}}delay(10);
client.stop();
Serial.println("Client disconnected");
`

Now the problem starts when i actually use the server,it works fine for some times but later esp hangs & thts how it goes-

`[WiFiEsp] New client 0
Incoming connection...
THE TEMPERATURE CHECKER SAYS = 33
Registered Time is = 0
Millis Time is = 57579
Start Time is = 0
What came is this = GET /LIGHT HTTP/1.1
Host: 192.168.0.49
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)

What I sent is this = light

sendData: 0 17

OK

Recv 17 bytes

SEND OK

sendData: 0 2

OK

Recv 2 bytes

SEND OK

sendData: 0 5

OK

Recv 5 bytes

SEND OK

sendData: 0 2

OK

Recv 2 bytes

SEND OK
[WiFiEsp] Disconnecting 0

stopClient 0

AT+CIPCLOSE=0
0,CLOSED

OK
---------------------------------------------- > 0

Client disconnected

Data packet 0 121
[WiFiEsp] New client 0
Incoming connection...
[WiFiEsp] TIMEOUT: 102

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"z!â

Connected

|
|
|
|
|
|

//////That block keeps repeating until client is stopped & for reasons my client can't have timeouts//////
|
|
|
|
|
////and ends with this(when client is stopped

getClientState 0

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","192.168.0.105",41324,1

OK
---------------------------------------------- > "TCP"�B�

Connected

getClientState 0

AT+CIPSTATUS
0,CLOSED
STATUS:4

OK
No start tag found: 0
---------------------------------------------- >

Not connected
Client disconnected

`

As you can see i switched to debug mode of WifiESP & this problem doesn't seem to have any pattern ,it happens to any time without certain reasoning.....
The only thing that came up to me when i tried to dig up is that , two requests may be mixed up with each other & causing this...but i am not sure, could you please look up into this issue ,this issue is really pushing my project to my deadline & really causing me problems!!
PLEASE HELP !!

Garbage in ScanNetwork

Show garbage from previous scan , must do cleaning memory prior to new scan.

// add:
memset(_networkSsid[ssidListNum], 0, WL_SSID_MAX_LENGTH );

// before line 473 in WiFiEsp/src/utility/EspDrv.cpp

ringBuf.getStr(_networkSsid[ssidListNum], 1);

Otherwise, an excellent library. Thanks.

ESP Version handling of _CUR _DEF commands

Hi, would it be possible to make the library use the commands that have _DEF _CUR etc only if the version of ESP attached supports them?
getFwVersion() checks the version so can the commands use be based on what it finds?

favicon.ico fails - multiple connections not supported well?

With 'wget' calling the webserver repeatedly it seems to work well but if I use Google Chrome that asks for both index.html and favicon.ico at the same time it fails and reads some garbage, then timeouts:

This is correct, connection ID = 0:

ConnID: 0
Bytes: 356
returning client 0
new client
GET / HTTP/1.1
Host: 192.168.105.160
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: cs,en-US;q=0.8,en;q=0.6

And this is the failing connection:

+IPD,1,330:GET /favicon.ico HTTP/1.1
Host: 192.168.105.160
Connection: keep-alive
User-Agent:ola.(1 nx86 lWK/76(T,leek rm40213Sa/76Aet*
D:
Rer t/1.81.0
etndggi fa,dhAetaug ,-S=8eq.
O

TIMEOUT >>>

Cannot initialize ESP module

i am running example code from this library.i.e. WebClient

i am getting this out put on Seria Monitor
[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module

then after some time

[WiFiEsp] Failed to connected to Taneja
SSID: [WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found

[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
IP Address: 0.0.0.0
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
Signal strength (RSSI):0 dBm

i have connected the circuit as below
esp8266 rx to pin 5
esp8266 tx to pin 6
5v to voltage regulator Vin and voltage regulator Vout to esp8266 vcc and CH_PD
gnd to gnd and then after uploading the program it gives above output.

the code is like this
`#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present

ifndef HAVE_HWSERIAL1

include "SoftwareSerial.h"

SoftwareSerial Serial1(6, 7); // RX, TX

endif

char ssid[] = "Taneja"; // your network SSID (name)
char pass[] = "taneja1993"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status

char server[] = "arduino.cc";

// Initialize the Ethernet client object
WiFiEspClient client;

void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);

// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}

// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}

// you're connected now, so print out the data
Serial.println("You're connected to the network");

printWifiStatus();

Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
if (client.connect(server, 80)) {
Serial.println("Connected to server");
// Make a HTTP request
client.println("GET /asciilogo.txt HTTP/1.1");
client.println("Host: arduino.cc");
client.println("Connection: close");
client.println();
}
}

void loop()
{
// if there are incoming bytes available
// from the server, read them and print them
while (client.available()) {
char c = client.read();
Serial.write(c);
}

// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();

// do nothing forevermore
while (true);

}
}

void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}`

Can't connect to server If I try without Computer

It is working very well If Arduino is connected to computer. If I will use standalone Arduino (without computer only power supply) It can't connect to server. It have a IP, can I ping from the computer but It can't send data to the server.

My code is:
Code

scan network and encryption type

Hi,

Thanks for your very good job with this library. I have a question about implementing the scannetwork function in order to see available APs around.

In this case the command is AT+CWLAP and, as reported in https://room-15.github.io/blog/2015/03/26/esp8266-at-command-reference/ the first number gives you the encryption type too.

Do you think to implement the possibility to see near aps around? With the iteadlib this function is implemented, resulting in an output string. Is it possible to do the same with your lib?

Thanks again.
Bye

compile errors

From the latest version, i get this list of complaints from the compiler
the previously downloaded version will compile ok
Terry

C:\Users\terry\AppData\Local\Temp\build6429296284531538672.tmp\ECU_yes2.cpp.o
ECU_yes2.ino: In function 'void SetUpGETRealTimeData()':
ECU_yes2.ino:128:26: error: no matching function for call to 'WiFiEspClient::print(const char [7])'
ECU_yes2.ino:128:26: note: candidate is:
In file included from C:\Program Files (x86)\Arduino\libraries\WiFiEsp-master\src/WiFiEsp.h:28:0,
from ECU_yes2.ino:14:
C:\Program Files (x86)\Arduino\libraries\WiFiEsp-master\src/WiFiEspClient.h:39:10: note: size_t WiFiEspClient::print(const _FlashStringHelper)
size_t print(const __FlashStringHelper *ifsh);
^
C:\Program Files (x86)\Arduino\libraries\WiFiEsp-master\src/WiFiEspClient.h:39:10: note: no known conversion for argument 1 from 'const char [7]' to 'const _FlashStringHelper'
ECU_yes2.ino: In function 'void SetUpGETHomeData()':
ECU_yes2.ino:143:26: error: no matching function for call to 'WiFiEspClient::print(const char [7])'
ECU_yes2.ino:143:26: note: candidate is:
In file included from C:\Program Files (x86)\Arduino\libraries\WiFiEsp-master\src/WiFiEsp.h:28:0,
from ECU_yes2.ino:14:
C:\Program Files (x86)\Arduino\libraries\WiFiEsp-master\src/WiFiEspClient.h:39:10: note: size_t WiFiEspClient::print(const _FlashStringHelper)
size_t print(const __FlashStringHelper *ifsh);
^
C:\Program Files (x86)\Arduino\libraries\WiFiEsp-master\src/WiFiEspClient.h:39:10: note: no known conversion for argument 1 from 'const char [7]' to 'const _FlashStringHelper'
no matching function for call to 'WiFiEspClient::print(const char [7])'

Can't connect to server with 2.1.2 version

I recently downloaded latest reposity version 2.1.2. I can't understand why my ESP8266 can't connect to server. With 2.1.1 version works like charm.
First I connect to WiFi using this code:

wifiEsp.init(&Serial);
wifiEsp.reset();
bool isCon = wifiEsp.begin("ssid", "psw");
if (isCon) {
  softSerial.println("Connected to Wifi");
}

ESP8266 successfully connected to wifi when using v2.1.1 or v2.1.2.
Then I try connect to server using this code:

if (httpClient.connect("xxx.xxx.xxx.xxx", 80)
{
  softSerial.println("Connected to Server");
}
else
{
  softSerial.println("Not Connected to Server");
}

ESP8266 successfully connected to server only using 2.1.1. Why not work with 2.1.2 version? :( I try two servers. Can't connect to both.

WebServer example does not work at all

The WebServer example does not work at all - it does not open up the port 80:

Attempting to connect to WPA SSID: Twim
You're connected to the network
SSID: Twim
IP Address: 192.168.3.144

To see this page in action, open a browser to http://192.168.3.144

$ telnet 192.168.3.144 80
Trying 192.168.3.144...
telnet: Unable to connect to remote host: Connection refused

Closing connection behavior

Sending client.println("Connection: close"); along with a request makes client.stop() throw an error

AT+CIPCLOSE=0
link is not
ERROR

Not calling client.stop() at all poses the problem that WiFiEsp thinks the connection is still active and runs out of sockets to use.

Compile Error for Arduino Zero

If I try to compile a sketch using i nthe Arduino IDE using the SAMD architecture (Arduino Zero), I get the following error:

`C:\Users\quino\Documents\Arduino\libraries\WiFiEsp\src/utility/RingBuffer.h:23:7: error: redefinition of 'class RingBuffer'``

Removing the lines 30,31 & 32 solves the compilation errors:
`//#include "utility/EspDrv.h"

//#include "utility/RingBuffer.h"

//#include "utility/debug.h"`

But then I have a new issue:
'WL_IDLE_STATUS' was not declared in this scope

Connection Bug: client.connected() says CONNECTED but it isnt connected no more

After GETting a block of data back, the client.connected() remains true, even though the connection is now closed.
seems like _sock isnt being set to 255 when the end tag "CLOSED" is received.

Doing a GET manually, this is how V1.5 ends the connection with a connection number,CLOSED.

4,CLOSED

...

. client.connected() says CONNECTED

getConnectionStatus

AT+CIPSTATUS
STATUS:4

OK
---------------------------------------------- > 4

Firmware needed

Hi, can anyone provide a link to firmware to update the ESP8622-01 the little blue one.
Currently AT+GMR returns 2.2.89.2, what ever that is.
I think WiFiERsp says ver 21.
I would like to upgrade to ver 22.

Declare errors

I am super excited about this library that you have created. Thank you for taking your time to make this. I have an issue i am hoping you can help me with. I get the following error when trying any of the examples. This is from the BasicTest.ino

`BasicTest.ino: In function 'void loop()':
BasicTest:45: error: 'assertEquals' was not declared in this scope
BasicTest:52: error: 'assertNotEquals' was not declared in this scope
BasicTest.ino: In function 'void assertNotEquals(const char_, int, int)':
BasicTest:100: error: 'pass' was not declared in this scope
BasicTest:102: error: 'fail' was not declared in this scope
BasicTest.ino: In function 'void assertEquals(const char_, int, int)':
BasicTest:108: error: 'pass' was not declared in this scope
BasicTest:110: error: 'fail' was not declared in this scope
BasicTest.ino: In function 'void assertEquals(const char_, char_, char*)':
BasicTest:116: error: 'pass' was not declared in this scope
BasicTest:118: error: 'fail' was not declared in this scope
'assertEquals' was not declared in this scope

`

I am using Arduino IDE 1.6.5

Failure of MQTT PubSubClient : Asyncronous operations not supported?

I attempted to use the standard MQTT Client with your WIFI library and subscription related incomming information was confused with responses from AT+CISTATUS.
It sounds like the incomming information from the Serial port should be classified as response from incomming traffic (+IPD...) vs other responses from outgoing requests such AT+CISTATUS.

Your library is compatible enough with PubSubClient to compile, but some work has to be done to make the processing of the incomming serial traffic asynchronous (SerialEvent) so responses to outgoing request are kept distinct from incoming requests from the different connected clients.

I have spent a lot of time trying to figure out why the MQTT subscriptions were not working, Unless you already have an Idea to fix your library, I may be able to provide some paths to fix the issue, this will require some work.

MEGA compatibility

The Arduino MEGA bootloader does not handle three exclamation marks in a row properly (it switches to monitoring mode) - which causes uploading any code using this library to fail. This can be easily solved by removing some of the "!" characters in EspDrv.cpp (lines 93 and 785).

I would consider this a bug in the MEGA bootloader, not in this library, but anyway it could solve many a headache!

Weird EspDrv::wifiConnect behavior

I have no clue why but I had to change 299-304 into return sendCmd(cmdBuf, 10000) == TAG_OK; to make EspDrv::wifiConnect return the correct status. With the current code the if statement was not evaluating correctly although the values were correct. This is with SDK 0.9.5 and Arduino 1.6.5.

Enhancement to debug output

Hi, I added \r\n to the level 4 debug output, makes viewing a large chuck of multiple packets more readable.
Currently, it puts the Data Packet message at the end of the line of html.

in EspDrv.cpp in availData function

line 487 LOGDEBUG2(F("\r\nData packet"), _connId, _bufPos);

Wifi.ping always true

trying to use .ping but always return true no matter which IP or DNS name specify, even putting a garbage as DNS also return True.

Litle problem

bool EspDrv::wifiConnect(char* ssid, const char *passphrase)
{
INFO1(F("> wifiConnect"));

bool ret;

// connect to access point
sprintf(cmdBuf, "AT+CWJAP=\"%s\",\"%s\"", ssid, passphrase);

if (sendCmd(cmdBuf, 20000)==TAG_OK);    << Problem!  ; must not be here
{
    return true;
}

return false;

}

UdpNTPClient example does not work reliably

I can't understand why exactly, but the UdpNTPClient mostly fails.

NTP packets are 48 bytes long, and Udp.parsePacket () correctly returns 48. But then, the buffer returned by Udp.read() only contains the first 33 bytes with padding zeroes. I have traced this problem to EspDrv::timedRead() timing out after the 33th byte, but I can't understand why this happens.

To add to the weirdness, the following Udp.read() calls only return 15 bytes (which is 48 - 33, by the way!), but they do not look to be the "missing" bytes of the previous message.

I thought this could be caused by the ring buffer size, so I tried increasing it but to no avail.

The NTP reply contains 8 consecutive zero bytes before the 33th byte (bytes 25-32), maybe this is causing the misbehaviour?

Note that since the actual time that gets decoded by the sketch is at bytes 40:43, the sketch will always say that time is 6:28:16, which corresponds to all zeroes at such positions.

Cannot connect to MQTT-server (problem due to not showing correct local IP?)

Hi! I am using a ESP8266-01 to enable wifi for my Arduino Uno. The ESP-01 is connected via the RX/TX on the Uno, and i am using SoftSerial for debugging (via an Arduino USB2Serial). The ESP-01 is powered from a separate power source.

I manage to connect to my AP (wifi), but not to my MQTT broker (mosquitto on a raspberry pi). I get the following error in mosquitto:

"Socket error on client (null), disconnecting"

In the serial monitor, i get that the MQTT-connection fails (RC: -2)

The essential parts of my code:
Declarations etc:

#include <WiFiEsp.h>
#include "SoftwareSerial.h"
#include <PubSubClient.h>

WiFiEspClient espClient;
PubSubClient client(espClient);

char* ssid = "XXXX";
char* password = "XXXXXX";
int status = WL_IDLE_STATUS;   // the Wifi radio's status

const char* mqtt_server = "server";
const char* mqtt_username = "user";
const char* mqtt_password = "password";
const char* mqtt_client_name = "cliendID";

My setup-loop (i'm using a macro to enable/disable serial.println for debugging)

void setup() {

  soft.begin(9600); // SoftSerial for debugging
  Serial.begin(115200); //ESP8266-01 

  delay(1000);
  WiFi.init(&Serial);

  delay(1000);

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    DEBUG_PRINTLNT("WiFi shield not present");
    // don't continue
    while (true);
  }
  delay(100);

  while ( status != WL_CONNECTED) {
    DEBUG_PRINT("Attempting to connect to WPA SSID: ");
    DEBUG_PRINT(ssid);
    DEBUG_PRINTLNT(".");
    status = WiFi.begin(ssid, password);
    delay(10000); 
    DEBUG_PRINT("SSID: ");
    DEBUG_PRINTLNT(WiFi.SSID());
    DEBUG_PRINT("Wifi.status: ");
    DEBUG_PRINTLNT(status);
    DEBUG_PRINT("IP: ");
    DEBUG_PRINTLNT(WiFi.localIP());
    DEBUG_PRINT("Firmware version: ");
    DEBUG_PRINTLNT(WiFi.firmwareVersion());
  }

  //CONNECT TO MQTT BROKER
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);

  while (!client.connected()) {
    reconnect();
  }  
  client.loop();  
}

The reconnect() function:

void reconnect() { 
  while (!client.connected()) {
    soft.println(F("Attempting MQTT connection..."));
    // Attempt to connect
    if (client.connect(mqtt_client_name, mqtt_username, mqtt_password,mqtt_topic_arduino_status,0,true,"offline")) {
      mqttSubscribe(mqtt_topic_r1_status);
      mqttSubscribe(mqtt_topic_r2_status);   
    } else {
      soft.print(F("Failed, rc=")); //using the softserial for debugging...
      soft.print(client.state());
      soft.println(F(", will try again in 5 seconds."));
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

I have found one strange thing:
In the mosquitto-logs my Uno/ESP-01 have the IP: 10.0.1.16 (which is also the IP that is shown when checking the connected clients in my AP). However, when i call the function WiFi.localIP() in my Arduino sketch, it says that my local IP is "10.0.1.116". Can this be the reason to why my MQTT-connection fails? I haven't found a way to get around it though...

Any ideas on how to solve this?

Thankful for any help!

Large GET request splits the data

I am reading read a page from my PV inverter.
I get all the web page source but only the first 1460 bytes can be read via client.read().
The next 3 blocks of 1460 bytes, 1270 bytes and 971 bytes are spat out as Trailing Data>>>>
How can I get all the GET to come back via client,read() so I can parse it?


AT+GMR
AT version:0.21.0.0
SDK version:0.9.5

OK
...

SEND OK

sendData: 0 1

OK

SEND OK
New incoming connection - connId: 0
Bytes: 1460
HTTP/1.0 200 OK
Date: Sat, 19 Dec 2015 16:32:03 GMT
Server: Boa/0.94.13
Connection: close
Content-type:text/html;charset=utf-8

<title></title>

<<<<<<<<<<<<<<<<<<<<<
/New incoming connection - connId: 0
Bytes: 1270

Inverter IDCurrent PowerGrid FrequencyGrid VoltageTemperatureDate
404000066544-A W Hz V oC
404000066544-B W Hz V oC
404000066570-A W Hz V oC
404000066570-B W Hz V o<

Trailing data >>>

+IPD,0,1460:sup>C

404000066368-A W Hz V oC
404000066368-B W Hz V oC
404000066775-A W Hz V oC
404000066775-B W Hz V oC
404000066688-A W Hz V oC
404000066688-B W Hz V oC
404000066650-A W Hz V  oC
404000066650-B W Hz V oC
404000066359-A 1 W 49.9 Hz 233 V 31 oC 2015-12-19 18:36:53
404000066359-B 1 W 49.9 Hz 233 V 31 oC 2015-12-19 18:36:53
404000066566-A W Hz V oC
404000066566-B W Hz V oC
404000066767-A

Trailing data >>>

+IPD,0,971:nter> W

 Hz V oC
404000066767-B W Hz V oC
404000066774-A 2 W 49.9 Hz 234 V 29 oC 2015-12-19 18:36:53
404000066774-B 2 W 49.9 Hz 234 V 29 oC 2015-12-19 18:36:53



&copy2013 Altenergy Power System Inc.0,CLOSED
<<<<<<<<<<<<<<<<<<<<<

Slow performances when sending string in flash memeory

WiFiEsp is slow when sending data using the F macro to store strings in flash memory.

client.print(F("<H1>WiFi ALA demo</H1>"));

Works fine when string is declared normally.

client.print("<H1>WiFi ALA demo</H1>");

Busy p

i was wondering why the IP address is all 0.0.0.0
ever come across this?


AT+RST


busy p...

OK
WIFI DISCONNECT
�ü˜Lü�•�þ€=)�œ€=)��ÿ€=�†Ü
ready
WIFI CONNECTED

WIFI GOT IP

AT+CIPAP_CUR?


AT+CIPAP_CUR?

busy p...
+CIPAP_CUR:ip:"0.0.0.0"
+CIPAP_CUR:gateway:"0.0.0.0"
+CIPAP_CUR:netmask:"0.0.0.0"

OK

wifiStartAP command

Hi,

I'm trying to setup an AccessPoint with ESP8266. My problem is related to the scannetwork function. It only works if espmode is 1 (station) or 3 (station+AP). It does not work in espmode=2 (AP).
Therefore, if I setup an AP (espmode=2), there is no way to scan active networks. I modified the line "if (sendCmd(F("AT+CWMODE_CUR=2"))!=TAG_OK)" in EspDrv.cpp to "if (sendCmd(F("AT+CWMODE_CUR=3"))!=TAG_OK)" and everuthing works like a charm.

Would not be this the best way to setup an AP with ESP?
Thanks a lot!

PS: is it possible to have the espmode variable as public instead of private? This is useful in order to check the current esp setup.

TIMEOUT on a GET request to "server"

I'm getting really unpredictable results when running the WifiESPLed sample.

  • It always connects to the network (sometimes after fail/retry)
  • It often fails to start the server (about 50/50)
  • When it does start, I can hit the IP from my browser
  • Sometimes it completes the request, page renders fine (shows me the LED is 0, etc)
  • However, it ALWAYS times out at this point, and disconnects the request.
  • It seems to be in a crashed state at this point too, further requests just timeout at the browser

Here is my output:

[WiFiEsp] Initializing ESP module
[WiFiEsp] Initilization successful - 1.4.0
Attempting to connect to WPA SSID: xxxx
[WiFiEsp] Connected to xxxx
You're connected to the network
SSID: xxxx
IP Address: 192.168.3.41

To see this page in action, open a browser to http://192.168.3.41

[WiFiEsp] Server started on port 80
[WiFiEsp] New client 0
New client
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 0
[WiFiEsp] Disconnecting  0
[WiFiEsp] Disconnecting  0
Client disconnected

Hardware Serial

Sorry if this is an obvious question. I'm going to try this library on an Arduino Mega 2560 and I would like to understand how to use the hardware serial ports. Should I just comment out the SoftWareSerial info and in Setup just go to "Serial1.begin(9600);"? If so, then I am also assuming you can just use any of the Mega UARTs (Serial1, Serial2, Serial3)?

ScanNetwork, not full list

Hello, when use the scanNetworks() it is not showing the full available networks like AT+CWLAP command.

ESP8266WifFi

Hi, this is not like an issue but a question. I had used this library extensively and I am very happy. I developed the project for Mega2560 using the Esp8266. I just tried to compile it for ESP8266 12E Nodemcu and had the following error.
"Arduino\libraries\WiFiEsp\src\utility\EspDrv.cpp:20:26: fatal error: avr/pgmspace.h: No such file or directory.

include <avr/pgmspace.h>"

I want to know if the your library and the Nodemcu are not compatible. I will have to modify many lines of code.

Sorry if I did a stupid question.

Thanks

Unsupported firmware warning

Hello , thank you for this great library.

i upgraded my ESP-01 but i have an error :
Warning: Unsupported firmware

when i write AT+GMR i can see this version : 0018000902

when i use your example codes i have these errors

[WiFiEsp] Warning: Unsupported firmware 
Attempting to connect to WPA SSID: mywifi
[WiFiEsp] Failed connecting to mywifi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.