Skip to content

Support for Arduino WiFi MKR 1010 and Arduino Nano 33 IOT #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/adafruitio_00_publish/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_01_subscribe/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_02_pubsub/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_03_multiple_feeds/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_04_location/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_05_type_conversion/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_06_digital_in/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_07_digital_out/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_08_analog_in/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_09_analog_out/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_10_dashboard_creation/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_11_group_pub/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_12_group_sub/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_13_rgb/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_14_neopixel/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_15_temp_humidity/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_16_servo/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_17_time_subscribe/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_18_device_info/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_19_deepsleep/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_20_shared_feed_write/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_21_feed_read/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_22_environmental_monitor/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_23_ifttt/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/adafruitio_24_zapier/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/io_home_series/io_home_security/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
3 changes: 3 additions & 0 deletions examples/io_home_series/neopixel_and_thermometer/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

Expand Down
5 changes: 5 additions & 0 deletions src/AdafruitIO_WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include "wifi/AdafruitIO_MKR1000.h"
typedef AdafruitIO_MKR1000 AdafruitIO_WiFi;

#elif defined(ARDUINO_SAMD_MKR1010)

#include "wifi/AdafruitIO_MKR1010.h"
typedef AdafruitIO_MKR1010 AdafruitIO_WiFi;

#elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || defined(ADAFRUIT_PYPORTAL) || \
defined(USE_AIRLIFT)

Expand Down
83 changes: 83 additions & 0 deletions src/wifi/AdafruitIO_MKR1010.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*!
* @file AdafruitIO_MKR1010.h
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: David Goldstein, Morgan Winters
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*/

#ifndef ADAFRUITIO_MKR1010_H
#define ADAFRUITIO_MKR1010_H

#include "AdafruitIO.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include "Arduino.h"
#include "SPI.h"
#include "WiFiNINA.h"
#include "WiFiSSLClient.h"

class AdafruitIO_MKR1010 : public AdafruitIO {

public:
AdafruitIO_MKR1010(const char *user, const char *key, const char *ssid,
const char *pass)
: AdafruitIO(user, key) {
_ssid = ssid;
_pass = pass;
_client = new WiFiSSLClient;
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
_http = new HttpClient(*_client, _host, _http_port);
}
~AdafruitIO_MKR1010() {
if (_client)
delete _client;
if (_mqtt)
delete _mqtt;
}

aio_status_t networkStatus() {
switch (WiFi.status()) {
case WL_CONNECTED:
return AIO_NET_CONNECTED;
case WL_CONNECT_FAILED:
return AIO_NET_CONNECT_FAILED;
case WL_IDLE_STATUS:
return AIO_IDLE;
default:
return AIO_NET_DISCONNECTED;
}
}

const char *connectionType() { return "wifi"; }

protected:
void _connect() {
if (strlen(_ssid) == 0) {
_status = AIO_SSID_INVALID;
} else {
_disconnect();

WiFi.begin(_ssid, _pass);
_status = networkStatus();
}
}

void _disconnect() {
WiFi.disconnect();
delay(AIO_NET_DISCONNECT_WAIT);
}

const char *_ssid;
const char *_pass;

WiFiSSLClient *_client;
};

#endif ADAFRUITIO_MKR1010_H
2 changes: 1 addition & 1 deletion src/wifi/AdafruitIO_WINC1500.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class AdafruitIO_WINC1500 : public AdafruitIO {
_status = AIO_SSID_INVALID;
} else {
_disconnect();
WiFi.setPins(_winc_cs, _winc_irq, _winc_rst, _winc_en);
WiFi.setPins(_winc_cs, _winc_irq, _winc_rst, _winc_en); //

// no shield? bail
if (WiFi.status() == WL_NO_SHIELD) {
Expand Down