Hello,
I'm trying to do a network with a AP_server and 4 clients with the board M0 Feather WiFi Adafruit. When I do the network with only the AP and (only) 1 client, the network works very well!!! But the problem is when I try to add more clients in the network. When I try to connect the second client, this don't connect with the network, only the first is connected. I believe that problem is in the code, I don't declare the others clients, I try a lot of ways but I didn't find the best. Can you help me? Thank you
//AP_server #include <SPI.h> #include <WiFi101.h> #include "arduino_secrets.h" char ssid[] = SECRET_SSID; // network SSID (name) char pass[] = SECRET_PASS; // network password (use for WPA, or use as key for WEP) char sequence[] = {'1','2','3'}; int status = WL_IDLE_STATUS; WiFiServer server(200); void setup() { WiFi.setPins(8, 7, 4, 2); status = WiFi.beginAP(ssid, pass); if (status != WL_AP_LISTENING) while (true); // wait 10 seconds for connection: delay(10000); // start the web server on port 80 server.begin(); } void loop() { // compare the previous status to the current status if (status != WiFi.status()) { // it has changed update the variable status = WiFi.status(); } WiFiClient client = server.available(); // listen for incoming clients if (client) { // if you get a client, while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // print it out the serial monitor } for(int i = 0; i < 3; i++){ server.write(sequence[i]); //Serial.write(server.write(sequence[i])); delay(1000); } } // close the connection: client.stop(); } }
//Cients #include <SPI.h> #include <WiFi101.h> #include "arduino_secrets.h" char ssid[] = SECRET_SSID; // your network SSID (name) char pass[] = SECRET_PASS; // your network password (use for WPA) int status = WL_IDLE_STATUS; IPAddress server(192, 168, 1, 1); // numeric IP WiFiClient client; void setup() { //Serial.begin(9600); pinMode(A0, 1); pinMode(A1, 1); pinMode(A2, 1); WiFi.setPins(8, 7, 4, 2); // attempt to connect to WiFi network: while (status != WL_CONNECTED) { status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); } if (client.connect(server, 200)) client.println(); } void loop() { // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); // Serial.write(c); //Serial.println(c); pinMode(6, 1); int pos = c - '0'; //Serial.println(pos); if (pos == 1 || pos == 3) { digitalWrite(A0, HIGH); digitalWrite(A1, LOW); digitalWrite(A2, HIGH); } if (pos == 2 || pos == 4) { digitalWrite(A0, LOW); digitalWrite(A1, HIGH); digitalWrite(A2 , LOW); } // if the server's disconnected, stop the client: if (!client.connected()) { client.stop(); // do nothing forevermore: while (true); } } }