Skip to content

Instantly share code, notes, and snippets.

@SandjayaIV
Created December 9, 2019 08:41
Show Gist options
  • Save SandjayaIV/e37f45492d0818bffc31328c9f526ca1 to your computer and use it in GitHub Desktop.
Save SandjayaIV/e37f45492d0818bffc31328c9f526ca1 to your computer and use it in GitHub Desktop.
Arduino Wifi101
#include <SPI.h>
#include <WiFi101.h>
char ssid[]="YNCREA_LAB";// your network SSID (name)
char pass[]="813nV3nue@";// your network password (use for WPA, or use as key for WEP)
int status =WL_IDLE_STATUS;
WiFiServer server(8000);
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 presenceof 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 SSID: ");
Serial.println(ssid);// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status =WiFi.begin(ssid,pass);// wait 10 seconds for connection:
delay(10000);
}
server.begin();// you're connected now, so print out the status:
printWiFiStatus();
}
void loop() { // listen for incoming clients
WiFiClient client =server.available();
if(client){
Serial.println("new client");
if (client.connected()) {
client.flush();
Serial.println("We have a new client");
client.println("Hello client!");
}
while (client.available()) {
char c = client.read();
Serial.write(c);
}
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
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