Giter Site home page Giter Site logo

wifi's Introduction

WiFi Library for Arduino

Check Arduino status Compile Examples status Spell Check status

With the Arduino WiFi Shield, this library allows an Arduino board to connect to the internet.

For more information about this library please visit us at http://www.arduino.cc/en/Reference/WiFi

License

Copyright (c) 2011-2014 Arduino LLC. All right reserved. Copyright © 2006-2008, Atmel Corporation All rights reserved. Copyright (c) 2001-2004 Swedish Institute of Computer Science. Copyright (c) 2009-2010, H&D Wireless AB All rights reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

wifi's People

Contributors

aentinger avatar agdl avatar cmaglie avatar damellis avatar dependabot[bot] avatar dschulz avatar facchinm avatar fede85 avatar jacobhylen avatar karlsoderby avatar mlafauci avatar per1234 avatar pnndra avatar rstephan avatar shfitz avatar tigoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wifi's Issues

read(buf, len) bug....Found error in code...

From @glennkreisel on December 21, 2013 6:29

UPDATE*** I have fixed this code in the udp_dev version..

in ard_utils.c

bool getTcpData(uint8_t sock, void** payload, uint16_t* len)
{
        tData* p = NULL;
        p = get_pBuf(sock);
        if (p != NULL)
        {
                *payload = p->data;
                *len = p->len;
                return true;
        }
        return false;
}

This function should return only the unread contents but instead the whole buffer of old and new data is returned. Even though the read(buf, len) from arduino only asks for 10 bytes. This should accept a LENGTH var and return the data at the current p->idx location up to end of buffered data or LENGTH reached...
This makes the WiFi code on arduino fail for wificlient.read(buf, len)..
So currently you can ONLY read one byte at a time and it is very slow with all the SPI traffic for each byte.

This is called in: ard_spi.c
This routine should accept another param of LENGTH from the arduino and only read that many bytes in the call to GetTcpData.

cmd_spi_state_t get_databuf_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_t* count) {

        uint8_t* data;
        uint16_t len;

    CHECK_ARD_NETIF(recv, reply, count);

    if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
    {
            if (getTcpData((uint8_t)recv[4], (void**)&data, &len))
            {
                    CREATE_HEADER_REPLY(reply, recv, PARAM_NUMS_1);
                    PUT_BUFDATA_INT(data, len, reply, 3);
                    END_HEADER_REPLY(reply, 3+len+2+1, *count);
                    freeTcpData((uint8_t)recv[4]);
            }else{
                    CREATE_HEADER_REPLY(reply, recv, PARAM_NUMS_0);
                    END_HEADER_REPLY(reply, 3, *count);
            }
    }
    return SPI_CMD_DONE;
}

Copied from original issue: arduino/Arduino#1752

WiFi server uses only one socket

From @SurferTim on December 3, 2013 13:22

The wifi shield library apparently uses only one socket, and that one poorly. The function below displays the state of each of the 4 sockets, and the port number if a server.

The first number is the status of that socket.
-1 = available
0 to 3 = used

The second is the port.

When I start the server and call this function, I get this
0 80
-1 0
-1 0
-1 0

After the first request from a client, I get this
-1 80
-1 0
-1 0
-1 0

That is indicating to me the server is not starting a second socket listening when a client connects on the first as does the ethernet shield.

Also note that socket 0 is now available after the first request. That seems like a bug to me.

I would expect this after the first client request
-1 0
1 80
-1 0
-1 0

I am getting wrong image downloads and corrupted images using the server library. I think this may be related to the use of only one socket.

Or am I seeing this incorrectly?

void ShowSockStatus() {
  for(int x = 0; x < MAX_SOCK_NUM; x++) {
    Serial.print(WiFi._state[x]);    
    Serial.print("  ");
    Serial.println(WiFi._server_port[x]);    
  }
}

Copied from original issue: arduino/Arduino#1715

WiFi Shield - Static IP addresses - WiFi.config(ip) and wrong endianness

From @ankitdaf on July 26, 2013 22:30

I just checked, there is an issue with the WiFi shield, a simple issue that is causing a lot of pain.

The endian-ness of the parameter is somehow wrong.

For example, I gave it an ip-address of 192.168.0.104.
Its equivalent uint32 value is 3232235624 since
2^24 × 192 + 2^16 × 168 + 2^8 × 0 + 120 = 3232235640

However, when I call WiFi.begin, the wifi status output is as below :
IP Address: 120.0.168.192

Copied from original issue: arduino/Arduino#1520

How to debug WiFi connection problems? WiFi.status() always return 6

Problem:
I am using a RPi for a WiFi access point server. I can connect any other device to it and I can connect the Xiao ESP32C3 to a FreshTomato router, But the Arduino will not connect to the RPI wifi. WiFi.status() always return 6, DISCONNECT.
Yes it is the combination of the RPI and the WiFI on the ESP32C3. And it is probably the RPi fault. But because every other device connects to the RPi, I have no clue what is wrong with the configuration.
The arduino-ide is too basic for me, too much is hidden from the developer, great for beginners cookie cutter development, bad for complex debugging.

Details:
I put the RPi in "g" mode and that forces 2.4 band.

