Hey all,
I have the following scenario:
- Arduino Nano 33 IoT with a NINA W-102 wifi/ble module. This board is acting as a wifi access point and a web server.
- Custom board, but similar to an Arduino Zero, with a SAMD21 microcontroller and an ATWINC1500 wifi module. This board is acting as a wifi client.
All I want to do is have the 2nd board connect to the Nano's web server, send a string, and then disconnect. The Nano only needs to do a Serial print of the string it receives from the web client. Unfortunately, I am having some serious issues with the client being able to connect to the server. To put it simply - it just isn't connecting. But it is connecting to the access point.
Here is my access point/server code which is running on the Nano 33 IoT. It is very similar to the code in the example "AP_SimpleWebServer" sketch for the Nano, except it's been simplified a bit:
#include <SPI.h>
#include <WiFiNINA.h>
WiFiServer server(80);
int wifi_status;
void setup()
{
//Begin serial communication
SerialUSB.begin(115200);
//Countdown to give user enough time to open Arduino serial monitor
for (int i = 10; i > 0; i--)
{
SerialUSB.println(i);
delay(1000);
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println("Communication with WiFi module failed!");
while(true);
}
else
{
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION)
{
SerialUSB.print("Current firmware version: ");
SerialUSB.println(fv);
SerialUSB.print("Expected firmware version: ");
SerialUSB.println(WIFI_FIRMWARE_LATEST_VERSION);
SerialUSB.println("Please upgrade the firmware");
}
//Print a message to the user
SerialUSB.println("Launching access point: HabiTrak_Gateway");
//Start the wifi access point
int status = WiFi.beginAP("HabiTrak_Gateway");
if (status != WL_AP_LISTENING)
{
SerialUSB.println("FAILED to create access point");
while(true);
}
else
{
SerialUSB.println("SUCCESSFULLY created access point");
}
}
}
void loop()
{
if (wifi_status != WiFi.status())
{
wifi_status = WiFi.status();
if (wifi_status == WL_AP_CONNECTED)
{
//a device has connected to the AP
SerialUSB.println("Device connected to AP");
}
else
{
//a device has disconnected from the AP, and we are back in listening mode
SerialUSB.println("Device disconnected from AP");
}
}
//Check if a client has connected to the server
WiFiClient client = server.available();
//If we have a client
if (client)
{
SerialUSB.println("Client connected to server");
//Read the message from the client and print it to the serial monitor
while (client.connected())
{
if (client.available())
{
char c = client.read();
SerialUSB.write(c);
}
}
//Close the connection to the client
client.stop();
SerialUSB.println("Client disconnected from server");
}
}
Now, here is the code running on the client board (custom board, but similar to a Zero - has a SAMD21 and an ATWINC1500):
#include <SPI.h>
#include <WiFi101.h>
#define WINC_IRQ 6 //Digital input for the ATWINC1500 interrupt output.
#define WINC_SS A1 //Digital output for the ATWINC1500 SPI slave select.
#define WINC_RESET 31 //Digital output for the ATWINC1500 reset input.
#define WINC_EN 30 //Digital output for the ATWINC1500 enable input.
#define WINC_WAKE 27 //Digital output for the ATWINC1500 wake input.
char ssid[] = "HabiTrak_Gateway"; // your network SSID (name)
int status = WL_IDLE_STATUS;
WiFiClient client;
void setup()
{
//Initialize serial communication
SerialUSB.begin(115200);
//Countdown sequence to allow user to open Arduino serial monitor
for (int i = 10; i > 0; i--)
{
SerialUSB.println(i);
delay(1000);
}
//Set the pins being used for the wifi module
WiFi.setPins(WINC_SS, WINC_IRQ, WINC_RESET, WINC_EN);
//Connec to the wifi network
SerialUSB.println("Attempting to connect to network...");
SerialUSB.print("SSID: ");
SerialUSB.println(ssid);
status = WiFi.begin(ssid);
if (status != WL_CONNECTED)
{
SerialUSB.println("Couldn't get a wifi connection");
//loop forever
while(true)
{
//empty
}
}
else
{
SerialUSB.println("Connected to wifi access point");
SerialUSB.println("Attempting to connect to server");
//Attempt to connect to the server
if (client.connect(IPAddress(192, 168, 1, 1), 80))
{
SerialUSB.println("Client successfully connected to server.");
//Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
}
else
{
SerialUSB.println("Client FAILED to connect to server.");
}
}
}
void loop()
{
//empty
}
Here is the Serial output I am receiving from the access point on the Nano:
Launching access point: HabiTrak_Gateway
SUCCESSFULLY created access point
Device disconnected from AP
Device connected to AP
And here is the Serial output from the client:
Attempting to connect to network...
SSID: HabiTrak_Gateway
Connected to wifi access point
Attempting to connect to server
Client FAILED to connect to server.
Any suggestions on what I may be doing wrong? As far as I can tell, this is a minimal example, and there isn't anything "out of the ordinary" in what I am doing.
Also, as another note of interest: if I use two of my custom boards (the board similar to the Zero with an ATWINC1500), and have one act as the access point/server and the other act as the client, then this works perfectly. So it seems to me that the issue is the Nano 33 IoT board acting as the access point/server.
Any help would be appreciated. Thank you!