Hi to all,
as part of other projects, i need a LED turned on when a device is connected to the AccessPoint. The LED should turn off, after disconnecting that device from the AP.
After reset the WiFi status = 7.
After connecting a device to the AP, the WiFi status = 8.
After disconnecting that device from the AP, the WiFi status remains 8.
I use this code for checking the WiFi status and switching the LED:
#include "WiFiS3.h"
char ssid[] = "CheckAccessPoint";
char pass[] = "";
int keyIndex = 0;
int led = LED_BUILTIN;
int status = WL_IDLE_STATUS;
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Serial.begin(9600);
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
while (true);
}
WiFi.config(IPAddress(192,168,1,1));
Serial.println("Creating access point with UNO R4 WiFi... please wait!");
status = WiFi.beginAP(ssid, pass);
if (status != WL_AP_LISTENING) {
Serial.println("Creating access point failed");
while (true);
}
delay(2500);
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP : ");
Serial.println(ip);
Serial.println("You may now connect a device to this AP...");
}
void loop() {
if (status != WiFi.status()) {
status = WiFi.status();
if (status != WL_AP_CONNECTED) {
Serial.println("No Device connected to AP");
digitalWrite(13, LOW);
}
if (status == WL_AP_CONNECTED) {
Serial.println("Device connected to AP");
digitalWrite(13, HIGH);
}
else {
Serial.println("Device disconnected from AP");
digitalWrite(13, LOW);
}
}
}
Any ideas whats wrong here?