Request;
I what debug "print" statement to function. And I am able to add debug prints.
How do I setup arduino-ide to include a local git repo as source? ( clone and use this repo )?
Any suggestion on a reason? Or where to look in the Wifi protocol.

I am going to try no security on the WiFi while I am waiting.

WiFiUdp read() fails when repeatedly called with two arguments

From @fpoto on October 26, 2013 16:17

I use repeated WiFiUdp.read() calls to read data from a single received packet.

In this scenario, read() without arguments works as expected, but fails when called with two arguments (buffer and length).

The gist at https://gist.github.com/fpoto/7171230 demonstrates the bug: when the bufl is set to 0 five NTP requests are sent and the response received. This is the expected serial output:

Attempting to connect to SSID: xxxxxxxx connected
UTC time: 1382804072
UTC time: 1382804074
UTC time: 1382804076
UTC time: 1382804078
UTC time: 1382804080

When bufl is set to a different number read() does not work. Everything should work with values of bufl set to 1, 2, 4, 8, 16 or 32. This is the observed output with any of those values:

Attempting to connect to SSID: xxxxxxxx connected
wrong time
UTC time: 2085978495
wrong time
UTC time: 2085978495
wrong time
UTC time: 2085978495
wrong time
UTC time: 2085978495
wrong time
UTC time: 2085978495

Copied from original issue: arduino/Arduino#1644

WiFiClient read method does not return readed length

From @bondarchook on August 21, 2014 21:48

In WiFiClient class read method implementation call getDataBuf and pass pointer to to _size variable
getDataBuf will return readed length in to it. But this length will not propagate out of WiFiClient::read method because size parameter is not a pointer and and also this uint16_t _size = size;

int WiFiClient::read(uint8_t* buf, size_t size) {
  // sizeof(size_t) is architecture dependent
  // but we need a 16 bit data type here
  uint16_t _size = size;
  if (!ServerDrv::getDataBuf(_sock, buf, &_size))
      return -1;
  return 0;
}

i think WiFiClient::read should get pointer to uint16_t and path it directly to getDataBuf
so after call size actualy has nember of readed bytes

int WiFiClient::read(uint8_t* buf, uint16_t* size) {
  if (!ServerDrv::getDataBuf(_sock, buf, size))
      return -1;
  return 0;
}

Copied from original issue: arduino/Arduino#2251

WiFi.disconnect is not working

Hi,

Testing with UNO rev3 and official wifi shield (firmware version1.1.0).

When I call WiFi.disconnect():

  • the green led (link) from the wifi shield turns off and the red led (error) turns on. At this point Wifi.status returns WL_CONNECT_FAILED.

  • After 2 seconds or so, error LED turns off, and link LED turns on. Wifi.status returns WL_CONNECTED.

Seems like the issue is around since 2012, wanted to document it on the source, maybe someone has an idea or a workaround.

Unused password in "WiFiUdpSendReceiveString" example

should be:

status = WiFi.begin(ssid, pass);

Although the code is valid for an open access point, the presence of this line in the sketch clearly indicates the sketch was intended for use with a WPA encrypted access point:

char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)

The user will be confused to find the board is unable to connect to the access point even though they set the correct password.

WiFi shield library usage does not preserve analogReference?

From @mfkrzeminski on February 22, 2015 22:50

A genuine Uno with WiFi shield, both MCU and WIFI chips updated to latest firmware
1.6.0 IDE with default associated libraries

A program that is pulling an aeronautical meteo observation (METAR) via HTTP GET and
then displays it on the 4x20 LCD screen along with local baro and temp readings.
Code makes use of WiFi, SPI and LiquidCrystal unmodified libs.

Apparently, after first pass of the HTTP GET request the read analog values all change (to unreliable, much-too-high ones).

I have noticed this can be cured only by reapplying the DEFAULT (my sensors are 5V) analogReference after the httpRequest routine is exited (this one actually comes wholly from the examples included with the IDE so not worth quoting it).

By trial and error it seems that the value gets changed to INTERNAL.

A real bug or i am doing something wrong here? Quite funny as i did not expect the WiFi library
to interact with the analog ports by itself.

Copied from original issue: arduino/Arduino#2679

WiFiUdpSendReceiveString password variable missing from connection.

From @Sebthepleb on March 21, 2014 3:27

There is an issue with the WiFiUdpSendReceiveString example code.

All the example WiFi codes I have looked at use the following line to connect:

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);

Now, with the WiFiUdpSendReceiveString example code, it seems the intention was similar, but the password variable has been missed.

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid);

I believe that this code needs to be changed to include the password variable, or the comment needs to be changed to explain that the connection is for an open network.

Copied from original issue: arduino/Arduino#1946

WiFiUdp stop() does not release UDP socket

From @fpoto on October 24, 2013 8:4

This is apparently a bug, described in some detail at http://forum.arduino.cc//index.php?topic=194991.0.

In short, if I have no problems with this pseudo-code:

begin();
for (;;) {
  sendrequest();
  getreply();
  delay();
}

which has worked reliably for hours with a request every ten seconds, but this one does not work:

for (;;) {
  begin();
  sendrequest();
  getreply();
  stop();
  delay();
}

