Skip to content

Commit 55efac3

Browse files
committed
Changes to support MKR 1010 and Nano 33 IOT
Changes to support MKR 1010 and Nano 33 IOT
1 parent e9ac466 commit 55efac3

File tree

3 files changed

+49
-96
lines changed

3 files changed

+49
-96
lines changed

src/wifi/AdafruitIO_MKR1010.cpp

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/wifi/AdafruitIO_MKR1010.h

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
* products from Adafruit!
77
*
88
* Copyright (c) 2015-2016 Adafruit Industries
9-
* Authors: Tony DiCola, Todd Treece
9+
* Authors: David Goldstein, Morgan Winters
1010
* Licensed under the MIT license.
1111
*
1212
* All text above must be included in any redistribution.
1313
*/
1414

15-
#ifndef ADAFRUITIO_MKR1010_H
16-
#define ADAFRUITIO_MKR1010_H
17-
18-
#if defined(ARDUINO_SAMD_MKR1010)
1915

2016
#include "AdafruitIO.h"
2117
#include "Adafruit_MQTT.h"
@@ -28,23 +24,58 @@
2824
class AdafruitIO_MKR1010 : public AdafruitIO {
2925

3026
public:
31-
AdafruitIO_MKR1010(const char *user, const char *key, const char *ssid,
32-
const char *pass);
33-
~AdafruitIO_MKR1010();
27+
AdafruitIO_MKR1010(const char *user, const char *key,
28+
const char *ssid, const char *pass)
29+
: AdafruitIO(user, key) {
30+
_ssid = ssid;
31+
_pass = pass;
32+
_client = new WiFiSSLClient;
33+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
34+
_http = new HttpClient(*_client, _host, _http_port);
35+
}
36+
~AdafruitIO_MKR1010() {
37+
if (_client)
38+
delete _client;
39+
if (_mqtt)
40+
delete _mqtt;
41+
}
3442

35-
aio_status_t networkStatus();
36-
const char *connectionType();
43+
aio_status_t networkStatus() {
44+
switch (WiFi.status()) {
45+
case WL_CONNECTED:
46+
return AIO_NET_CONNECTED;
47+
case WL_CONNECT_FAILED:
48+
return AIO_NET_CONNECT_FAILED;
49+
case WL_IDLE_STATUS:
50+
return AIO_IDLE;
51+
default:
52+
return AIO_NET_DISCONNECTED;
53+
}
54+
}
55+
56+
const char *connectionType() { return "wifi"; }
3757

3858
protected:
39-
void _connect();
40-
void _disconnect();
59+
void _connect() {
60+
if (strlen(_ssid) == 0) {
61+
_status = AIO_SSID_INVALID;
62+
} else {
63+
_disconnect();
64+
65+
WiFi.begin(_ssid, _pass);
66+
_status = networkStatus();
67+
}
68+
}
69+
70+
void _disconnect() {
71+
WiFi.disconnect();
72+
delay(AIO_NET_DISCONNECT_WAIT);
73+
}
4174

4275
const char *_ssid;
4376
const char *_pass;
4477

4578
WiFiSSLClient *_client;
4679
};
4780

48-
#endif // ARDUINO_ARCH_SAMD
4981

50-
#endif // ADAFRUITIO_MKR1010_H

src/wifi/AdafruitIO_WINC1500.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@
1515
#ifndef ADAFRUITIO_WINC1500_H
1616
#define ADAFRUITIO_WINC1500_H
1717

18-
#if !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_SAMD_MKR1010) && \
19-
defined(ARDUINO_ARCH_SAMD) && !defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) && \
20-
!defined(ADAFRUIT_PYPORTAL)
18+
#if !defined(ARDUINO_SAMD_MKR1000) && defined(ARDUINO_ARCH_SAMD) && \
19+
!defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) && !defined(ADAFRUIT_PYPORTAL)
2120

2221
#include "AdafruitIO.h"
2322
#include "Adafruit_MQTT.h"
2423
#include "Adafruit_MQTT_Client.h"
2524
#include "Arduino.h"
2625
#include "SPI.h"
27-
//#include "WiFi101.h" // USE THIS FOR WiFi101 boards such as the MKR1000
28-
#include "WiFiNINA.h // USE THIS FOR WiFiNINA boards such as the MKR1010
26+
#include "WiFi101.h"
27+
2928

3029
/**************************************************************************/
3130
/*!

0 commit comments

Comments
 (0)