Skip to content

Commit 3d1b0b1

Browse files
committed
add mkr1000 support
1 parent a5a690d commit 3d1b0b1

File tree

5 files changed

+134
-5
lines changed

5 files changed

+134
-5
lines changed

AdafruitIO_MKR1000.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Tony DiCola, Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#if defined(ARDUINO_ARCH_SAMD) && defined(WINC1501_RESET_PIN)
13+
14+
#include "AdafruitIO_MKR1000.h"
15+
16+
AdafruitIO_MKR1000::AdafruitIO_MKR1000(const char *user, const char *key, const char *ssid, const char *pass):AdafruitIO(user, key)
17+
{
18+
_ssid = ssid;
19+
_pass = pass;
20+
_client = new WiFiSSLClient;
21+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _port);
22+
}
23+
24+
AdafruitIO_MKR1000::AdafruitIO_MKR1000(const __FlashStringHelper *user, const __FlashStringHelper *key, const __FlashStringHelper *ssid, const __FlashStringHelper *pass):AdafruitIO(user, key)
25+
{
26+
_ssid = (const char*)ssid;
27+
_pass = (const char*)pass;
28+
_client = new WiFiSSLClient;
29+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _port);
30+
}
31+
32+
AdafruitIO_MKR1000::~AdafruitIO_MKR1000()
33+
{
34+
if(_client)
35+
delete _client;
36+
if(_mqtt)
37+
delete _mqtt;
38+
}
39+
40+
void AdafruitIO_MKR1000::_connect()
41+
{
42+
43+
// no shield? bail
44+
if(WiFi.status() == WL_NO_SHIELD)
45+
return;
46+
47+
WiFi.begin(_ssid, _pass);
48+
_status = AIO_NET_DISCONNECTED;
49+
50+
}
51+
52+
aio_status_t AdafruitIO_MKR1000::networkStatus()
53+
{
54+
55+
switch(WiFi.status()) {
56+
case WL_CONNECTED:
57+
return AIO_NET_CONNECTED;
58+
case WL_CONNECT_FAILED:
59+
return AIO_NET_CONNECT_FAILED;
60+
case WL_IDLE_STATUS:
61+
return AIO_IDLE;
62+
default:
63+
return AIO_NET_DISCONNECTED;
64+
}
65+
66+
}
67+
68+
#endif // ARDUINO_ARCH_SAMD

AdafruitIO_MKR1000.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Tony DiCola, Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#ifndef ADAFRUITIO_MKR1000_H
13+
#define ADAFRUITIO_MKR1000_H
14+
15+
#if defined(ARDUINO_ARCH_SAMD) && defined(WINC1501_RESET_PIN)
16+
17+
#include "Arduino.h"
18+
#include "AdafruitIO.h"
19+
#include "SPI.h"
20+
#include "WiFi101.h"
21+
#include "WiFiSSLClient.h"
22+
#include "Adafruit_MQTT.h"
23+
#include "Adafruit_MQTT_Client.h"
24+
25+
class AdafruitIO_MKR1000 : public AdafruitIO {
26+
27+
public:
28+
AdafruitIO_MKR1000(const char *user, const char *key, const char *ssid, const char *pass);
29+
AdafruitIO_MKR1000(const __FlashStringHelper *user, const __FlashStringHelper *key, const __FlashStringHelper *ssid, const __FlashStringHelper *pass);
30+
~AdafruitIO_MKR1000();
31+
32+
aio_status_t networkStatus();
33+
34+
protected:
35+
void _connect();
36+
37+
const char *_ssid;
38+
const char *_pass;
39+
40+
WiFiSSLClient *_client;
41+
42+
};
43+
44+
#endif // ARDUINO_ARCH_SAMD
45+
46+
#endif // ADAFRUITIO_MKR1000_H

AdafruitIO_WINC1500.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
// All text above must be included in any redistribution.
1111
//
12-
#ifdef ARDUINO_ARCH_SAMD
12+
#if defined(ARDUINO_ARCH_SAMD) && !defined(WINC1501_RESET_PIN)
1313

1414
#include "AdafruitIO_WINC1500.h"
1515

AdafruitIO_WINC1500.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#ifndef ADAFRUITIO_WINC1500_H
1313
#define ADAFRUITIO_WINC1500_H
1414

15-
#ifdef ARDUINO_ARCH_SAMD
15+
#if defined(ARDUINO_ARCH_SAMD) && !defined(WINC1501_RESET_PIN)
1616

1717
#include "Arduino.h"
1818
#include "AdafruitIO.h"
@@ -21,6 +21,7 @@
2121
#include "Adafruit_MQTT.h"
2222
#include "Adafruit_MQTT_Client.h"
2323

24+
// feather wifi m0
2425
#define WINC_CS 8
2526
#define WINC_IRQ 7
2627
#define WINC_RST 4

AdafruitIO_WiFi.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@
1212
#ifndef ADAFRUITIO_WIFI_H
1313
#define ADAFRUITIO_WIFI_H
1414

15-
#ifdef ARDUINO_ARCH_SAMD
15+
#if defined(ARDUINO_ARCH_SAMD) && defined(WINC1501_RESET_PIN)
16+
17+
#include "AdafruitIO_MKR1000.h"
18+
19+
class AdafruitIO_WiFi: public AdafruitIO_MKR1000 {
20+
21+
public:
22+
AdafruitIO_WiFi(const char *user, const char *key, const char *ssid, const char *pass) :
23+
AdafruitIO_MKR1000(user, key, ssid, pass) {}
24+
AdafruitIO_WiFi(const __FlashStringHelper *user, const __FlashStringHelper *key, const __FlashStringHelper *ssid, const __FlashStringHelper *pass) :
25+
AdafruitIO_MKR1000(user, key, ssid, pass) {}
26+
27+
};
28+
29+
#elif defined(ARDUINO_ARCH_SAMD) && !defined(WINC1501_RESET_PIN)
1630

1731
#include "AdafruitIO_WINC1500.h"
1832

@@ -26,7 +40,7 @@ class AdafruitIO_WiFi: public AdafruitIO_WINC1500 {
2640

2741
};
2842

29-
#elif ESP8266
43+
#elif defined(ESP8266)
3044

3145
#include "AdafruitIO_ESP8266.h"
3246

@@ -40,7 +54,7 @@ class AdafruitIO_WiFi: public AdafruitIO_ESP8266 {
4054

4155
};
4256

43-
#elif ARDUINO_STM32_FEATHER
57+
#elif defined(ARDUINO_STM32_FEATHER)
4458

4559
#include "AdafruitIO_WICED.h"
4660

0 commit comments

Comments
 (0)