In this second case, the program correctly receives the first reply, but fails from the second time on. Additionally, it seems that stop() does not deallocate the internal structures, because begin() fails from the fifth time on, meaning that there are no more sockets available.

I can provide an example trimmed down sketch if necessary.

Copied from original issue: arduino/Arduino#1637

WiFiClient.stop doesn't discard any remaining data in the read buffer [imported]

From @cmaglie on November 15, 2012 19:2

This is Issue 1030 moved from a Google Code project.
Added by 2012-09-03T18:31:07.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium

Original description

If you close a connection before you've read all the data left in the read buffer, that data seems to stay around until the next time that socket is used, and gets incorrectly delivered as data having been read in the new connection.

You can see it happening by trying the WiFiDatastreamUpload example in the Cosm library https://github.com/amcewen/Cosm-Arduino - the first upload will succeed (or if you've not set the API key or feed id correctly, fail with a -40x error code) and subsequent attempts will fail with an error of -4 (which the HttpClient library returns if it doesn't understand the response - because it's being fed data from the previous request)

Adding a call to flush() during stop() seems to fix the problem.

void WiFiClient::stop() {

if (_sock == 255)
return;

  • flush();
    ServerDrv::stopClient(_sock);

    unsigned long start = millis();

    // wait a second for the connection to close
    while (status() != CLOSED && millis() - start < 1000)
    delay(1);
    _sock = 255;
    }

Copied from original issue: arduino/Arduino#1030

WiFi shield client does not release socket on connect fail (with fix)

From @SurferTim on December 5, 2013 10:57

The wifi shield client code is not releasing the socket when the connection fails. This results in the client using all the sockets in 4 failed attempts, and the connection will fail until the Arduino is reset/rebooted.
IDE v1.0.5 and v1.5.5.
Here is the fix. This is in WiFiClient.cpp

int WiFiClient::connect(IPAddress ip, uint16_t port) {
    _sock = getFirstSocket();
    if (_sock != NO_SOCKET_AVAIL)
    {
        ServerDrv::startClient(uint32_t(ip), port, _sock);
        WiFiClass::_state[_sock] = _sock;

        unsigned long start = millis();

        // wait 4 second for the connection to close
        while (!connected() && millis() - start < 10000)
            delay(1);

        if (!connected())
    {

// Add this
            WiFiClass::_state[_sock] = -1;
// end of add

            return 0;
        }
    }else{
        Serial.println("No Socket available");
        return 0;
    }
    return 1;
}

Copied from original issue: arduino/Arduino#1720

WiFi library getSocket function incorrect

From @SurferTim on December 11, 2013 11:45

The way the getSocket() function allocates sockets is incorrect. It uses the wrong array to determine availability. This will cause errors if using a client connection with any of the listening protocols (udp and tcp server). This is in WiFi.cpp.
IDE v1.0.5 and v1.5.5.

uint8_t WiFiClass::getSocket()
{
    for (uint8_t i = 0; i < MAX_SOCK_NUM; ++i)
    {
        if (WiFiClass::_server_port[i] == 0)
        {
             return i;
        }
    }
    return NO_SOCKET_AVAIL;
}

This is the function I currently use, and it works good. It uses the state array instead. This is the same variable array that the client socket allocation uses.

uint8_t WiFiClass::getSocket()
{
    for (uint8_t i = 0; i < MAX_SOCK_NUM; ++i)
    {
        if (WiFiClass::_state[i] == 0)
        {
             return i;
        }
    }
    return NO_SOCKET_AVAIL;
}

Copied from original issue: arduino/Arduino#1732

WiFiUdp write() does not work when repeatedly writing single bytes

From @fpoto on October 26, 2013 0:37

Writing a buffer with a single call to WiFiUdp.write() works, while writing that same buffer one byte at a time does not.

The gist at https://gist.github.com/fpoto/7163904 demonstrates the problem.

Expected output with allTogether set to true:

Attempting to connect to SSID: xxxxxxxx connected
UTC time: 1382745247
UTC time: 1382745249
UTC time: 1382745251
UTC time: 1382745254
UTC time: 1382745257

Expected output with allTogether set to false:

Attempting to connect to SSID: xxxxxxxx connected
endPacket successful
request failed

You may notice that when it fails it also stops looping. I did not investigate why.

Copied from original issue: arduino/Arduino#1642

bad behaviour of WiFiClient when writing one byte at a time

From @fpoto on December 2, 2013 16:18

I am trying to set up a WiFi web server following one of many tutorials around there. I get terrible performance with this code:

# include <Streaming.h>
...
client << F("HTTP/1.1 200 OK") << endl
         << F("Content-Type: text/html") << endl
         << F("Connection: keep-alive") << endl << endl;
// send web page
webFile = SD.open("index.htm"); // open web page file
if (webFile)
    while(webFile.available())
        client.write(webFile.read()); // send web page to client
webFile.close();
...

As you see, one byte at a time is read from a file on SD card and is immediately written to the TCP stream. What happens is strange. This is an excerpt of a tcpdump where the timing of each packet is relative to the previous packet:

