Skip to content

Commit e4e11e5

Browse files
committed
- extended example with GSM compatibility options
- fixed typo in example - cleanup GSMConnectionManager - cleanup WiFiConnectionManager - fixed missing WiFiUDP member which broke compilation
1 parent 8eefcc0 commit e4e11e5

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

examples/ArduinoIoTCloud_LED_switch/ArduinoIoTCloud_LED_switch.ino

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
When the potentiometer (or sensor) value changes the data is sent to the Cloud.
66
When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
77
8-
8+
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.
12+
913
*/
1014
#include "arduino_secrets.h"
1115
#include "thingProperties.h"
@@ -51,5 +55,5 @@ void loop() {
5155
void onLedChange() {
5256
Serial.print("LED set to ");
5357
Serial.println(led);
54-
digitalWrite(LED_BUILTIN, ledSwitch);
58+
digitalWrite(LED_BUILTIN, led);
5559
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
Fill in your login credentials:
3+
4+
The following lines are used for WiFi enabled boards (MKR1000, MKR WiFi 1010)
5+
*/
16
#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
27
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
3-
8+
/*
9+
If you prefer using a MKR GSM 1400 comment the lines above and uncommet the following.
10+
PIN, APN, Login and Password are supplied by your Cellular Data provider.
11+
*/
12+
//#define SECRET_PIN ""
13+
//#define SECRET_APN ""
14+
//#define SECRET_LOGIN ""
15+
//#define SECRET_PASS ""

examples/ArduinoIoTCloud_LED_switch/thingProperties.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#include <ArduinoIoTCloud.h>
2+
/*
3+
The following include line is used for WiFi enabled boards (MKR1000, MKR WiFi 1010)
4+
*/
25
#include <WiFiConnectionManager.h>
6+
/*
7+
If you prefer using a MKR GSM 1400 comment the line above and uncommet the following.
8+
*/
9+
//#include <GSMConnectionManager.h>
310

4-
5-
char ssid[] = SECRET_SSID; // your network SSID (name)
6-
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
711
// Your THING_ID
812
#define THING_ID "ARDUINO_IOT_CLOUD_THING_ID"
913

@@ -18,4 +22,11 @@ void initProperties() {
1822
ArduinoCloud.addProperty(potentiometer, READ, ON_CHANGE);
1923
}
2024

21-
ConnectionManager *ArduinoIoTPreferredConnection = new WiFiConnectionManager(SECRET_SSID, SECRET_PASS);
25+
/*
26+
The following include line is used for WiFi enabled boards (MKR1000, MKR WiFi 1010)
27+
*/
28+
ConnectionManager *ArduinoIoTPreferredConnection = new WiFiConnectionManager(SECRET_SSID, SECRET_PASS);
29+
/*
30+
If you prefer using a MKR GSM 1400 comment the line above and uncommet the following.
31+
*/
32+
//ConnectionManager *ArduinoIoTPreferredConnection = new GSMConnectionManager(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);

src/GSMConnectionManager.h

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class GSMConnectionManager : public ConnectionManager {
5151
unsigned long lastConnectionTickTime;
5252
unsigned long getTimeRetries;
5353
int connectionTickTimeInterval;
54-
GSMUDP Udp;
5554

5655
};
5756

src/WiFiConnectionManager.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "ConnectionManager.h"
19+
#include <WiFiUdp.h>
1920

2021
class WiFiConnectionManager : public ConnectionManager {
2122
public:
@@ -27,6 +28,8 @@ class WiFiConnectionManager : public ConnectionManager {
2728
virtual Client &getClient() { return wifiClient; };
2829
virtual UDP &getUDP() { return udp; };
2930

31+
WiFiUDP udp;
32+
3033
private:
3134

3235
void changeConnectionState(NetworkConnectionState _newState);
@@ -125,7 +128,7 @@ void WiFiConnectionManager::check() {
125128
if(WiFi.firmwareVersion() < WIFI_FIRMWARE_VERSION_REQUIRED){
126129
sprintf(msgBuffer, "Latest WiFi Firmware: %s", WIFI_FIRMWARE_VERSION_REQUIRED);
127130
debugMessage(msgBuffer, 0);
128-
debugMessage("Please update to latest version for optimal performance.", 0);
131+
debugMessage("Please update to the latest version for best performance.", 0);
129132
delay(5000);
130133
}
131134
changeConnectionState(CONNECTION_STATE_CONNECTING);

0 commit comments

Comments
 (0)