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);
}
إرسال تعليق