00:00:02.030797 IP arduino.www > casapot.38839: Flags [P.], seq 199:231, ack 8, win 2041, length 32
00:00:00.000043 IP casapot.38839 > arduino.www: Flags [.], ack 231, win 5840, length 0
00:00:00.001829 IP arduino.www > casapot.38839: Flags [P.], seq 231:232, ack 8, win 2041, length 1
00:00:00.000047 IP casapot.38839 > arduino.www: Flags [.], ack 232, win 5840, length 0
00:00:02.030607 IP arduino.www > casapot.38839: Flags [P.], seq 232:264, ack 8, win 2041, length 32
00:00:00.000049 IP casapot.38839 > arduino.www: Flags [.], ack 264, win 5840, length 0
00:00:00.001546 IP arduino.www > casapot.38839: Flags [P.], seq 264:265, ack 8, win 2041, length 1
00:00:00.000033 IP casapot.38839 > arduino.www: Flags [.], ack 265, win 5840, length 0
00:00:02.030799 IP arduino.www > casapot.38839: Flags [P.], seq 265:297, ack 8, win 2041, length 32
00:00:00.000094 IP casapot.38839 > arduino.www: Flags [.], ack 297, win 5840, length 0
00:00:00.002027 IP arduino.www > casapot.38839: Flags [P.], seq 297:298, ack 8, win 2041, length 1
00:00:00.000092 IP casapot.38839 > arduino.www: Flags [.], ack 298, win 5840, length 0

This means that Arduino sends a 32-byte long packet immediately followed by a 1-byte long packet, then waits 2 seconds before repeating again!!

If I replace this:

while(webFile.available())
    client.write(webFile.read()); // send web page to client

with this:

while(webFile.available()) {
    const byte maxn = 32;
    byte buf[maxn];
    client.write(buf, webFile.read(buf, maxn)); // send web page to client
}

the WiFI shield sends 512-byte long packets, all in a matter of milliseconds.

Copied from original issue: arduino/Arduino#1712

`WiFi.begin()` missing overload

According to the Arduino Reference, the method WiFi.begin(), should have an overload taking 0 arguments (no ssid nor password). However the library as written currently has no declaration nor definition of said method for no arguments.

Please kindly implement this functionality.

Make `WiFi.disconnect()` send `DHCPRELEASE` packet

Hi there! I am having some issues with the WiFi library not playing nice with DHCP servers. An illustration would be the following boilerplate logic:

void loop() {
  //...

  WiFi.mode(WIFI_STA);
  WiFi.begin(STA_SSID, STA_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }

  // do

  WiFi.disconnect();

  //...
}

The part after a WiFi disconnect could be a sleep or a very large pause although that is irrelevant.

From the server side it seems that the code would generate the following events:

  1. DHCPDISCOVER
  2. DHCPOFFER
  3. DHCPREQUEST
  4. DHCPACK

which seems fine for requesting an IP but that is rather the end of it and it seems that:

WiFi.disconnect();

is somewhat of a dud in what regards actually shutting down the connection - I have not looked at the code so I am not sure what it does, but it looks like it disconnects the device from WiFi but does not really bother about issuing a DHCPRELEASE in order to let the server know that the IP address currently being held is now free.

I am thinking about crafting a DHCPRELEASE packet myself and sending it through but it would be so much nicer for that to be part of WiFi.disconnect() because it belongs there if WiFi also handles DHCP.

DHCP servers like ISC are clever enough to cache and reuse the same address the next time the same client requests an IP but, pedantically speaking, there is no obligation to cache the client and offer up the same address next time. In case you have quite a large number of IoT devices hammering the DHCP server with requests for IP addresses without even bothering to let the server know that the IP address can be released, this could just shift the workload and power consumption from the client to the server, where the server would just struggle to keep track of all these devices that just abandon their IP addresses and wonder if they'll ever return. Or this behavior could just lead to an IP address starvation attack, by just requesting IP addresses incessantly and hammering the DHCP server with requests.

Would it be alright if we got an RFC1541-compliant implementation for the DHCP part that WiFi handles? Everything is good up and until DHCPACK, flawless, but it would be nice if it could also send a DHCPRELEASE such that DHCP servers can be graciously informed that the IP address can be put back into the address pool.

Thanks!

Wifi client frees socket allocation on a listening socket

From @SurferTim on December 11, 2013 11:55

If using a server, this incorrectly released a socket that should still be reserved for the server. If the server_port array entry for that socket is non-zero, it should not release the socket. This is in WiFiClient.cpp.
IDE v1.0.5 and v1.5.5.

void WiFiClient::stop() {

  if (_sock == 255)
    return;

  ServerDrv::stopClient(_sock);

// add this line to prevent release of a listening socket (server)
  if(WiFiClass::_server_port[_sock] == 0)
    WiFiClass::_state[_sock] = NA_STATE;

  int count = 0;
  // wait maximum 5 secs for the connection to close
  while (status() != CLOSED && ++count < 50)
    delay(100);

  _sock = 255;
}

Copied from original issue: arduino/Arduino#1733

Arduino IDE 1.8.1 WiFi library multiple byte TCP read function read(*databuf, datasize) gives wrong values

