Fix WiFi code for ESP8266
This commit is contained in:
parent
34d0902928
commit
203f61c36e
|
@ -5,12 +5,10 @@
|
||||||
* by Starbeamrainbowlabs
|
* by Starbeamrainbowlabs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
|
||||||
char ssid[] = "evenstar-2.4";
|
char ssid[] = "AJ_HullFromHome_F1EAA6E5";
|
||||||
char password[] = "yourPasswordHere";
|
char password[] = "humberbridge";
|
||||||
// The current wifi status
|
|
||||||
int currentStatus = WL_IDLE_STATUS;
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
@ -20,23 +18,15 @@ void setup()
|
||||||
Serial.println("Hello, world!");
|
Serial.println("Hello, world!");
|
||||||
|
|
||||||
// Make sure that WiFi is supported
|
// 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.");
|
Serial.println("Beginning connection sequence.");
|
||||||
while(currentStatus != WL_CONNECTED)
|
while(WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
Serial.print("Attempting to connect to ");
|
Serial.print("Attempting to connect to ");
|
||||||
Serial.print(ssid);
|
Serial.print(ssid);
|
||||||
Serial.print(" - ");
|
Serial.print(" - ");
|
||||||
|
|
||||||
currentStatus = WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
// Wait 10 seconds for the connection to start
|
// Wait 10 seconds for the connection to start
|
||||||
delay(10000);
|
delay(10000);
|
||||||
|
@ -49,7 +39,6 @@ void loop()
|
||||||
{
|
{
|
||||||
delay(1000);
|
delay(1000);
|
||||||
printWiFiInfoLocal();
|
printWiFiInfoLocal();
|
||||||
printWiFiInfoRemote();
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,37 +46,4 @@ void printWiFiInfoLocal()
|
||||||
{
|
{
|
||||||
Serial.print("IP Address: ");
|
Serial.print("IP Address: ");
|
||||||
Serial.println(WiFi.localIP());
|
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(":");
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue