Skip to content

Commit 2c34b4c

Browse files
authored
Merge pull request #83 from fabik111/lora-support
This pull request adds support for the MKRWAN LoRa board to be used with the Arduino IoT Cloud.
2 parents 902f31f + 103bfde commit 2c34b4c

18 files changed

+1102
-541
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*~
44
.vscode
55
*.orig
6+
.vs

Diff for: .travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ matrix:
77
- BOARD="arduino:samd:mkrwifi1010"
88
- env:
99
- BOARD="arduino:samd:mkrgsm1400"
10+
- env:
11+
- BOARD="arduino:samd:mkrwan1300"
1012
- env:
1113
- BOARD="esp8266:esp8266:huzzah"
1214
- env:
@@ -69,6 +71,7 @@ before_install:
6971
- installLibrary arduino-libraries/ArduinoBearSSL
7072
- installLibrary arduino-libraries/ArduinoMqttClient
7173
- installLibrary arduino-libraries/MKRGSM
74+
- installLibrary arduino-libraries/MKRWAN
7275
- installLibrary arduino-libraries/RTCZero
7376
- installLibrary arduino-libraries/WiFi101
7477
- installLibrary arduino-libraries/WiFiNINA
@@ -87,6 +90,11 @@ script:
8790
buildExampleSketch ArduinoIoTCloud_Travis_CI;
8891
buildExampleUtilitySketch Provisioning;
8992
fi
93+
- |
94+
if [ "$BOARD" == "arduino:samd:mkrwan1300" ]; then
95+
buildExampleSketch ArduinoIoTCloud_LED_switch;
96+
buildExampleSketch ArduinoIoTCloud_Travis_CI;
97+
fi
9098
- |
9199
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ]; then
92100
buildExampleSketch WiFi_Cloud_Blink;

Diff for: examples/ArduinoIoTCloud_LED_switch/ArduinoIoTCloud_LED_switch.ino

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
77
88
IMPORTANT:
9-
This sketch will work with both WiFi and GSM enabled boards supported by Arduino IoT Cloud.
10-
By default, settings for WiFi are chosen. If you prefer to use a GSM board take a look at thingProperties.h arduino_secrets.h,
11-
to make sure you uncomment what's needed and comment incompatible instructions.
9+
This sketch will work with WiFi, GSM and Lora enabled boards supported by Arduino IoT Cloud.
10+
On a LoRa board, if it is configuered as a class A device (default and preferred option), values from Cloud dashboard are received
11+
only after a value is sent to Cloud.
1212
1313
This sketch is compatible with:
1414
- MKR 1000
1515
- MKR WIFI 1010
1616
- MKR GSM 1400
17+
- MKR WAN 1300/1310
1718
*/
1819
#include "arduino_secrets.h"
1920
#include "thingProperties.h"
@@ -30,7 +31,7 @@ void setup() {
3031

3132
// initProperties takes care of connecting your sketch variables to the ArduinoIoTCloud object
3233
initProperties();
33-
// tell ArduinoIoTCloud to use our WiFi connection
34+
// tell ArduinoIoTCloud to use right connection handler
3435
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
3536

3637
/*

Diff for: examples/ArduinoIoTCloud_LED_switch/arduino_secrets.h

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
#define SECRET_LOGIN ""
1414
#define SECRET_PASS ""
1515
#endif
16+
17+
/* MKR WAN 1300/1310 */
18+
#if defined(BOARD_HAS_LORA)
19+
#define SECRET_APP_EUI ""
20+
#define SECRET_APP_KEY ""
21+
#endif

Diff for: examples/ArduinoIoTCloud_LED_switch/thingProperties.h

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#if defined(BOARD_HAS_WIFI)
55
#elif defined(BOARD_HAS_GSM)
6+
#elif defined(BOARD_HAS_LORA)
67
#else
78
#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010 and MKR GSM 1400"
89
#endif
@@ -18,12 +19,20 @@ int potentiometer;
1819

1920
void initProperties() {
2021
ArduinoCloud.setThingId(THING_ID);
22+
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM)
2123
ArduinoCloud.addProperty(led, READWRITE, ON_CHANGE, onLedChange);
2224
ArduinoCloud.addProperty(potentiometer, READ, ON_CHANGE);
25+
#elif defined(BOARD_HAS_LORA)
26+
ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange);
27+
ArduinoCloud.addProperty(potentiometer, 2, READ, ON_CHANGE);
28+
#endif
29+
2330
}
2431

2532
#if defined(BOARD_HAS_WIFI)
2633
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
2734
#elif defined(BOARD_HAS_GSM)
2835
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
36+
#elif defined(BOARD_HAS_LORA)
37+
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, _lora_class::CLASS_A);
2938
#endif