I have Mega 2560 connected to WiFi Shield (configured as server). I am using IDE 1.8.1. In my code I want to receive say 2 bytes. The client sends 1 byte at a time. Say client sends b first and then A ideally server should read bA after the second byte sent from client. However, I notice the second value getting corrupted. I am pasting the code below:

#include <SPI.h>
#include<WiFi.h>

int configureSuccess = WL_IDLE_STATUS;
char ssid[] = "xyz";
char pass[] = "*******";
WiFiServer server(20000);

static uint8_t alreadyConnected = 0;

void setup() {
Serial.begin(9600);
Serial1.begin(28800);
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
while ( configureSuccess != WL_CONNECTED) {
configureSuccess = WiFi.begin(ssid, pass);
// delay 10000
unsigned long startMillis = millis();
while(millis()- startMillis < 10000)
{
};
}
server.begin();

  for(int trialcount=0;trialcount<5;trialcount++)
  {
      if(Serial)
      {
          break;
      }else
      {
          unsigned long startMillis  = millis();
    while(millis()- startMillis < 1000)
                    {
                    };
      }
  }
  
  if (configureSuccess==WL_CONNECTED)
   { 
     IPAddress ip = WiFi.localIP();
     Serial.print("<<<IP address: ");
     Serial.print(ip);  
     Serial.println(">>>");            
  }
 else
 {
     Serial.println("<<< IP address :Failed to configure. >>>");
 }
}

void loop() {
// wait for a new client:
int avlBytes = 0;
int st = 0;
int data2[2];

Serial1.println("loop");
WiFiClient client1 = server.available();
if (client1){
if(!alreadyConnected){
client1.flush();
alreadyConnected++;
Serial1.println("Flushing");
}
avlBytes = client1.available();
if(avlBytes >= 2){
st = client1.read(data2,2);
//data2[0] = client1.read();
//data2[1] = client1.read();
Serial1.println("data_s");
Serial1.println(data2[0]);
Serial1.println(data2[1]);
Serial1.println("rx_status");
Serial1.println(st);
}
else{
Serial1.println("rcvd");
Serial1.println(avlBytes);
}
}
else {
alreadyConnected = 0;
Serial1.println("No client");
}
unsigned long startMillis = millis();
while(millis()- startMillis < 1000)
{
};
}

With client1.read(data2, 2) if client send b first then rcvd 1 is printed. If client then sends A then data_s 98 2 is printed and rcvd is still 1. Next time if I send c then data_s 65 2 and rcvd 1.

However, if I use two back-to-back read() (data2[0] = client1.read(); data2[1] = client1.read();) the Serial1 print would be data_s 98 65. Seems to be an issue in ServerDrv::getDataBuf. The method ServerDrv::getData works fine.

Wifi WEP connection fails

From @chris711 on June 25, 2013 17:57

I'm using an Arduino Mega 2560 with the WIFI shield and the ConnectWithWep example. The device fails to connect to my network and the error led lights up on the WIFI shield.

My router shows up if I run the scan network example.

My network is running the Shared Key Authentication mode for WEP.

If I switch to WPA everything works fine.

Copied from original issue: arduino/Arduino#1486

TCP connections die after few seconds of inactivity [imported]

From @cmaglie on November 15, 2012 19:2

This is Issue 1024 moved from a Google Code project.
Added by 2012-08-31T10:45:38.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium

Original description

Hardware:

  • Arduino Leonardo
  • WiFi Shield

Software:

  • Arduino IDE 1.0.1
  • Mac OSX 10.7 / Ubuntu 12.04

Libraries:

  • WiFi Libraries (downloaded from arduino.cc)

What steps will reproduce the problem?

  1. Code a sketch to open a TCP connection with a simple TCP server (I tried with a Node.js HelloWorld as server)
  2. Sending and receiving messages works fine, so wait few seconds and the connection will be closed by the Arduino with a "reset" packet as the last packet sent from the board.
  3. Now you can't send/receive anything more and the server is not correctly notified about the connection status until it tries to read/write.

What is the expected output? What do you see instead?
I expected the connection to be kept open until it was closed properly by the server/client. No other client (except for Arduino) seems to drop the connection in this way.

I'm gonna attach a wireshark log about the traffic produced by my TCP server and the board.

Kind Regards.
Marco Lipparini

Copied from original issue: arduino/Arduino#1024

WiFi Soft Ap web server hotspot disconnecting issue in esp8266/esp32 with redmi note 8 pro android phone

Hi there,
I've been trying to set up an access point combined with a web server using the ESP8266WiFi/WiFi.h(for esp32) libraries for Arduino. I am using an ESP8266 NodeMCU/ESP32.

Setting up an AP using softAP works fine and connection also is stable , The problem is when trying to access the web server from a connected device, it always ends up with a timeout exception and connection not stable. but its working fine with some android but not works with redmi note 8 pro.

please give some ideas to sort this issue.

thanks in advance.

vasanth

IPv6 support

This library seems to currently not support IPv6, which it should nowadays. It might not work on all of the micro controllers due to memory, but it should be supported.

Can't mix Wifi Client / Server

From @RobinWoo on September 20, 2013 8:33

Hello all,

