I want to turn my Arduino MKR1000 into an Access Point. My code is the following:
#include <SPI.h>
#include <WiFi101.h>
#define PubNub_BASE_CLIENT WiFiClient
#include <PubNub.h>
WiFiServer server(80);
char ssid[] = "MKR1000";
int status = WL_IDLE_STATUS;
void setup() {
delay(1000);
Serial.begin(9600);
Serial.print("Creating access point named: ");
Serial.println(ssid);
if (WiFi.beginAP(ssid) != WL_CONNECTED) {
Serial.println("Creating access point failed");
while (true);
}
server.begin();
printStatus();
}
void loop() {
}
void printStatus() {
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
Serial.print("To connect, join the network and open a browser to http://");
Serial.println(ip);
}
After uploading this, in the serial monitor I get this:
Creating access point named: MKR1000
Creating access point failed
I'm new to this so I really don't know what's the problem. I hope someone knows what's going on.
Thank you in advance.
-
Hopefully you mean you want the board to function in AP mode for connected clients to exchange messages specifically with it. Trying to actually make it a wifi access point in the sense of a wifi router is not a viable idea.Chris Stratton– Chris Stratton2018年04月04日 16:58:49 +00:00Commented Apr 4, 2018 at 16:58
-
Yeah sorry, that's what I meant.user9026955– user90269552018年04月06日 14:50:49 +00:00Commented Apr 6, 2018 at 14:50
1 Answer 1
I found this reference for Wifi.beginAP()
in the Wifi101 library, which I hope is the correct one - apologies if it's not.
It says that beginAP()
returns either WL_AP_LISTENING
or WL_CONNECT_FAILED
, so checking for WL_CONNECTED
is not sensible.
Try this:
if (WiFi.beginAP(ssid) != WL_AP_LISTENING) {
Serial.println("Creating access point failed");
while (true);
}