May 18, 2015

ESP8266 WiFi library

After several nights spent developing and tweaking I finally have a working ESP8266 WiFi library called WiFiEsp.
The main characteristic of the WiFiEsp library is that is fully compatible with the standard library for the Arduino WiFi shield. This gives a cheap alternative to the expensive WiFi shield to connect Arduino to the Internet.
It uses hardware Serial1 if exists or emulate a second serial port on pins 6 and 7.
You can download WiFiEsp library from GitHub.
Please give it a try and tell me what you think.

Here is a small sketch that connects to a WiFi network.


#include "WiFiEsp.h"

// Emulate Serial1 on pins 7/6 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif

char ssid[] = "Twim";            // your network SSID (name)
char pass[] = "12345678";        // your network password

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

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

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

  // you're connected now, so print out the data:
  Serial.println("You're connected to the network");
  
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  delay(10000);
}


5 comments:

  1. Hi,

    1. how I can edit default pin (6/7) of software serial without edit the source code of library?
    2. can you add demo about how use the library to send data (for example using thingspeak website)?

    Thanks

    ReplyDelete
  2. Hi!! I try to use this code, it Works succesfully!! :D
    But the serial port says -> Warning: This firmware has not been tested!!!!
    How can I fix it?

    ReplyDelete
    Replies
    1. Hi,
      I have published an article to explain how to flash the new firmware.
      http://yaab-arduino.blogspot.com/2015/12/flashing-esp8266-firmware-arduino.html

      Delete
  3. Hi!

    I got cheap eay "WangTangze" ESP shield working with Arduino using this libary. Firmware looks like 1.3, but having only one ESP shield, maybe I'll leave it there ;)

    My procedure was:
    1. all shield switches off
    2. Arduino MiniUSB connected to debug port
    a) to verify communication (115200 8N1) with the ESP
    b) to change baud rate using command "AT+UART_DEF=9600,8,1,0,0"
    3. bend port 0 and port 1 pins (RX and TX) of the shield so that they don't go to Arduino header. They are connected to internal level conversion but to which pins - beats me...
    4. connect jumper wires from Arduino port 6 directly to debug TX and Arduino port 7 through resistor level conversion to debug RX
    5. try out examples
    6. smile :)

    Are there restrictions in handling server requests and making client calls at the same time? One connection at a time?

    Thanks!

    ReplyDelete
  4. This is exactly the project I have been looking for. Unfortunately I think I blew out the XMit on my only ESP8266. Good news is I have more on the way and am looking forward to trying out the ESP8266 WiFi library as soon as they arrive.

    Thx,
    TekMason

    ReplyDelete