It seems not possible to mix client and server with the WifiShield library / Firmware. Please look at the following code. The Wifi is used as server and check for "GET /alm" request. In this case, the Wifi is used as client to send a Push alert if the time between 2 notifications was passes.

#include <SPI.h>
#include <WiFi.h>
#include <FlexiTimer2.h>
#include <WString.h>

#define NETWORK_SSID "****"     //  network SSID (name) 
#define NETWORK_PASSWD "***"  // network password
#define KEY_INDEX 0;        // network key Index number (needed only for WEP)
#define LED 13
#define CYCLE_NB_BETWEEN_NOTIFY 12000;

int status = WL_IDLE_STATUS;
WiFiServer server(80);
WiFiClient alertClient;

void setup() {
    Serial.begin(9600);
    pinMode(LED, OUTPUT);  

    // check for the presence of the shield:
    if (WiFi.status() == WL_NO_SHIELD) {
        Serial.println("WiFi shield not present");
        while(true) {
            digitalWrite(LED, HIGH);
            delay(125);
            digitalWrite(LED, LOW);
            delay(125);
        }
    }

    // Set the IP address for the WIFI
    //WiFi.config(serverIp);
    // attempt to connect to Wifi network:
    do {
        Serial.print("Attempting to connect to SSID: ");
        Serial.println(NETWORK_SSID);
        status = WiFi.begin(NETWORK_SSID, NETWORK_PASSWD);
    } while ( status != WL_CONNECTED);

    // Start server
    server.begin();

    // you're connected now, so print out the status:
    printWifiStatus();

    // Set Timer 2 interrupt
    FlexiTimer2::set(5, interruptTimer2);
    FlexiTimer2::start(); // active
}

void loop() {
    // Client connected
    WiFiClient client = server.available();
    if (client) {
        String response = "";
        String currentLine = ""; // make a String to hold incoming data from the client
        Serial.println("new client");
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();
                if (c == '\n') { // if the byte is a newline character
                    // Check GET request 
                    int ind1 = currentLine.indexOf("GET /");
                    if(ind1 >= 0) {
                        String cmd = currentLine.substring(ind1+5, ind1+8);
                        if (cmd == "alm") {
                            alertAvailable=true;
                        }
                    }
                    // if the current line is blank, you got two newline characters in a row.
                    // that's the end of the client HTTP request, so send a response:
                    if (currentLine.length() == 0) {
                        Serial.println("Send response to client.");
                        client.println("HTTP/1.1 200 OK");
                        client.println("Content-type:text/html");
                        client.println();
                        // the content of the HTTP response follows the header:
                        if (response != "") {
                            client.println(response);
                        }
                        // The HTTP response ends with another blank line:
                        client.println();
                        // break out of the while loop:
                        break;
                    } else { // if you got a newline, then clear currentLine:
                        currentLine = "";
                    }
                } else if (c != '\r') { // if you got anything else but a cr character,
                    currentLine += c; // add it to the end of the currentLine
                }
            }
        }
        //stopping client
        client.stop();
        Serial.println("Client disonnected");
    }

    // Send alert ?
    if ((alertAvailable==true) && (timerAlert == 0)) {
        sendAlert("ALERT+TEST");
    }
}

void interruptTimer2() {
    if (timerAlert > 0) {
        timerAlert --;
    }
}

void sendAlert(String message) {
    if (alertClient.connect(alertServerIp, 80)) {
        Serial.println("connected to ALERT server");
        Serial.println("Send Alert for "+message);
        alertClient.println("GET /push/push.php?call=*******&message=+"+message+" HTTP/1.1");
        alertClient.println("Host:pautex.fr");
        alertClient.println("Connection: close");
        alertClient.println();
        alertClient.flush();
        alertClient.stop();
        Serial.println("End Alert for "+message);
        alertClient.flush();
    }
    alertAvailable = false;
    timerAlert = CYCLE_NB_BETWEEN_NOTIFY;
}

The server work correctly and send response for any request from my browser until I send the request ip-adress/alm. In this case, the alert is sent (client work correctly). But the server seems to be stopped: The "server.available()" return 0.

Copied from original issue: arduino/Arduino#1582

WiFiUdp write() does not work when repeatedly writing single bytes

From @fpoto on October 26, 2013 0:37

Writing a buffer with a single call to WiFiUdp.write() works, while writing that same buffer one byte at a time does not.

The gist at https://gist.github.com/fpoto/7163904 demonstrates the problem.

Expected output with allTogether set to true:

Attempting to connect to SSID: xxxxxxxx connected
UTC time: 1382745247
UTC time: 1382745249
UTC time: 1382745251
UTC time: 1382745254
UTC time: 1382745257

Expected output with allTogether set to false:

Attempting to connect to SSID: xxxxxxxx connected
endPacket successful
request failed

You may notice that when it fails it also stops looping. I did not investigate why.

Copied from original issue: arduino/Arduino#1642

When wifi shield goes out of network range for a period of time, the tcpServer dies and does not respawn. [imported]

From @cmaglie on November 15, 2012 19:4

This is Issue 1086 moved from a Google Code project.
Added by 2012-10-29T00:03:28.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium

Original description

