-
-
Notifications
You must be signed in to change notification settings - Fork 214
Wifi example #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Wifi example #109
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino
This file contains hidden or 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,108 @@ | ||
/* | ||
Web client | ||
|
||
This sketch connects to a website (http://example.com) using the WiFi module. | ||
|
||
This example is written for a network using WPA encryption. For | ||
WEP or WPA, change the Wifi.begin() call accordingly. | ||
|
||
Circuit: | ||
* Arduino Portenta H7 | ||
|
||
created 13 July 2010 | ||
by dlf (Metodo2 srl) | ||
modified 31 May 2012 | ||
by Tom Igoe | ||
*/ | ||
|
||
#include <WiFi.h> | ||
|
||
#include "arduino_secrets.h" | ||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||
char ssid[] = SECRET_SSID; // your network SSID (name) | ||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) | ||
int keyIndex = 0; // your network key Index number (needed only for WEP) | ||
|
||
int status = WL_IDLE_STATUS; | ||
// if you don't want to use DNS (and reduce your sketch size) | ||
// use the numeric IP instead of the name for the server: | ||
// IPAddress server(93,184,216,34); // IP address for example.com (no DNS) | ||
char server[] = "example.com"; // host name for example.com (using DNS) | ||
|
||
WiFiClient client; | ||
|
||
void setup() { | ||
//Initialize serial and wait for port to open: | ||
Serial.begin(9600); | ||
while (!Serial) { | ||
; // wait for serial port to connect. Needed for native USB port only | ||
} | ||
|
||
// check for the WiFi module: | ||
if (WiFi.status() == WL_NO_SHIELD) { | ||
Serial.println("Communication with WiFi module failed!"); | ||
// don't continue | ||
while (true); | ||
} | ||
|
||
// attempt to connect to Wifi network: | ||
while (status != WL_CONNECTED) { | ||
Serial.print("Attempting to connect to SSID: "); | ||
Serial.println(ssid); | ||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network: | ||
status = WiFi.begin(ssid, pass); | ||
|
||
// wait 3 seconds for connection: | ||
delay(3000); | ||
} | ||
Serial.println("Connected to wifi"); | ||
printWifiStatus(); | ||
|
||
Serial.println("\nStarting 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 /index.html HTTP/1.1"); | ||
client.print("Host: "); | ||
client.println(server); | ||
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 board'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 hidden or 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,2 @@ | ||
#define SECRET_SSID "" | ||
#define SECRET_PASS "" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@don If you made changes to it, you may want to put your name here. Looks good otherwise.