Skip to content

Commit 955cc1f

Browse files
authored
Merge branch 'arduino-libraries:master' into master
2 parents 8bf8f73 + f55e1fc commit 955cc1f

File tree

9 files changed

+3352
-20
lines changed

9 files changed

+3352
-20
lines changed

docs/api.md

Lines changed: 3290 additions & 0 deletions
Large diffs are not rendered by default.

docs/readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WiFiNINA Library
2+
3+
4+
This library allows you to use the Arduino UNO WiFi Rev.2, Arduino NANO 33 IoT, Arduino MKR 1010 and Arduino MKR VIDOR 4000 WiFi capabilities. It can serve as either a server accepting incoming connections or a client making outgoing ones. The library supports WEP, WPA2 Personal and WPA2 Enterprise encryptions. This library support all the same methods of the original WiFi library plus the connectSSL(). The WiFiNINA library is very similar to the Ethernet and the library WiFi, and many of the function calls are the same.
5+
6+
To use this library
7+
8+
```
9+
#include <SPI.h>
10+
#include <WiFiNINA.h>
11+
```
12+
13+
## Examples
14+
15+
Several examples for the **WiFiNINA** library are available from the [Examples from Libraries page](https://docs.arduino.cc/library-examples/).

examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ void loop() {
101101

102102
// Check to see if the client request was "GET /H" or "GET /L":
103103
if (currentLine.endsWith("GET /H")) {
104-
digitalWrite(9, HIGH); // GET /H turns the LED on
104+
digitalWrite(LED_BUILTIN, HIGH); // GET /H turns the LED on
105105
}
106106
if (currentLine.endsWith("GET /L")) {
107-
digitalWrite(9, LOW); // GET /L turns the LED off
107+
digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off
108108
}
109109
}
110110
}

examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ int keyIndex = 0; // your network key index number (needed only for W
2828

2929
unsigned int localPort = 2390; // local port to listen for UDP packets
3030

31-
IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server
31+
IPAddress timeServer(162, 159, 200, 123); // pool.ntp.org NTP server
3232

3333
const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message
3434

35-
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
35+
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
3636

3737
// A UDP instance to let us send and receive packets over UDP
3838
WiFiUDP Udp;

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=WiFiNINA
2-
version=1.8.10
2+
version=1.8.13
33
author=Arduino
44
maintainer=Arduino <[email protected]>
55
sentence=Enables network connection (local and Internet) with the Arduino MKR WiFi 1010, Arduino MKR VIDOR 4000, Arduino UNO WiFi Rev.2 and Nano 33 IoT.

src/WiFi.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
#include "utility/debug.h"
2828
}
2929

30-
WiFiClass::WiFiClass() : _timeout(50000)
30+
WiFiClass::WiFiClass() : _timeout(50000), _feed_watchdog_func(0)
3131
{
3232
}
3333