What steps will reproduce the problem?

  1. Use any of the example sketches that instantiate the WiFiServer that come with the WiFi shield and load it up. ie. WiFiChatServer
  2. Take your arduino+wifi shield out of wifi range and leave it there for a few minutes.
  3. Take it back in to wifi range and it will be pingable, you'll be able to open a socket to the server, but it will just hang there. You can observe the TCP packets bouncing back and forth and eventually the wifishield disconnects you.

You should expect that when the wifi server is back in range, it will continue to serve new/old established connections.

I did some very superficial debugging and if you output server.status() you'll notice that at some point it returns 0, instead of 1. This is when you know it's dead. I've tried to add code that runs another server.begin(), to no avail. I've even added a new function to restart the server. Again, to no avail. I've yet to dig deeper.

I'm using the Arduino UNO + Arduino Wifi Shield, using 1.0.1 of the IDE in OS X Mountain Lion.

This function does not restart the server as I would expect when it dies, i've yet to debug why:
void WiFiServer::restart()
{
uint8_t _sock = WiFiClass::getSocket();
ServerDrv::startServer(_port, _sock);
}

Copied from original issue: arduino/Arduino#1086

WiFi print line length issue

From @CountDoozer on August 22, 2015 7:21

If any, individual, line length in a series of client.print statements exceeds ~100 chars the whole page is dropped or sent so badly a browser will ignore it.

Arduino WiFi r3 Version 1.1.0 firmware
Atmega 2650
Arduino 1.6.5 IDE

Copied from original issue: arduino/Arduino#3711

Add check for empty passphrase to Wifi.begin(_ssid, _pass)

WiFi.cpp
line 98-116

Board: Arduino UNO R4 Wifi

Connections to an open network will fail, when Wifi.begin(_ssid, _pass) is called with an empty String. Some client (e.g. Arduino Cloud) allow the passphrase to be empty when configuring the network. This empty field is then passed on as "" to Wifi.begin(_ssid, _pass), resulting in a connection failure. Can you add a check for this condition and call Wifi.begin(_ssid) instead?

Related Issue: arduino-libraries/Arduino_ConnectionHandler#114

`-Wimplicit-fallthrough=` compiler warning

~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/utility/http_parser/http_parser.c: In function 'http_parser_execute':
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/utility/http_parser/http_parser.c:1817:31: warning: this statement may fall through [-Wimplicit-fallthrough=]
               parser->upgrade = 1;
               ~~~~~~~~~~~~~~~~^~~
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/utility/http_parser/http_parser.c:1819:13: note: here
             case 1:
             ^~~~
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/utility/http_parser/http_parser.c: In function 'http_parser_parse_url':
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/utility/http_parser/http_parser.c:2376:18: warning: this statement may fall through [-Wimplicit-fallthrough=]
         found_at = 1;
         ~~~~~~~~~^~~
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/utility/http_parser/http_parser.c:2379:7: note: here
       case s_req_server:
       ^~~~

WifiShield R3 doesn't work with IDE 1.0.5, 1.0.3

From @ldgarcia on February 2, 2014 3:38

Currently using an Arduino UNO R3 with a WiFi Shield R3.
Tried all the tutorial code regarding the WiFi shield, and nothing worked.
Finally, I found a "fix" in the Arduino forums: use IDE 1.0.2

