Network with 1 AP and 4 clients M0 Feather WiFi --> WINC1500

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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);
    }
  }
}

 

ChrisitoxX

Last Edited: Thu. May 31, 2018 - 12:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

If this is about WINC1500...

Quote:

8.3 Limitations
The AP can only support a single associated station. Further connection attempts are rejected.
• The WINC supports WPA2 security feature starting from the firmware version 19.5.x.
• Concurrency (simultaneous STA/P2P and AP mode) is not supported. Prior to activating the AP
mode, the host MCU application must disable the mode that is currently running.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, so much for  the answer :)

Yeah, this module can work like AP mode with only a client :(

So I can imagine that if I have a client, then I can disconnect these client for connect other?

It's maybe time for searching something in the web ^^

ChrisitoxX

Last Edited: Tue. May 22, 2018 - 02:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I have questions. If I stop the AP I have stop the client (WiFi.disconnect() ?), I'm trying to set all that in the loop() but I didn't have the best results. Then I tried to do a request with an interrupt but don't work :(
I just tried to reconnect the client disconnected ...

//APcode
#include <SPI.h>
#include <WiFi101.h>
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)


int status = WL_IDLE_STATUS;
WiFiServer server(20);

void setup() {
  WiFi.setPins(8, 7, 4, 2); // set ATWINC1500
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {}
  Serial.println("Access Point Web Server");
  //WiFi.config();
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  //IP address
  WiFi.config(IPAddress(10, 0, 0, 1));

  // print the network name (SSID);
  Serial.print("Creating access point named: ");
  Serial.println(ssid);

  // Create open network. Change this line if you want to create an WEP network:
  status = WiFi.beginAP(ssid);
  if (status != WL_AP_LISTENING) {
    Serial.println("Creating access point failed");
    // don't continue
    while (true);
  }

  // wait 10 seconds for connection:
  delay(10000);

  // start the web server on port 20
  server.begin();

  // you're connected now, so print out the status
  printWiFiStatus();
}


void loop() {
  // compare the previous status to the current status
  if (status != WiFi.status()) {
    // it has changed update the variable
    status = WiFi.status();
    Serial.println(WiFi.status());
    if (status == WL_AP_CONNECTED) {
      server.begin();
    } else {
      // a device has disconnected from the AP, and we are back in listening mode
      Serial.println("Device disconnected from AP");
    }
  }

  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    if (client.connected()) {           // loop while the client's connected
      char c = '1';                         // read a byte, then
      Serial.write(c);
      // close the connection:
      client.stop();
      Serial.println("client disconnected");
      WiFi.end();
    }
  }

  delay(2000);
  WiFi.config(IPAddress(10, 0, 0, 1));
  status = WiFi.beginAP(ssid);
  delay(10000);
}
//Clientcode
#include <SPI.h>
#include <WiFi101.h>
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)


int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(10, 0, 0, 1);   // numeric IP AP


// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {
  WiFi.setPins(8,7,4,2);
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  //while(!Serial){}
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
  //WiFi.config(ip);
  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 20)) {
    Serial.println("connected to server");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
 
}

ChrisitoxX

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is the client also a WINC1500? I don't know anything about the developing environment you use, however, in the WINC1500 API, a client should get a WiFi callback event M2M_WIFI_RESP_CON_STATE_CHANGED with current state being M2M_WIFI_DISCONNECTED if the WiFi AP shuts down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

yes the client has the WINC1500. I'm trying to do a data  transmission to 4 clients (all with WINC1500) with an AP.

ChrisitoxX

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Not sure I understand what you are saying here - So four clients, all WINC1500, running in the STATION mode, one server WINC1500, running in the Access Point mode, correct? In this case, you can only make one WiFi connection, from one of the four client WINC1500s, to the WINC1500 that is in the AP mode, until this client WINC1500 decides to disconnect its WiFi.  I don't know of any API calls for a WINC1500 that is in the AP mode to disconnect a WiFi client.

 

