I'm trying to set up two Feather WiFi M0s, one as an Access Point Host and one as a Client, so that the Client one can connect to the Host one and send and receive data with the Host.
I seem to be successful in setting up the Host. When it's running I can even see it's name on the list of available WiFi connections as reported on my PC. And when I run the client Feather I have it do a scan for connections and sure enough it reports that other Feather that's running as a Host.
When I run the Client Feather it reports that it successfully connects to the Host, and the Host reports that it is now connected to the Client, by reporting its WiFi.status as WL_AP_CONNECTED. So I SEEM to have a successful connection both from the Client's and the Host's perspectives.
Having made the connection with the Host, the Client Feather then sends some data using the following code:
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write("BLINK");
Udp.endPacket();
and diagnostics on the Client indicates that it successfully sent the right number of bytes.
BUT BUT BUT, I can't figure out how to actually RECEIVE the data on the Host Feather.
I tried using a Udp as in:
Udp.parsePacket();
and that always returns zero, i.e. no data available.
I tried using:
WiFiClient client = server.available();
and that always indicates no server available.
SO I'M STUMPED. What might I be doing wrong?
Following is the major code for the Host side, with comments throughout indicating what's working and what's not.
#include <SPI.h>
#include <WiFi101.h>
char ssidWiFiAccessPoint[] = "YabbaDoo777";
int status = WL_IDLE_STATUS;
void setup()
{
//Configure pins for Adafruit ATWINC1500 Feather
WiFi.setPins(8,7,4,2);
// Check for the presence of the shield
Serial.print("WiFi hardware: : ");
if (WiFi.status() == WL_NO_SHIELD)
{
Serial.println("NOT PRESENT : UNABLE TO CONTINUE PROGRAM");
return; // don't continue. I actually don't think that this causes it to "not continue".
}
Serial.println("DETECTED"); // this shows that the WiFi circuitry is present.
// And indeed it is present.
WiFi.beginAP(ssidWiFiAccessPoint);
// Start up this Feather as an Access Point.
status = WiFi.beginAP(ssidWiFiAccessPoint); // i.e. as YabbaDoo777
if (status != WL_AP_LISTENING)
{
Serial.println("Creating access point FAILURE");
// don't continue
while (true);
}
else
{
Serial.println("Created Access Point SUCCESS");
}
// wait 10 seconds to complete the connection:
delay(10000);
// And indeed it is successful doing the WiFi.beginAP(ssidWiFiAccessPoint);
// In fact I can see this WiFi Access Point, i.e. YabbaDoo777, via my PC when I
// use it to show the list of available WiFi access points.
} // END OF setup
void loop()
{
status = WiFi.status();
if (status == WL_AP_CONNECTED)
{
Serial.println("We HAVE A CONNECTION");
// We do indeed get here as soon as my OTHER Feather, which is set up to attempt
// a connection to THIS Feather, by doing a WiFi.begin(ssidWiFiAccessPoint);
// over on that OTHER Feather.
// That OTHER Feather then repeatedly sends out data (presumably to THIS Feather)
// using the following sequence
// Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
// Udp.write("BLINK");
// Udp.endPacket();
// Diagnostics over on that OTHER Feather indicates that it did indeed send 5 bytes
// BUT it shows Udp.remoteIP() as 0,0,0,0 and Udp.remotePort() as 0
// so it seems sometyhing's not quite right over there.
// THE QUESTION now is HOW DO I **RECEIVE** the data that was sent???
// I TRIED setting up a Udp on THIS Feather and doing...
Udp.parsePacket();
// but that always returns 0 as the packet size, so apparently nothing received.
// I also tried setting up a server and doing...
WiFiClient client = server.available();
// BUT client always come back indicating that no client is available.
// SO WHAT DO I DO to receive the data being sent by that other Feather, which SEEMS
// to have successfully connected to THIS Feather and SEEMS to be successfully sending
// some data??
}
}