@@ -49,6 +49,7 @@ int WiFiClass::begin(const char* ssid)
4949
{
5050
for (unsigned long start = millis(); (millis() - start) < _timeout;)
5151
{
52+
feedWatchdog();
5253
delay(WL_DELAY_START_CONNECTION);
5354
status = WiFiDrv::getConnectionStatus();
5455
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
@@ -71,6 +72,7 @@ int WiFiClass::begin(const char* ssid, uint8_t key_idx, const char *key)
7172
{
7273
for (unsigned long start = millis(); (millis() - start) < _timeout;)
7374
{
75+
feedWatchdog();
7476
delay(WL_DELAY_START_CONNECTION);
7577
status = WiFiDrv::getConnectionStatus();
7678
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
@@ -92,6 +94,7 @@ int WiFiClass::begin(const char* ssid, const char *passphrase)
9294
{
9395
for (unsigned long start = millis(); (millis() - start) < _timeout;)
9496
{
97+
feedWatchdog();
9598
delay(WL_DELAY_START_CONNECTION);
9699
status = WiFiDrv::getConnectionStatus();
97100
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
@@ -382,4 +385,16 @@ void WiFiClass::setTimeout(unsigned long timeout)
382385
{
383386
_timeout = timeout;
384387
}
388+
389+
void WiFiClass::setFeedWatchdogFunc(FeedHostProcessorWatchdogFuncPointer func)
390+
{
391+
_feed_watchdog_func = func;
392+
}
393+
394+
void WiFiClass::feedWatchdog()
395+
{
396+
if (_feed_watchdog_func)
397+
_feed_watchdog_func();
398+
}
399+
385400
WiFiClass WiFi;

src/WiFi.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
#ifndef WiFi_h
2222
#define WiFi_h
2323

24-
#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5"
24+
#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8"
25+
#define WIFI_HAS_FEED_WATCHDOG_FUNC
2526

2627
#include <inttypes.h>
2728

@@ -36,12 +37,15 @@ extern "C" {
3637
#include "WiFiServer.h"
3738
#include "WiFiStorage.h"
3839

40+
typedef void(*FeedHostProcessorWatchdogFuncPointer)();
41+
3942
class WiFiClass
4043
{
4144
private:
4245

4346
static void init();
4447
unsigned long _timeout;
48+
FeedHostProcessorWatchdogFuncPointer _feed_watchdog_func;
4549
public:
4650
WiFiClass();
4751

@@ -274,6 +278,9 @@ class WiFiClass
274278
int ping(IPAddress host, uint8_t ttl = 128);
275279

276280
void setTimeout(unsigned long timeout);
281+
282+
void setFeedWatchdogFunc(FeedHostProcessorWatchdogFuncPointer func);
283+
void feedWatchdog();
277284
};
278285

279286
extern WiFiClass WiFi;

src/utility/nano_rp2040_support.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
* FUNCTION DEFINITION
3131
******************************************************************************/
3232

33+
#ifdef NINA_PINS_AS_CLASS
34+
#define VAL(x) x.get()
35+
#else
36+
#define VAL(x) static_cast<uint8_t>(x)
37+
#endif
38+
3339
uint8_t toAnalogPin(NinaPin pin)
3440
{
3541
if (pin == A4) return 6; /* ADC1 - CH6 */
@@ -41,20 +47,20 @@ uint8_t toAnalogPin(NinaPin pin)
4147

4248
void pinMode(NinaPin pin, PinMode mode)
4349
{
44-
WiFiDrv::pinMode(static_cast<uint8_t>(pin), static_cast<uint8_t>(mode));
50+
WiFiDrv::pinMode(VAL(pin), static_cast<uint8_t>(mode));
4551
}
4652

4753
PinStatus digitalRead(NinaPin pin)
4854
{
49-
return WiFiDrv::digitalRead(static_cast<uint8_t>(pin));
55+
return WiFiDrv::digitalRead(VAL(pin));
5056
}
5157

5258
void digitalWrite(NinaPin pin, PinStatus value)
5359
{
5460
if (value == LOW)
55-
WiFiDrv::digitalWrite(static_cast<uint8_t>(pin), 1);
61+
WiFiDrv::digitalWrite(VAL(pin), 1);
5662
else
57-
WiFiDrv::digitalWrite(static_cast<uint8_t>(pin), 0);
63+
WiFiDrv::digitalWrite(VAL(pin), 0);
5864
}
5965

6066
int analogRead(NinaPin pin)
@@ -64,12 +70,16 @@ int analogRead(NinaPin pin)
6470
if (adc_channel == 0xFF)
6571
return 0;
6672
else
73+
#ifdef NINA_PINS_AS_CLASS
74+
return WiFiDrv::analogRead(adc_channel) >> (12 - pin.analogReadResolution());
75+
#else
6776
return WiFiDrv::analogRead(adc_channel);
77+
#endif
6878
}
6979

7080
void analogWrite(NinaPin pin, int value)
7181
{
72-
WiFiDrv::analogWrite(static_cast<uint8_t>(pin), static_cast<uint8_t>(value));
82+
WiFiDrv::analogWrite(VAL(pin), static_cast<uint8_t>(value));
7383
}
7484

7585
#endif /* ARDUINO_NANO_RP2040_CONNECT */

src/utility/spi_drv.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <SPI.h>
2323
#include "utility/spi_drv.h"
2424
#include "pins_arduino.h"
25+
#include "WiFi.h"
2526

2627
#ifdef ARDUINO_SAMD_MKRVIDOR4000
2728

@@ -67,13 +68,7 @@ static bool inverted_reset = false;
6768

6869
bool SpiDrv::initialized = false;
6970

70-
__attribute__((weak)) void wifi_nina_feed_watchdog()
71-
{
72-
/* This function can be overwritten by a "strong" implementation
73-
* in a higher level application, such as the ArduinoIoTCloud
74-
* firmware stack.
75-
*/
76-
}
71+
extern WiFiClass WiFi;
7772

7873
void SpiDrv::begin()
7974
{
@@ -227,7 +222,7 @@ void SpiDrv::waitForSlaveReady(bool const feed_watchdog)
227222
{
228223
if (feed_watchdog) {
229224
if ((millis() - start) < 10000) {
230-
wifi_nina_feed_watchdog();
225+
WiFi.feedWatchdog();
231226
}
232227
}
233228
}

0 commit comments

Comments
 (0)