Skip to content

Commit 2837f73

Browse files
authored
Create AdafruitIO_MKR1010.cpp
This new file is a copy of the original AdafruitIO_MKR1000.cpp but modified for the Arduino MKR1010
1 parent a5f380e commit 2837f73

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

src/wifi/AdafruitIO_MKR1010.cpp

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

0 commit comments

Comments
 (0)