diff --git a/examples/adafruitio_00_publish/config.h b/examples/adafruitio_00_publish/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_00_publish/config.h +++ b/examples/adafruitio_00_publish/config.h @@ -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" diff --git a/examples/adafruitio_01_subscribe/config.h b/examples/adafruitio_01_subscribe/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_01_subscribe/config.h +++ b/examples/adafruitio_01_subscribe/config.h @@ -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" diff --git a/examples/adafruitio_02_pubsub/config.h b/examples/adafruitio_02_pubsub/config.h index 25cd8f55..289b880f 100644 --- a/examples/adafruitio_02_pubsub/config.h +++ b/examples/adafruitio_02_pubsub/config.h @@ -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" diff --git a/examples/adafruitio_03_multiple_feeds/config.h b/examples/adafruitio_03_multiple_feeds/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_03_multiple_feeds/config.h +++ b/examples/adafruitio_03_multiple_feeds/config.h @@ -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" diff --git a/examples/adafruitio_04_location/config.h b/examples/adafruitio_04_location/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_04_location/config.h +++ b/examples/adafruitio_04_location/config.h @@ -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" diff --git a/examples/adafruitio_05_type_conversion/config.h b/examples/adafruitio_05_type_conversion/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_05_type_conversion/config.h +++ b/examples/adafruitio_05_type_conversion/config.h @@ -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" diff --git a/examples/adafruitio_06_digital_in/config.h b/examples/adafruitio_06_digital_in/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_06_digital_in/config.h +++ b/examples/adafruitio_06_digital_in/config.h @@ -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" diff --git a/examples/adafruitio_07_digital_out/config.h b/examples/adafruitio_07_digital_out/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_07_digital_out/config.h +++ b/examples/adafruitio_07_digital_out/config.h @@ -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" diff --git a/examples/adafruitio_08_analog_in/config.h b/examples/adafruitio_08_analog_in/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_08_analog_in/config.h +++ b/examples/adafruitio_08_analog_in/config.h @@ -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" diff --git a/examples/adafruitio_09_analog_out/config.h b/examples/adafruitio_09_analog_out/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_09_analog_out/config.h +++ b/examples/adafruitio_09_analog_out/config.h @@ -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" diff --git a/examples/adafruitio_10_dashboard_creation/config.h b/examples/adafruitio_10_dashboard_creation/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_10_dashboard_creation/config.h +++ b/examples/adafruitio_10_dashboard_creation/config.h @@ -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" diff --git a/examples/adafruitio_11_group_pub/config.h b/examples/adafruitio_11_group_pub/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_11_group_pub/config.h +++ b/examples/adafruitio_11_group_pub/config.h @@ -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" diff --git a/examples/adafruitio_12_group_sub/config.h b/examples/adafruitio_12_group_sub/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_12_group_sub/config.h +++ b/examples/adafruitio_12_group_sub/config.h @@ -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" diff --git a/examples/adafruitio_13_rgb/config.h b/examples/adafruitio_13_rgb/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_13_rgb/config.h +++ b/examples/adafruitio_13_rgb/config.h @@ -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" diff --git a/examples/adafruitio_14_neopixel/config.h b/examples/adafruitio_14_neopixel/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_14_neopixel/config.h +++ b/examples/adafruitio_14_neopixel/config.h @@ -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" diff --git a/examples/adafruitio_15_temp_humidity/config.h b/examples/adafruitio_15_temp_humidity/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_15_temp_humidity/config.h +++ b/examples/adafruitio_15_temp_humidity/config.h @@ -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" diff --git a/examples/adafruitio_16_servo/config.h b/examples/adafruitio_16_servo/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_16_servo/config.h +++ b/examples/adafruitio_16_servo/config.h @@ -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" diff --git a/examples/adafruitio_17_time_subscribe/config.h b/examples/adafruitio_17_time_subscribe/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_17_time_subscribe/config.h +++ b/examples/adafruitio_17_time_subscribe/config.h @@ -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" diff --git a/examples/adafruitio_18_device_info/config.h b/examples/adafruitio_18_device_info/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_18_device_info/config.h +++ b/examples/adafruitio_18_device_info/config.h @@ -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" diff --git a/examples/adafruitio_19_deepsleep/config.h b/examples/adafruitio_19_deepsleep/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_19_deepsleep/config.h +++ b/examples/adafruitio_19_deepsleep/config.h @@ -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" diff --git a/examples/adafruitio_20_shared_feed_write/config.h b/examples/adafruitio_20_shared_feed_write/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_20_shared_feed_write/config.h +++ b/examples/adafruitio_20_shared_feed_write/config.h @@ -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" diff --git a/examples/adafruitio_21_feed_read/config.h b/examples/adafruitio_21_feed_read/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_21_feed_read/config.h +++ b/examples/adafruitio_21_feed_read/config.h @@ -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" diff --git a/examples/adafruitio_22_environmental_monitor/config.h b/examples/adafruitio_22_environmental_monitor/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_22_environmental_monitor/config.h +++ b/examples/adafruitio_22_environmental_monitor/config.h @@ -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" diff --git a/examples/adafruitio_23_ifttt/config.h b/examples/adafruitio_23_ifttt/config.h index 25cd8f55..289b880f 100644 --- a/examples/adafruitio_23_ifttt/config.h +++ b/examples/adafruitio_23_ifttt/config.h @@ -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" diff --git a/examples/adafruitio_24_zapier/config.h b/examples/adafruitio_24_zapier/config.h index bcff0c95..c7b156f1 100644 --- a/examples/adafruitio_24_zapier/config.h +++ b/examples/adafruitio_24_zapier/config.h @@ -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" diff --git a/examples/io_home_series/io_home_security/config.h b/examples/io_home_series/io_home_security/config.h index bcff0c95..c7b156f1 100644 --- a/examples/io_home_series/io_home_security/config.h +++ b/examples/io_home_series/io_home_security/config.h @@ -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" diff --git a/examples/io_home_series/neopixel_and_thermometer/config.h b/examples/io_home_series/neopixel_and_thermometer/config.h index bcff0c95..c7b156f1 100644 --- a/examples/io_home_series/neopixel_and_thermometer/config.h +++ b/examples/io_home_series/neopixel_and_thermometer/config.h @@ -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" diff --git a/src/AdafruitIO_WiFi.h b/src/AdafruitIO_WiFi.h index 24f39b65..93c92f64 100644 --- a/src/AdafruitIO_WiFi.h +++ b/src/AdafruitIO_WiFi.h @@ -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) diff --git a/src/wifi/AdafruitIO_MKR1010.h b/src/wifi/AdafruitIO_MKR1010.h new file mode 100644 index 00000000..c99106ff --- /dev/null +++ b/src/wifi/AdafruitIO_MKR1010.h @@ -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 diff --git a/src/wifi/AdafruitIO_WINC1500.h b/src/wifi/AdafruitIO_WINC1500.h index 5f6b7fec..88280ec2 100644 --- a/src/wifi/AdafruitIO_WINC1500.h +++ b/src/wifi/AdafruitIO_WINC1500.h @@ -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) {