OK, is your Arduino IDE version 1.0.5? If it is, I recommend you download 1.0.2 to give it a try. 1.0.5 has library only working well with the "latest" firmware. Your R3 wifi shield has an unknown version firmware (unfortunately I have not found the version of firmware for an original R3. This version is the most stable from my own arduino server tests. Please don't upgrade firmware and try arduino ide 1.0.2

Source: http://forum.arduino.cc/index.php/topic,167794.0.html

Copied from original issue: arduino/Arduino#1840

Arduino WiFi Shield Firmware/Library do not pass up sender's info.

From @josephlm on March 16, 2015 18:9

I am not familiar with how much detail I should add here, so I am giving a description of the issue and a proposed solution.

When using the Firmware already installed on my Arduino Wifi Shield (V1.0.0) or the firmware (V1.1.0) in the latest release version of Arduino (Arduino 1.6.1), it does not pass up the sender's information to the library for each packet in my shield's buffer (ie. IP Address & Port). There is an API provided which can get the last packet in my buffer and retrieve it's sender, but this sender information can be overwritten before my application can retrieve what is at the beginning of the buffer when a new packet goes in at the end of my buffer. Therefore, all packets will appear to be belong to the last packet's sender. This can cause weird operation in the enduser's application as receiving packets from different network users simultaneously will appear to only belong to the last packet's sender.

There is no disassociation between the last sender's packet and the sender before that packet as the sender's information is simply overwritten by the last sender's information via "setRemoteClient()". I would propose fixing this via:

A. changing the interface between the firmware and wifi library to pass up IP Address & Port information with every recv() command.
B. add a new send/recv construct and API in the Wifi Library (so as not to break existing users of this library) with fixes from proposal A.
C. Update the interface between the firmware and wifi library and change the public APIs of the Wifi Library to pass up IP Address & Port information with every recv() command.

I have tested proposal C above locally and I am able to provide my solution to developer's within the Arduino community to implement how they see fit as a reference only, if needed. Please contact me for a copy of my updated source.

Copied from original issue: arduino/Arduino#2780

Using this library for Ublox NINA W15 wifi modules

Hi all,

I just wanted to know if this library can be used to get Ublox NINA W152 WiFi module working? If yes, what pins of NINA wifi module are required to get Wifi up and running? I'd appreciate any kind of information here.

Thanks,
Akshay

Request for Bonjour/zeroconf on WiFi Shield

From @akauffm on November 28, 2012 17:44

I have used Georg Kaindl's excellent Arduino Ethernet library in the past to give Ethernet shield projects constant addresses (a la "arduino.local") on networks where I couldn't control assigned IP addresses and would very much like to have the same ability using the WiFi shield, along with some of the other bonuses of zeroconf. Because DHCP and DNS are handled in firmware on the WiFi shield, this feels like an issue that can't just be solved with a library like Georg's.

Copied from original issue: arduino/Arduino#1143

`-Wvla` compiler warnings

~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/MbedUdp.cpp: In member function 'virtual int arduino::MbedUDP::endPacket()':
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/MbedUdp.cpp:76:22: warning: variable length array 'buffer' is used [-Wvla]
   uint8_t buffer[size];
                      ^

`-Wsign-compare` compiler warnings

~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/MbedUdp.cpp:77:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < size; i++) {
                   ~~^~~~~~
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/MbedUdp.cpp: In member function 'virtual size_t arduino::MbedUDP::write(const uint8_t*, size_t)':
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/MbedUdp.cpp:97:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i<size; i++) {
                   ~^~~~~
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-deprecated-copy'
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/MbedClient.cpp: In member function 'size_t arduino::MbedClient::write(const uint8_t*, size_t)':
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/MbedClient.cpp:221:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   } while ((ret != size && ret == NSAPI_ERROR_WOULD_BLOCK) && connected());
             ~~~~^~~~~~~
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-deprecated-copy'
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/SocketHelpers.cpp: In member function 'int arduino::MbedSocketClass::download(const char*, bool, mbed::Callback<void(const char*, long unsigned int)>)':
~/Development/Arduino/hardware/test/mbed_opta/libraries/SocketWrapper/src/SocketHelpers.cpp:192:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<header_fields.size(); i++) {
                ~^~~~~~~~~~~~~~~~~~~~~

WEMOS LOLIN32 doesnt connect to WPA2 networks

I do have a WEMOS LOLIN32 and he denied to connect to WPA2 networks.

I se all networks but the encrytion type 3 seems not to be the best idea...

13:17:13.245 -> =======================================================================
13:17:13.245 -> SSID: 'xxxnet#2'; Channel: 4; RSSI: -62; Encryption: 3
13:17:13.245 -> SSID: 'xxx.freifunk.net'; Channel: 1; RSSI: -70; Encryption: 0
13:17:13.245 -> SSID: 'xxxnet'; Channel: 1; RSSI: -70; Encryption: 3
13:17:13.245 -> SSID: 'xxxznet LoRaWan'; Channel: 11; RSSI: -79; Encryption: 3
13:17:13.245 -> SSID: 'xxxnet'; Channel: 11; RSSI: -81; Encryption: 3

If I use the freifunk wifi net it works as it should.

Is there any fw upgrade needed or other things to do ?

WiFi shield issue: client.connect(server, 80)

From @piyali1988 on January 3, 2015 0:6

client.connect(server, 80); is not working. Here is the code:

include <SPI.h>

include <WiFi.h>

include <WiFiClient.h>

include <WiFiServer.h>

undef int

undef abs

undef double

undef float

undef round

int SensorIn1 = 1;
int led_pin = 13;

char devid[] = "v90EC98310145483";

int del=100; // Amount of seconds delay between posting to google docs.

char postmsg[100];
int k=0;
int temp_av = 0;
char server[] = "api.pushingbox.com";
char ssid[] = "**_";
char pass[] = "_
";
WiFiClient client;

void setup()
{
Serial.begin(9600);
WiFi.begin(ssid, pass);
delay(1000);
Serial.println("connecting...");
}

void loop(){

int val;
val = analogRead(SensorIn1);
Serial.println(val);

// Post to Google Form.............................................
if (client.connect(server, 80))
{
k=0;
Serial.println("connected");
sprintf(postmsg,"GET /pushingbox?devid=%c&status=%d HTTP/1.1",devid,val);
client.println(postmsg);
client.println("Host: api.pushingbox.com");
client.println("Connection: close");
client.println();

Serial.println(postmsg);
Serial.println("Host: api.pushingbox.com");
Serial.println("Connection: close");
Serial.println();

 delay(1000);
 client.stop();

}
delay(1000);

if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
k==1;
return;
}
}

The output I receive is
connecting....
456
disconnecting.
563
disconnecting.
and so on..
I have tried using different servers and accordingly selected the port numbers (eg 80, 443 etc) but the it never connects to the server. Kindly help.

Copied from original issue: arduino/Arduino#2531

Builtin LED blinking

Is it possible this library is blinking the builting LED when using a ESP32?

I found that if I exclude the WiFi begin, the blinking does not happen. If I include it, the LED blinks very fast.

I really don't know where else to look.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.