|
| 1 | +/****************************************************************************** |
| 2 | + * INCLUDE |
| 3 | + ******************************************************************************/ |
| 4 | + |
| 5 | +#include <ArduinoIoTCloud.h> |
| 6 | +#include <ConnectionManager.h> |
| 7 | + |
| 8 | +#if defined(BOARD_HAS_WIFI) |
| 9 | + #include <WiFiConnectionManager.h> |
| 10 | +#elif defined(BOARD_HAS_GSM) |
| 11 | + #include <GSMConnectionManager.h> |
| 12 | +#else |
| 13 | + #error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010 and MKR GSM 1400" |
| 14 | +#endif |
| 15 | + |
| 16 | +/****************************************************************************** |
| 17 | + * DEFINES |
| 18 | + ******************************************************************************/ |
| 19 | + |
| 20 | +#define THING_ID "ARDUINO_IOT_CLOUD_THING_ID" |
| 21 | + |
| 22 | +/****************************************************************************** |
| 23 | + * GLOBAL CONSTANTS |
| 24 | + ******************************************************************************/ |
| 25 | + |
| 26 | +int const MIN_DELTA_INT_PROPERTY = 5; |
| 27 | +float const MIN_DELTA_FLOAT_PROPERTY = 10.0f; |
| 28 | + |
| 29 | +/****************************************************************************** |
| 30 | + * GLOBAL VARIABLES |
| 31 | + ******************************************************************************/ |
| 32 | + |
| 33 | +bool bool_property_1; |
| 34 | +bool bool_property_2; |
| 35 | + |
| 36 | +int int_property_1; |
| 37 | +int int_property_2; |
| 38 | +int int_property_3; |
| 39 | +int int_property_4; |
| 40 | +int int_property_5; |
| 41 | +int int_property_6; |
| 42 | + |
| 43 | +float float_property_1; |
| 44 | +float float_property_2; |
| 45 | +float float_property_3; |
| 46 | +float float_property_4; |
| 47 | + |
| 48 | +String str_property_1; |
| 49 | +String str_property_2; |
| 50 | +String str_property_3; |
| 51 | +String str_property_4; |
| 52 | +String str_property_5; |
| 53 | +String str_property_6; |
| 54 | +String str_property_7; |
| 55 | +String str_property_8; |
| 56 | + |
| 57 | +#if defined(BOARD_HAS_WIFI) |
| 58 | +ConnectionManager * ArduinoIoTPreferredConnection = new WiFiConnectionManager(SECRET_SSID, SECRET_PASS); |
| 59 | +#elif defined(BOARD_HAS_GSM) |
| 60 | +ConnectionManager * ArduinoIoTPreferredConnection = new GSMConnectionManager (SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); |
| 61 | +#endif |
| 62 | + |
| 63 | +/****************************************************************************** |
| 64 | + * PROTOTYPES |
| 65 | + ******************************************************************************/ |
| 66 | + |
| 67 | +void onBoolPropertyChange (); |
| 68 | +void onIntPropertyChange (); |
| 69 | +void onFloatPropertyChange (); |
| 70 | +void onStringPropertyChange(); |
| 71 | + |
| 72 | +/****************************************************************************** |
| 73 | + * FUNCTIONS |
| 74 | + ******************************************************************************/ |
| 75 | + |
| 76 | +void initProperties() { |
| 77 | + ArduinoCloud.setThingId(THING_ID); |
| 78 | + |
| 79 | + ArduinoCloud.addProperty(bool_property_1, READWRITE, 1*SECONDS); |
| 80 | + ArduinoCloud.addProperty(int_property_1, READ, 2*MINUTES); |
| 81 | + ArduinoCloud.addProperty(float_property_1, WRITE, 3*HOURS ); |
| 82 | + ArduinoCloud.addProperty(str_property_1, READWRITE, 4*DAYS ); |
| 83 | + |
| 84 | + ArduinoCloud.addProperty(bool_property_2, Permission::ReadWrite).publishEvery(1*SECONDS); |
| 85 | + ArduinoCloud.addProperty(int_property_2, Permission::Read ).publishEvery(1*MINUTES); |
| 86 | + ArduinoCloud.addProperty(float_property_2, Permission::Write ).publishEvery(3*HOURS ); |
| 87 | + ArduinoCloud.addProperty(str_property_2, Permission::ReadWrite).publishEvery(4*DAYS ); |
| 88 | + |
| 89 | + ArduinoCloud.addProperty(int_property_3, READWRITE, ON_CHANGE); /* Default 'minDelta' = 0 */ |
| 90 | + ArduinoCloud.addProperty(int_property_4, READWRITE, ON_CHANGE, onIntPropertyChange); /* Default 'minDelta' = 0 */ |
| 91 | + ArduinoCloud.addProperty(int_property_5, READWRITE, ON_CHANGE, 0 /* onIntPropertyChange */, MIN_DELTA_INT_PROPERTY); |
| 92 | + ArduinoCloud.addProperty(int_property_6, READWRITE, ON_CHANGE, onIntPropertyChange, MIN_DELTA_INT_PROPERTY); |
| 93 | + |
| 94 | + ArduinoCloud.addProperty(float_property_3, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY); |
| 95 | + ArduinoCloud.addProperty(float_property_4, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY).onUpdate(onFloatPropertyChange); |
| 96 | + |
| 97 | + ArduinoCloud.addProperty(str_property_3, READWRITE, 1*SECONDS, 0 /* onStringPropertyChange */, "" /* 'minDelta' */, MOST_RECENT_WINS); |
| 98 | + ArduinoCloud.addProperty(str_property_4, READWRITE, 1*SECONDS, 0 /* onStringPropertyChange */, "" /* 'minDelta' */, CLOUD_WINS); |
| 99 | + ArduinoCloud.addProperty(str_property_5, READWRITE, 1*SECONDS, 0 /* onStringPropertyChange */, "" /* 'minDelta' */, DEVICE_WINS); |
| 100 | + |
| 101 | + ArduinoCloud.addProperty(str_property_6, Permission::ReadWrite).publishEvery(1*SECONDS).onSync(MOST_RECENT_WINS); |
| 102 | + ArduinoCloud.addProperty(str_property_7, Permission::ReadWrite).publishEvery(1*SECONDS).onSync(CLOUD_WINS); |
| 103 | + ArduinoCloud.addProperty(str_property_8, Permission::ReadWrite).publishEvery(1*SECONDS).onSync(DEVICE_WINS); |
| 104 | +} |
0 commit comments