I currently have two Arduino Zero boards (using the SAMD21 microcontroller), each with an ATWINC1500 wifi module attached. I have established one of these units as a wifi access point with a server running on it, while the other unit is a client that attempts to connect to the access point and then send some data to the server.
As far as I can tell, the access point and the server on the first unit are created correctly. I am able to use telnet on a separate Android device to connect to the access point and send data to the server. Unfortunately, when I attempt to connect to the AP/server using the other Arduino board, it is never successful.
Here is the code I am using on the first board to create the access point and server:
WiFiServer server(23);
WiFiClient client;
void LaunchAccessPoint ()
{
uint8_t begin_ap_status = WiFi.beginAP(access_point_name);
if (begin_ap_status == WL_AP_LISTENING)
{
server.begin();
}
}
void HandleClientConnection ()
{
String result;
client = server.available();
if (client && client.connected() && client.available())
{
while (client.available())
{
result += (char) client.read();
}
client.stop();
}
SerialUSB.println(result);
}
void setup()
{
/* ... some code in this function has been cut for clarity ... */
LaunchAccessPoint();
}
void loop()
{
/* ... some code in this function has been cut for clarity ... */
HandleClientConnection();
}
Meanwhile, here is the code for the client that attempts to connect to the AP/server:
bool ConnectToWifi ()
{
uint8_t wifi_connection_result = 0;
wifi_connection_result = WiFi.begin(wifi_ssid);
return (wifi_connection_result == WL_CONNECTED)
}
void PublishData (const char *json_string)
{
WiFiClient client = WiFiClient();
int client_connect_success = client.connect(IPAddress(192, 168, 1, 1), 23);
if (client_connect_success)
{
int client_bytes_written = client.println(json_string);
client.stop();
}
}
void setup ()
{
/* some code cut for clarity */
ConnectToWifi();
}
void loop()
{
/* some code cut for clarity */
PublishData(some_string);
}
As I said before, if I try using telnet on a computer or phone, it is able to successfully connect to the server and send data. But when I attempt to use my Arduino board to act as the client, the socket gets closed by the server, as if it's actively refusing the connection.
EDIT: On the server side, the line client = server.available();
never returns a client object if server ATWINC is AP and client is the other ATWINC.
Any suggestions? Is there something I am missing or doing wrong? Thanks!
[edit]
After doing some testing, it seems as though the server works if it is not also acting as an access point. This is unfortunate, because I need it to act as the access point and a server.
If anyone has experience getting two ATWINC1500s to talk to each other, where one is both an AP and a server, and the other is a client, any help would be appreciated!
[/edit]