Fix WiFi code for ESP8266

This commit is contained in:
Starbeamrainbowlabs 2016-10-06 19:36:44 +01:00
parent 34d0902928
commit 203f61c36e
1 changed files with 5 additions and 49 deletions

View File

@ -5,12 +5,10 @@
* by Starbeamrainbowlabs
*/
#include <WiFi.h>
#include <ESP8266WiFi.h>
char ssid[] = "evenstar-2.4";
char password[] = "yourPasswordHere";
// The current wifi status
int currentStatus = WL_IDLE_STATUS;
char ssid[] = "AJ_HullFromHome_F1EAA6E5";
char password[] = "humberbridge";
void setup()
{
@ -20,23 +18,15 @@ void setup()
Serial.println("Hello, world!");
// Make sure that WiFi is supported
Serial.print("Testing for WiFi support - ");
if(WiFi.status() == WL_NO_SHIELD)
{
Serial.println("failed!");
Serial.println("WiFi shield not present :-(");
while(true) { delay(1000); }
}
Serial.println("success.");
Serial.println("Beginning connection sequence.");
while(currentStatus != WL_CONNECTED)
while(WiFi.status() != WL_CONNECTED)
{
Serial.print("Attempting to connect to ");
Serial.print(ssid);
Serial.print(" - ");
currentStatus = WiFi.begin(ssid, password);
WiFi.begin(ssid, password);
// Wait 10 seconds for the connection to start
delay(10000);
@ -49,7 +39,6 @@ void loop()
{
delay(1000);
printWiFiInfoLocal();
printWiFiInfoRemote();
delay(1000);
}
@ -57,37 +46,4 @@ void printWiFiInfoLocal()
{
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
Serial.print("MAC Address: ");
byte macAddress[6];
WiFi.macAddress(macAddress);
printMac(macAddress);
}
void printWiFiInfoRemote()
{
Serial.print("Current Wifi network:");
Serial.print(WiFi.SSID());
Serial.print(" (");
byte macAddress[6];
WiFi.macAddress(macAddress);
printMac(macAddress);
Serial.println(")");
}
void printMacPart(byte& macPart, bool end);
void printMac(byte macAddress[])
{
for(int i = 5; i >= 0; --i)
{
printMacPart(macAddress[i], i == 0 ? true : false);
}
}
void printMacPart(byte& macPart, bool end)
{
Serial.print(macPart,HEX);
if(!end) Serial.print(":");
}