Diff for: examples/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- MKR 1000
88
- MKR WIFI 1010
99
- MKR GSM 1400
10+
- MKR WAN 1300/1310
1011
*/
1112

1213
#include "arduino_secrets.h"

Diff for: examples/ArduinoIoTCloud_Travis_CI/arduino_secrets.h

+7
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@
1313
#define SECRET_LOGIN ""
1414
#define SECRET_PASS ""
1515
#endif
16+
17+
/* MKR WAN 1300/1310 */
18+
#if defined(BOARD_HAS_LORA)
19+
#define SECRET_APP_EUI ""
20+
#define SECRET_APP_KEY ""
21+
#endif
22+

Diff for: examples/ArduinoIoTCloud_Travis_CI/thingProperties.h

+37-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
#if defined(BOARD_HAS_WIFI)
99
#elif defined(BOARD_HAS_GSM)
10+
#elif defined(BOARD_HAS_LORA)
1011
#else
11-
#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010 and MKR GSM 1400"
12+
#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR GSM 1400 and MKR WAN 1300/1310"
1213
#endif
1314

1415
/******************************************************************************
@@ -57,6 +58,8 @@ String str_property_8;
5758
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
5859
#elif defined(BOARD_HAS_GSM)
5960
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
61+
#elif defined(BOARD_HAS_LORA)
62+
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, EU868);
6063
#endif
6164

6265
/******************************************************************************
@@ -71,7 +74,7 @@ void onStringPropertyChange();
7174
/******************************************************************************
7275
FUNCTIONS
7376
******************************************************************************/
74-
77+
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM)
7578
void initProperties() {
7679
ArduinoCloud.setThingId(THING_ID);
7780

@@ -101,3 +104,35 @@ void initProperties() {
101104
ArduinoCloud.addProperty(str_property_7, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(CLOUD_WINS);
102105
ArduinoCloud.addProperty(str_property_8, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(DEVICE_WINS);
103106
}
107+
108+
#elif defined(BOARD_HAS_LORA)
109+
void initProperties() {
110+
ArduinoCloud.setThingId(THING_ID);
111+
112+
ArduinoCloud.addProperty(bool_property_1, 1, READWRITE, 1 * SECONDS);
113+
ArduinoCloud.addProperty(int_property_1, 2, READ, 2 * MINUTES);
114+
ArduinoCloud.addProperty(float_property_1, 3, WRITE, 3 * HOURS);
115+
ArduinoCloud.addProperty(str_property_1, 4, READWRITE, 4 * DAYS);
116+
117+
ArduinoCloud.addProperty(bool_property_2, 5, Permission::ReadWrite).publishEvery(1 * SECONDS);
118+
ArduinoCloud.addProperty(int_property_2, 6, Permission::Read).publishEvery(1 * MINUTES);
119+
ArduinoCloud.addProperty(float_property_2, 7, Permission::Write).publishEvery(3 * HOURS);
120+
ArduinoCloud.addProperty(str_property_2, 8, Permission::ReadWrite).publishEvery(4 * DAYS);
121+
122+
ArduinoCloud.addProperty(int_property_3, 9, READWRITE, ON_CHANGE); /* Default 'minDelta' = 0 */
123+
ArduinoCloud.addProperty(int_property_4, 10, READWRITE, ON_CHANGE, onIntPropertyChange); /* Default 'minDelta' = 0 */
124+
ArduinoCloud.addProperty(int_property_5, 11, READWRITE, ON_CHANGE, 0 /* onIntPropertyChange */, MIN_DELTA_INT_PROPERTY);
125+
ArduinoCloud.addProperty(int_property_6, 12, READWRITE, ON_CHANGE, onIntPropertyChange, MIN_DELTA_INT_PROPERTY);
126+
127+
ArduinoCloud.addProperty(float_property_3, 13, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY);
128+
ArduinoCloud.addProperty(float_property_4, 14, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY).onUpdate(onFloatPropertyChange);
129+
130+
ArduinoCloud.addProperty(str_property_3, 15, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, MOST_RECENT_WINS);
131+
ArduinoCloud.addProperty(str_property_4, 16, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, CLOUD_WINS);
132+
ArduinoCloud.addProperty(str_property_5, 17, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, DEVICE_WINS);
133+
134+
ArduinoCloud.addProperty(str_property_6, 18, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(MOST_RECENT_WINS);
135+
ArduinoCloud.addProperty(str_property_7, 19, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(CLOUD_WINS);
136+
ArduinoCloud.addProperty(str_property_8, 20, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(DEVICE_WINS);
137+
}
138+
#endif

Diff for: extras/codespell-ignore-words-list.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wan

0 commit comments

Comments
 (0)