IP Configuration
This commit is contained in:
142
lib/WiFiEsp/test/BasicTest/BasicTest.ino
Normal file
142
lib/WiFiEsp/test/BasicTest/BasicTest.ino
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
WiFiEsp test: BasicTest
|
||||
|
||||
Performs basic connectivity test and checks.
|
||||
*/
|
||||
|
||||
#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 pwd[] = "12345678"; // your network password
|
||||
char pwdErr[] = "xxxx"; // wrong password
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial1.begin(9600);
|
||||
WiFi.init(&Serial1);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
assertEquals("Firmware version", WiFi.firmwareVersion(), "1.5.2");
|
||||
assertEquals("Status is (WL_DISCONNECTED)", WiFi.status(), WL_DISCONNECTED);
|
||||
assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
|
||||
assertEquals("Check status (WL_CONNECTED)", WiFi.status(), WL_CONNECTED);
|
||||
assertEquals("Check SSID", WiFi.SSID(), ssid);
|
||||
|
||||
IPAddress ip = WiFi.localIP();
|
||||
assertNotEquals("Check IP Address", ip[0], 0);
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
byte mac[6]={0,0,0,0,0,0};
|
||||
WiFi.macAddress(mac);
|
||||
|
||||
Serial.print("MAC: ");
|
||||
Serial.print(mac[5], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1], HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0], HEX);
|
||||
Serial.println();
|
||||
|
||||
assertEquals("Disconnect", WiFi.disconnect(), WL_DISCONNECTED);
|
||||
assertEquals("Check status (WL_DISCONNECTED)", WiFi.status(), WL_DISCONNECTED);
|
||||
assertEquals("IP Address", WiFi.localIP(), 0);
|
||||
assertEquals("Check SSID", WiFi.SSID(), "");
|
||||
assertEquals("Wrong pwd", WiFi.begin(ssid, pwdErr), WL_CONNECT_FAILED);
|
||||
|
||||
IPAddress localIp(192, 168, 168, 111);
|
||||
WiFi.config(localIp);
|
||||
|
||||
assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
|
||||
assertEquals("Check status (WL_CONNECTED)", WiFi.status(), WL_CONNECTED);
|
||||
|
||||
ip = WiFi.localIP();
|
||||
assertNotEquals("Check IP Address", ip[0], 0);
|
||||
|
||||
|
||||
Serial.println("END OF TESTS");
|
||||
delay(60000);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void assertNotEquals(const char* test, int actual, int expected)
|
||||
{
|
||||
if(actual!=expected)
|
||||
pass(test);
|
||||
else
|
||||
fail(test, actual, expected);
|
||||
}
|
||||
|
||||
void assertEquals(const char* test, int actual, int expected)
|
||||
{
|
||||
if(actual==expected)
|
||||
pass(test);
|
||||
else
|
||||
fail(test, actual, expected);
|
||||
}
|
||||
|
||||
void assertEquals(const char* test, char* actual, char* expected)
|
||||
{
|
||||
if(strcmp(actual, expected) == 0)
|
||||
pass(test);
|
||||
else
|
||||
fail(test, actual, expected);
|
||||
}
|
||||
|
||||
|
||||
void pass(const char* test)
|
||||
{
|
||||
Serial.print(F("********************************************** "));
|
||||
Serial.print(test);
|
||||
Serial.println(" > PASSED");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void fail(const char* test, char* actual, char* expected)
|
||||
{
|
||||
Serial.print(F("********************************************** "));
|
||||
Serial.print(test);
|
||||
Serial.print(" > FAILED");
|
||||
Serial.print(" (actual=\"");
|
||||
Serial.print(actual);
|
||||
Serial.print("\", expected=\"");
|
||||
Serial.print(expected);
|
||||
Serial.println("\")");
|
||||
Serial.println();
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
void fail(const char* test, int actual, int expected)
|
||||
{
|
||||
Serial.print(F("********************************************** "));
|
||||
Serial.print(test);
|
||||
Serial.print(" > FAILED");
|
||||
Serial.print(" (actual=");
|
||||
Serial.print(actual);
|
||||
Serial.print(", expected=");
|
||||
Serial.print(expected);
|
||||
Serial.println(")");
|
||||
Serial.println();
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
184
lib/WiFiEsp/test/ClientTest/ClientTest.ino
Normal file
184
lib/WiFiEsp/test/ClientTest/ClientTest.ino
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
WiFiEsp test: ClientTest
|
||||
|
||||
Test client functions.
|
||||
*/
|
||||
|
||||
#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 pwd[] = "12345678"; // your network password
|
||||
|
||||
|
||||
// Initialize the Wifi client library
|
||||
WiFiEspClient client;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial1.begin(9600);
|
||||
WiFi.init(&Serial1);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
bool f;
|
||||
int c;
|
||||
|
||||
|
||||
assertEquals("Check status WL_DISCONNECTED", WiFi.status(), WL_DISCONNECTED);
|
||||
|
||||
assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
|
||||
|
||||
assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
|
||||
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
assertEquals("Ping", WiFi.ping("www.google.com"), true);
|
||||
|
||||
assertEquals("Not connected", client.connected(), false);
|
||||
assertEquals("Connect to server", client.connect("www.brainjar.com", 80), 1);
|
||||
assertEquals("Connected", client.connected(), true);
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// HTTP request without 'Connection: close' command
|
||||
|
||||
client.println("GET /java/host/test.html HTTP/1.1");
|
||||
client.println("Host: www.brainjar.com");
|
||||
client.println();
|
||||
|
||||
// wait for the response
|
||||
long _startMillis = millis();
|
||||
while (!client.available() and (millis()-_startMillis < 2000))
|
||||
{
|
||||
}
|
||||
|
||||
assertEquals("Response received", (millis()-_startMillis < 2000), true);
|
||||
|
||||
f = client.find("<html>");
|
||||
assertEquals("Response check", f, true);
|
||||
if (f)
|
||||
{
|
||||
while( (c = client.read()) > 0)
|
||||
Serial.print((char)c);
|
||||
}
|
||||
|
||||
assertEquals("Connected", client.connected(), true);
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
||||
delay(5000);
|
||||
|
||||
assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
|
||||
|
||||
assertEquals("Connected", client.connected(), true);
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// HTTP request without 'Connection: close' command
|
||||
|
||||
client.println("GET /java/host/test.html HTTP/1.1");
|
||||
client.println("Host: www.brainjar.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
|
||||
// wait for the response
|
||||
_startMillis = millis();
|
||||
while (!client.available() and (millis()-_startMillis < 2000))
|
||||
{
|
||||
}
|
||||
|
||||
assertEquals("Response received", (millis()-_startMillis < 2000), true);
|
||||
|
||||
f = client.find("<html>");
|
||||
assertEquals("Response check", f, true);
|
||||
if (f)
|
||||
{
|
||||
while( (c = client.read()) > 0)
|
||||
Serial.print((char)c);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
||||
assertEquals("Check status WL_CONNECTED", WiFi.status(), WL_CONNECTED);
|
||||
assertEquals("Not connected", client.connected(), false);
|
||||
|
||||
assertEquals("Ping", WiFi.ping("www.google.com"), true);
|
||||
|
||||
assertEquals("Connect", WiFi.disconnect(), WL_DISCONNECTED);
|
||||
assertEquals("Check status WL_DISCONNECTED", WiFi.status(), WL_DISCONNECTED);
|
||||
|
||||
Serial.println("END OF TESTS");
|
||||
delay(30000);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void assertEquals(const char* test, int actual, int expected)
|
||||
{
|
||||
if(actual==expected)
|
||||
pass(test);
|
||||
else
|
||||
fail(test, actual, expected);
|
||||
}
|
||||
|
||||
void assertEquals(const char* test, char* actual, char* expected)
|
||||
{
|
||||
if(strcmp(actual, expected) == 0)
|
||||
pass(test);
|
||||
else
|
||||
fail(test, actual, expected);
|
||||
}
|
||||
|
||||
|
||||
void pass(const char* test)
|
||||
{
|
||||
Serial.print(F("********************************************** "));
|
||||
Serial.print(test);
|
||||
Serial.println(" > PASSED");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void fail(const char* test, char* actual, char* expected)
|
||||
{
|
||||
Serial.print(F("********************************************** "));
|
||||
Serial.print(test);
|
||||
Serial.print(" > FAILED");
|
||||
Serial.print(" (actual=\"");
|
||||
Serial.print(actual);
|
||||
Serial.print("\", expected=\"");
|
||||
Serial.print(expected);
|
||||
Serial.println("\")");
|
||||
Serial.println();
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
void fail(const char* test, int actual, int expected)
|
||||
{
|
||||
Serial.print(F("********************************************** "));
|
||||
Serial.print(test);
|
||||
Serial.print(" > FAILED");
|
||||
Serial.print(" (actual=");
|
||||
Serial.print(actual);
|
||||
Serial.print(", expected=");
|
||||
Serial.print(expected);
|
||||
Serial.println(")");
|
||||
Serial.println();
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
|
||||
48
lib/WiFiEsp/test/EspDebug/EspDebug.ino
Normal file
48
lib/WiFiEsp/test/EspDebug/EspDebug.ino
Normal file
@@ -0,0 +1,48 @@
|
||||
// EspDebug - Test sketch for ESP8266 module
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
// Emulate Serial1 on pins 7/6 if not present
|
||||
#ifndef HAVE_HWSERIAL1
|
||||
#include "SoftwareSerial.h"
|
||||
SoftwareSerial Serial1(6, 7); // RX, TX
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200); // serial port used for debugging
|
||||
Serial1.begin(9600); // your ESP's baud rate might be different
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if(Serial1.available()) // check if the ESP is sending a message
|
||||
{
|
||||
while(Serial1.available())
|
||||
{
|
||||
int c = Serial1.read(); // read the next character
|
||||
Serial.write((char)c); // writes data to the serial monitor
|
||||
}
|
||||
}
|
||||
|
||||
if(Serial.available())
|
||||
{
|
||||
// wait to let all the input command in the serial buffer
|
||||
delay(10);
|
||||
|
||||
// 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);
|
||||
|
||||
// send the read character to the ESP
|
||||
Serial1.print(cmd);
|
||||
}
|
||||
}
|
||||
58
lib/WiFiEsp/test/RingBufferTest/RingBufferTest.ino
Normal file
58
lib/WiFiEsp/test/RingBufferTest/RingBufferTest.ino
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
WiFiEsp test: RingBufferTest
|
||||
|
||||
Test of the RingBuffer class.
|
||||
*/
|
||||
|
||||
#include "WiFiEsp.h"
|
||||
|
||||
RingBuffer buf(5);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Starting tests");
|
||||
|
||||
buf.init();
|
||||
|
||||
buf.push('a');
|
||||
assert(10, buf.endsWith("a"), true);
|
||||
assert(11, buf.endsWith("A"), false);
|
||||
assert(12, buf.endsWith("ab"), false);
|
||||
|
||||
buf.push('b');
|
||||
assert(21, buf.endsWith("a"), false);
|
||||
assert(22, buf.endsWith("A"), false);
|
||||
assert(23, buf.endsWith("ab"), true);
|
||||
|
||||
buf.push('c');
|
||||
buf.push('d');
|
||||
buf.push('e');
|
||||
assert(31, buf.endsWith("abcde"), true);
|
||||
assert(32, buf.endsWith("de"), true);
|
||||
|
||||
buf.push('f');
|
||||
assert(43, buf.endsWith("bcdef"), true);
|
||||
assert(44, buf.endsWith("ef"), true);
|
||||
|
||||
Serial.println("Done");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
void assert(int i, bool x, bool y)
|
||||
{
|
||||
if (x!=y)
|
||||
{
|
||||
Serial.print ("FAIL ");
|
||||
Serial.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user