A TCP/UDP server, assuming the WiFi connect is already made, can disconnect a client and the client can subsequently disconnect the WiFi. Why not just connect all WINC1500s to a WiFi router? If one of them is a TCP server, it should be able to handle multiple socket requests as long as sockets are available. A WINC1500 can support up to 7 TCP sockets and 4 UPD sockets.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, the idea is to do a network for only data transmission, I'm trying without a WiFi router. My project is to controller DotStar string light but I want, for example, to change the color from an Android device. So for to do this update(data) I was think to use a network with this chip, I just saw the WiFi101 library of arduino to make this project. I'm so sorry for my english :(

ChrisitoxX

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,
I tried many things, now the code works really good. But, there is a little issue, so when I send the data 3 times(3 long loop)works good, after that there is something weird, both chips try to connect but the there is a long delay(like 90 sec), then I saw the client's WINC1500 doesn't stop. Why? I don't know.

//AP code
#include <SPI.h>
#include <WiFi101.h>
#include "data_network.h"

char ssid[] = SECRET_SSID;        // network SSID (name)
char pass[] = SECRET_PASS;        // network password (WPA)

int status = WL_IDLE_STATUS;
WiFiServer server(1234);

void setup() {
  WiFi.setPins(8, 7, 4, 2); // Chip WiFi WINC1500 ON
 
  Serial.begin(9600);
  // while (!Serial) {;}

  Serial.println("Access Point...");


  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // AddressIP AP
  WiFi.config(IPAddress(10, 0, 0, 1));

  // print the network name (SSID);
  Serial.print("Creating access point named: ");
  Serial.println(ssid);

  // WAP Network
  status = WiFi.beginAP(ssid, pass);
  Serial.println(WiFi.status());

  while (status == WL_AP_LISTENING) {
    //Serial.println(status);
    Serial.println("Attempting for clients...");
    if (status != WiFi.status())break;  // Out loop when there is a client (time maybe to be more than 10s)
  }

  // start the web server on port 1234
  server.begin();

  // you're connected now, so print out the status
  printWiFiStatus();
}


void loop() {
  // compare the previous status to the current status
  if (status != WiFi.status()) {
    // it has changed update the variable
    status = WiFi.status();

    if (status == WL_AP_CONNECTED) {
      byte remoteMac[6];
      server.begin(); // if there is a Client server start to listen
      // a device has connected to the AP
      Serial.print("Device connected to AP, MAC address: ");
      WiFi.APClientMacAddress(remoteMac);
      Serial.print(remoteMac[5], HEX);
      Serial.print(":");
      Serial.print(remoteMac[4], HEX);
      Serial.print(":");
      Serial.print(remoteMac[3], HEX);
      Serial.print(":");
      Serial.print(remoteMac[2], HEX);
      Serial.print(":");
      Serial.print(remoteMac[1], HEX);
      Serial.print(":");
      Serial.println(remoteMac[0], HEX);
    } else {
      // a device has disconnected from the AP, and we are back in listening mode
      Serial.println("Device disconnected from AP");
    }
  }

  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    unsigned long startTime = millis();
    while (client.connected()) {            // loop while the client's connected
      server.write("hola\n");
      if (millis() - startTime > 10000)     //Time to deconnect the client
      {
        client.stop();                      //stop the client
        Serial.println("client disconnected");
        WiFi.end();                         //turn OFF the WINC1500
        Serial.println("Chip WiFi OFF");
        delay(1000);                        //delay to activate again the AP
        WiFi.config(IPAddress(10, 0, 0, 1));
        status = WiFi.beginAP(ssid, pass);  //listen clients
        //Serial.println(status);
        //delay(10);
        while (status == WL_AP_LISTENING) {
          Serial.println("Attempting for clients...");
          if (status != WiFi.status())break;
        }
        server.begin();
      }
    }
  }
}

void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  / WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
//Client code
#include <SPI.h>
#include <WiFi101.h>
#include "data_network.h"

char ssid[] = SECRET_SSID;    //network SSID (name)
char pass[] = SECRET_PASS;    //network password (WPA)

int status = WL_IDLE_STATUS;

IPAddress server(10, 0, 0, 1);  // numeric IP for AP

WiFiClient client;

void setup() {
  WiFi.setPins(8, 7, 4, 2); //Turn ON WINC1500
  
  Serial.begin(9600);
  //while (!Serial) {; }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    Serial.println(status);
    //delay(10000);
  }
  Serial.println("Connected to wifi");
  printWiFiStatus();

  Serial.println("\nStarting connection to server...");
  // if there is a connection, report back via serial:
  if (client.connect(server, 1234)) {
    client.println();
  }
}


void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    //Serial.println(client.available());
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    //Serial.println(WiFi.status());
    Serial.println("disconnecting from server.");
    client.stop();  //stop client
    //WiFi.disconnect();
    //Serial.println(WiFi.status());
    WiFi.end();    //turn OFF WINC1500
    //Serial.println();
    delay(2000);
    status = WiFi.status();
    Serial.println(WiFi.status());
    
    while (status != WL_CONNECTED) {
      Serial.print("Attempting to connect to SSID: ");
      Serial.println(ssid);
     // WiFi.config(IPAddress(192, 168,10,1));
      
      status = WiFi.begin(ssid, pass);
      if(status != WiFi.status())break;
      Serial.println(status);
      }
      if (client.connect(server, 1234)) {
        client.println();
      }
    }
  }

void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}




With this code I tried to disconnect a client and then connect it again, with this way I can connect many clients!! :)

ChrisitoxX