Last active
August 24, 2017 23:17
-
-
Save sabas1080/4de6e1f81b2f0743a8caed41376eba7b to your computer and use it in GitHub Desktop.
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
#include <ESP8266WiFi.h> | |
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[] = "arduino.cc"; | |
// Initialize the Ethernet client object | |
WiFiClient client; | |
void setup() | |
{ | |
// initialize serial for debugging | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
// 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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment