-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fda7e19
commit 61aa610
Showing
8 changed files
with
183 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
WiFiEsp example: WebClient | ||
This sketch connects to google website using an ESP8266 module to | ||
perform a simple web search. | ||
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html | ||
*/ | ||
|
||
#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[] = "Twim"; // your network SSID (name) | ||
char pass[] = "12345678"; // your network password | ||
int status = WL_IDLE_STATUS; // the Wifi radio's status | ||
|
||
char server[] = "www.google.com"; | ||
|
||
// 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.connectSSL(server, 443)) { | ||
Serial.println("Connected to server"); | ||
// Make a HTTP request | ||
client.println("GET / HTTP/1.1"); | ||
client.println("Host: www.google.com"); | ||
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |