From e57ab50f841ade1dd9af7b7c3271c84d3e345c4a Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 14 Aug 2024 11:07:32 +0200 Subject: [PATCH 1/2] examples: add CellularConnectionHandler --- examples/ArduinoIoTCloud-Advanced/arduino_secrets.h | 4 +++- examples/ArduinoIoTCloud-Advanced/thingProperties.h | 2 ++ examples/ArduinoIoTCloud-Basic/arduino_secrets.h | 4 +++- examples/ArduinoIoTCloud-Basic/thingProperties.h | 2 ++ examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h | 4 +++- examples/ArduinoIoTCloud-Callbacks/thingProperties.h | 2 ++ examples/ArduinoIoTCloud-Schedule/arduino_secrets.h | 4 +++- examples/ArduinoIoTCloud-Schedule/thingProperties.h | 2 ++ examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h | 4 +++- examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h | 2 ++ 10 files changed, 25 insertions(+), 5 deletions(-) diff --git a/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h b/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h index 44a9e21d..0be56888 100644 --- a/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h +++ b/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h @@ -14,7 +14,9 @@ #endif /* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */ -#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_CATM1_NBIOT) +/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */ +#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \ + defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR) #define SECRET_PIN "" #define SECRET_APN "" #define SECRET_LOGIN "" diff --git a/examples/ArduinoIoTCloud-Advanced/thingProperties.h b/examples/ArduinoIoTCloud-Advanced/thingProperties.h index 43187104..21639c45 100644 --- a/examples/ArduinoIoTCloud-Advanced/thingProperties.h +++ b/examples/ArduinoIoTCloud-Advanced/thingProperties.h @@ -49,4 +49,6 @@ void initProperties() { //EthernetConnectionHandler ArduinoIoTPreferredConnection; /* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */ EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK); +#elif defined(BOARD_HAS_CELLULAR) + CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); #endif diff --git a/examples/ArduinoIoTCloud-Basic/arduino_secrets.h b/examples/ArduinoIoTCloud-Basic/arduino_secrets.h index 44a9e21d..0be56888 100644 --- a/examples/ArduinoIoTCloud-Basic/arduino_secrets.h +++ b/examples/ArduinoIoTCloud-Basic/arduino_secrets.h @@ -14,7 +14,9 @@ #endif /* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */ -#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_CATM1_NBIOT) +/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */ +#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \ + defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR) #define SECRET_PIN "" #define SECRET_APN "" #define SECRET_LOGIN "" diff --git a/examples/ArduinoIoTCloud-Basic/thingProperties.h b/examples/ArduinoIoTCloud-Basic/thingProperties.h index 4193b440..16f75829 100644 --- a/examples/ArduinoIoTCloud-Basic/thingProperties.h +++ b/examples/ArduinoIoTCloud-Basic/thingProperties.h @@ -48,4 +48,6 @@ void initProperties() { NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); #elif defined(BOARD_HAS_CATM1_NBIOT) CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_CELLULAR) + CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); #endif diff --git a/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h b/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h index 44a9e21d..0be56888 100644 --- a/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h +++ b/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h @@ -14,7 +14,9 @@ #endif /* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */ -#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_CATM1_NBIOT) +/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */ +#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \ + defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR) #define SECRET_PIN "" #define SECRET_APN "" #define SECRET_LOGIN "" diff --git a/examples/ArduinoIoTCloud-Callbacks/thingProperties.h b/examples/ArduinoIoTCloud-Callbacks/thingProperties.h index 8f2b5055..89a365ce 100644 --- a/examples/ArduinoIoTCloud-Callbacks/thingProperties.h +++ b/examples/ArduinoIoTCloud-Callbacks/thingProperties.h @@ -33,4 +33,6 @@ void initProperties() { //EthernetConnectionHandler ArduinoIoTPreferredConnection; /* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */ EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK); +#elif defined(BOARD_HAS_CELLULAR) + CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); #endif diff --git a/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h b/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h index 44a9e21d..0be56888 100644 --- a/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h +++ b/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h @@ -14,7 +14,9 @@ #endif /* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */ -#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_CATM1_NBIOT) +/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */ +#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \ + defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR) #define SECRET_PIN "" #define SECRET_APN "" #define SECRET_LOGIN "" diff --git a/examples/ArduinoIoTCloud-Schedule/thingProperties.h b/examples/ArduinoIoTCloud-Schedule/thingProperties.h index 8d2d7dfc..0af38fe3 100644 --- a/examples/ArduinoIoTCloud-Schedule/thingProperties.h +++ b/examples/ArduinoIoTCloud-Schedule/thingProperties.h @@ -56,4 +56,6 @@ void initProperties() { //EthernetConnectionHandler ArduinoIoTPreferredConnection; /* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */ EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK); +#elif defined(BOARD_HAS_CELLULAR) + CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); #endif diff --git a/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h b/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h index 2ae0cefa..a3fd8a7e 100644 --- a/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h +++ b/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h @@ -14,7 +14,9 @@ #endif /* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */ -#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_CATM1_NBIOT) +/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */ +#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \ + defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR) #define SECRET_PIN "" #define SECRET_APN "" #define SECRET_LOGIN "" diff --git a/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h b/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h index 36604ebf..8ecd7077 100644 --- a/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h +++ b/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h @@ -69,6 +69,8 @@ String str_property_8; //EthernetConnectionHandler ArduinoIoTPreferredConnection; /* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */ EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK); +#elif defined(BOARD_HAS_CELLULAR) + CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); #endif /****************************************************************************** From bd8de84bfc7f5a38d72f8e6c02eb0a6ffba6165c Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 14 Aug 2024 11:10:03 +0200 Subject: [PATCH 2/2] examples: use HAS_TCP or HAS_LORA to reduce maintenance efforts --- examples/ArduinoIoTCloud-Advanced/thingProperties.h | 9 ++++----- examples/ArduinoIoTCloud-Basic/thingProperties.h | 9 ++++----- examples/ArduinoIoTCloud-Callbacks/thingProperties.h | 5 ++--- examples/ArduinoIoTCloud-Schedule/thingProperties.h | 9 ++++----- .../ArduinoIoTCloud_Travis_CI/thingProperties.h | 11 +++++------ 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/examples/ArduinoIoTCloud-Advanced/thingProperties.h b/examples/ArduinoIoTCloud-Advanced/thingProperties.h index 21639c45..6e1e6656 100644 --- a/examples/ArduinoIoTCloud-Advanced/thingProperties.h +++ b/examples/ArduinoIoTCloud-Advanced/thingProperties.h @@ -2,9 +2,8 @@ #include #include "arduino_secrets.h" -#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \ - defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)) - #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" +#if !(defined(HAS_TCP) || defined(HAS_LORA)) + #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" #endif #if defined(BOARD_HAS_SECRET_KEY) @@ -23,11 +22,11 @@ void initProperties() { ArduinoCloud.setBoardId(BOARD_ID); ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); #endif -#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) +#if defined(HAS_TCP) ArduinoCloud.addProperty(switchButton, Permission::Write).onUpdate(onSwitchButtonChange); ArduinoCloud.addProperty(location, Permission::Read).publishOnChange(0.0f); ArduinoCloud.addProperty(color, Permission::ReadWrite).onUpdate(onColorChange); -#elif defined(BOARD_HAS_LORA) +#elif defined(HAS_LORA) ArduinoCloud.addProperty(switchButton, 1, Permission::Write).onUpdate(onSwitchButtonChange); ArduinoCloud.addProperty(location, 2, Permission::Read).publishOnChange(0.0f); ArduinoCloud.addProperty(color, 3, Permission::ReadWrite).onUpdate(onColorChange); diff --git a/examples/ArduinoIoTCloud-Basic/thingProperties.h b/examples/ArduinoIoTCloud-Basic/thingProperties.h index 16f75829..48be1bf9 100644 --- a/examples/ArduinoIoTCloud-Basic/thingProperties.h +++ b/examples/ArduinoIoTCloud-Basic/thingProperties.h @@ -2,9 +2,8 @@ #include #include "arduino_secrets.h" -#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \ - defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)) - #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" +#if !(defined(HAS_TCP) || defined(HAS_LORA)) + #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" #endif #if defined(BOARD_HAS_SECRET_KEY) @@ -22,11 +21,11 @@ void initProperties() { ArduinoCloud.setBoardId(BOARD_ID); ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); #endif -#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) +#if defined(HAS_TCP) ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange); ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10); ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1); -#elif defined(BOARD_HAS_LORA) +#elif defined(HAS_LORA) ArduinoCloud.addProperty(led, 1, Permission::ReadWrite).onUpdate(onLedChange); ArduinoCloud.addProperty(potentiometer, 2, Permission::Read).publishOnChange(10); ArduinoCloud.addProperty(seconds, 3, Permission::Read).publishEvery(5 * MINUTES); diff --git a/examples/ArduinoIoTCloud-Callbacks/thingProperties.h b/examples/ArduinoIoTCloud-Callbacks/thingProperties.h index 89a365ce..d52660a9 100644 --- a/examples/ArduinoIoTCloud-Callbacks/thingProperties.h +++ b/examples/ArduinoIoTCloud-Callbacks/thingProperties.h @@ -2,9 +2,8 @@ #include #include "arduino_secrets.h" -#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \ - defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)) - #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" +#if !(defined(HAS_TCP) || defined(HAS_LORA)) + #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" #endif #if defined(BOARD_HAS_SECRET_KEY) diff --git a/examples/ArduinoIoTCloud-Schedule/thingProperties.h b/examples/ArduinoIoTCloud-Schedule/thingProperties.h index 0af38fe3..8a3d21f9 100644 --- a/examples/ArduinoIoTCloud-Schedule/thingProperties.h +++ b/examples/ArduinoIoTCloud-Schedule/thingProperties.h @@ -2,9 +2,8 @@ #include #include "arduino_secrets.h" -#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \ - defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)) - #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" +#if !(defined(HAS_TCP) || defined(HAS_LORA)) + #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" #endif #if defined(BOARD_HAS_SECRET_KEY) @@ -27,7 +26,7 @@ void initProperties() { ArduinoCloud.setBoardId(BOARD_ID); ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); #endif -#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) +#if defined(HAS_TCP) ArduinoCloud.addProperty(switchButton, Permission::Write); ArduinoCloud.addProperty(oneShot, Permission::ReadWrite); ArduinoCloud.addProperty(minute, Permission::ReadWrite); @@ -36,7 +35,7 @@ void initProperties() { ArduinoCloud.addProperty(weekly, Permission::ReadWrite); ArduinoCloud.addProperty(monthly, Permission::ReadWrite); ArduinoCloud.addProperty(yearly, Permission::ReadWrite); -#elif defined(BOARD_HAS_LORA) +#elif defined(HAS_LORA) ArduinoCloud.addProperty(switchButton, 1, Permission::Write); #endif } diff --git a/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h b/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h index 8ecd7077..2574220f 100644 --- a/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h +++ b/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h @@ -2,9 +2,8 @@ #include #include "arduino_secrets.h" -#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \ - defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)) - #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" +#if !(defined(HAS_TCP) || defined(HAS_LORA)) + #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" #endif /****************************************************************************** @@ -15,7 +14,7 @@ #define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" #endif -#if defined(BOARD_HAS_LORA) +#if defined(HAS_LORA) #define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" #endif @@ -85,7 +84,7 @@ void onStringPropertyChange(); /****************************************************************************** FUNCTIONS ******************************************************************************/ -#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined (BOARD_HAS_NB) || defined (BOARD_HAS_CATM1_NBIOT) +#if defined(HAS_TCP) void initProperties() { #if defined(BOARD_HAS_SECRET_KEY) ArduinoCloud.setBoardId(BOARD_ID); @@ -118,7 +117,7 @@ void initProperties() { ArduinoCloud.addProperty(str_property_8, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(DEVICE_WINS); } -#elif defined(BOARD_HAS_LORA) +#elif defined(HAS_LORA) void initProperties() { ArduinoCloud.setThingId(THING_ID);