|
| 1 | +#include <ArduinoIoTCloud.h> |
| 2 | +#include <Arduino_ConnectionHandler.h> |
| 3 | +#include "arduino_secrets.h" |
| 4 | + |
| 5 | +#if !(defined(HAS_TCP) || defined(HAS_LORA)) |
| 6 | + #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what" |
| 7 | +#endif |
| 8 | + |
| 9 | +#if defined(BOARD_HAS_SECRET_KEY) |
| 10 | + #define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 11 | +#endif |
| 12 | + |
| 13 | +#if defined(HAS_LORA) |
| 14 | + #define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
| 15 | +#endif |
| 16 | + |
| 17 | +void onLedChange(); |
| 18 | + |
| 19 | +bool led; |
| 20 | +int potentiometer; |
| 21 | +int seconds; |
| 22 | + |
| 23 | +void initProperties() { |
| 24 | +#if defined(BOARD_HAS_SECRET_KEY) |
| 25 | + ArduinoCloud.setBoardId(BOARD_ID); |
| 26 | + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); |
| 27 | +#endif |
| 28 | +#if defined(HAS_TCP) |
| 29 | + ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange); |
| 30 | + ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10); |
| 31 | + ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1); |
| 32 | +#elif defined(HAS_LORA) |
| 33 | + ArduinoCloud.addProperty(led, 1, Permission::ReadWrite).onUpdate(onLedChange); |
| 34 | + ArduinoCloud.addProperty(potentiometer, 2, Permission::Read).publishOnChange(10); |
| 35 | + ArduinoCloud.addProperty(seconds, 3, Permission::Read).publishEvery(5 * MINUTES); |
| 36 | + |
| 37 | + ArduinoCloud.setThingId(THING_ID); |
| 38 | +#endif |
| 39 | +} |
| 40 | + |
| 41 | +#if defined(BOARD_HAS_ETHERNET) |
| 42 | + /* DHCP mode */ |
| 43 | + //EthernetConnectionHandler ArduinoIoTPreferredConnection; |
| 44 | + /* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */ |
| 45 | + EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK); |
| 46 | +#elif defined(BOARD_HAS_WIFI) |
| 47 | + WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS); |
| 48 | +#elif defined(BOARD_HAS_GSM) |
| 49 | + GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); |
| 50 | +#elif defined(BOARD_HAS_LORA) |
| 51 | + LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); |
| 52 | +#elif defined(BOARD_HAS_NB) |
| 53 | + NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); |
| 54 | +#elif defined(BOARD_HAS_CATM1_NBIOT) |
| 55 | + CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); |
| 56 | +#elif defined(BOARD_HAS_CELLULAR) |
| 57 | + CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); |
| 58 | +#endif |
0 commit comments