1919#include < lte.h>
2020#include < mqtt_client.h>
2121
22- #define DEVICE_ID " device_id "
22+ #define DEVICE_ID " <name your plant monitoring system here> "
2323#define AWS_PUB_TOPIC " sensorData"
2424
2525// Define whether you want to use power save (not available on all operators),
@@ -40,31 +40,31 @@ Adafruit_VEML7700 veml = Adafruit_VEML7700();
4040 */
4141bool setupSensors () {
4242 if (!seesaw.begin (0x36 )) {
43- Log.error (" Adafruit seesaw not found." );
43+ Log.error (F ( " Adafruit seesaw not found." ) );
4444 return false ;
4545 }
4646
4747 if (!aht.begin (&Wire1)) {
48- Log.error (" Adafruit AHT not found." );
48+ Log.error (F ( " Adafruit AHT not found." ) );
4949 return false ;
5050 }
5151
5252 if (!veml.begin (&Wire1)) {
53- Log.error (" Adafruit VEML7700 not found." );
53+ Log.error (F ( " Adafruit VEML7700 not found." ) );
5454 return false ;
5555 }
5656
5757 // We want to shutdown the onboard sensors to save power as they are not
5858 // used
5959 if (Mcp9808.begin ()) {
60- Log.error (" Could not start MCP9808." );
60+ Log.error (F ( " Could not start MCP9808." ) );
6161 return false ;
6262 }
6363
6464 Mcp9808.shutdown ();
6565
6666 if (Veml3328.begin ()) {
67- Log.error (" Could not start VEML3328." );
67+ Log.error (F ( " Could not start VEML3328." ) );
6868 return false ;
6969 }
7070
@@ -78,16 +78,17 @@ void setup() {
7878 LedCtrl.startupCycle ();
7979
8080 Log.begin (115200 );
81- Log.info (" Starting up plant monitoring example\r\n " );
81+ Log.info (F ( " Starting up plant monitoring example\r\n " ) );
8282
8383 if (!setupSensors ()) {
8484 while (1 ) {}
8585 }
8686
8787#if defined(USE_POWER_SAVE) && !defined(USE_POWER_DOWN)
8888 // Configure power save. Here we set to sleep for 30 minutes
89- LowPower.configurePeriodicPowerSave (PowerSaveModePeriodMultiplier::MINUTES,
90- 1 );
89+ LowPower.configurePeriodicPowerSave (
90+ PowerSaveModePeriodMultiplier::ONE_MINUTE,
91+ 1 );
9192#elif !defined(USE_POWER_SAVE) && defined(USE_POWER_DOWN)
9293 // Configure power down. Note that here we don't need to preconfigure the
9394 // time to power down
@@ -145,22 +146,19 @@ void loop() {
145146 // Attempt to connect to the operator
146147 if (!Lte.begin ()) {
147148 return ;
149+ } else {
150+ Log.infof (F (" Connected to operator %s\r\n " ),
151+ Lte.getOperator ().c_str ());
148152 }
153+ }
149154
150- // Attempt to connect to AWS
151- if (MqttClient.beginAWS ()) {
152-
153- Log.infof (" Connecting to AWS" );
154-
155- while (!MqttClient.isConnected ()) {
156- Log.rawf (" ." );
157- delay (500 );
155+ if (Lte.isConnected ()) {
156+ // Check if we are connected to the cloud. If not, attempt to connect
157+ if (!MqttClient.isConnected ()) {
158+ if (!MqttClient.beginAWS ()) {
159+ Log.error (F (" Failed to connect to AWS." ));
160+ return ;
158161 }
159-
160- Log.rawf (" OK!\r\n " );
161- } else {
162- Log.error (" Failed to configure MqttClient for AWS" );
163- while (1 ) {}
164162 }
165163 }
166164
@@ -170,20 +168,20 @@ void loop() {
170168 static char data[512 ] = " " ;
171169
172170 if (retrieveData (data, sizeof (data)) > sizeof (data)) {
173- Log.error (" Data buffer too small." );
171+ Log.error (F ( " Data buffer too small." ) );
174172 while (1 ) {}
175173 }
176174
177- /*
178- Log.infof("Publishing data: %s\r\n", data);
175+ Log.infof (F (" Publishing data: %s\r\n " ), data);
179176 if (!MqttClient.publish (AWS_PUB_TOPIC, data)) {
180- Log.warn("Failed to publish data");
177+ Log.warn (F ( " Failed to publish data" ) );
181178 }
182- */
183179
184180#if defined(USE_POWER_SAVE) && !defined(USE_POWER_DOWN)
181+ Log.info (F (" Power saving..." ));
185182 LowPower.powerSave ();
186183#elif !defined(USE_POWER_SAVE) && defined(USE_POWER_DOWN)
184+ Log.info (F (" Powering down..." ));
187185 // Power down for 1 minute
188186 LowPower.powerDown (60 );
189187#elif defined(USE_POWER_SAVE) && defined(USE_POWER_DOWN)
0 commit comments