Hi,
I am trying to have my Arduino attempt to reconnect to the cellular network if it loses connection. Additionally, the board is set to sleep for 20 seconds after sending a set of updated values. If it doesn't connect, I want it to continually try and update until it is successful and then sleep. I have pasted the main code below and attached all the files for reference.
#include "ArduinoLowPower.h"
#include "thingProperties.h"
#include "dht11.h"#define DHT11PIN 5
dht11 DHT11;
const int trigPin = 7; const int echoPin = 6;float duration; float speedOfSound;
void setup() {
pinMode(trigPin,OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin,INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Initialize serial and wait for port to open:
delay(3000); // This delay gives the chance to wait for a Serial Monitor without blocking if none is foundinitProperties(); // Defined in thingProperties.h
ArduinoCloud.begin(ArduinoIoTPreferredConnection); // Connect to Arduino IoT Cloud
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
delay(1000);
}void loop() {
ArduinoCloud.update();digitalWrite(trigPin, LOW); // Clears the trigPin
delayMicroseconds(10);
digitalWrite(trigPin, HIGH); // write the Trigger for MCU on Module
delayMicroseconds(20);
digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH); // Using the Formula
DHT11.read(DHT11PIN);
speedOfSound = 331.4+(.606DHT11.temperature)+(.0124DHT11.humidity);//distance= ((duration/2)(speedOfSound/10000)(.393701)); //this is for the raw sensor
distance= duration*0.0393701; //this is for the MaxBotix sensot, 1000us = 1mm
temperature = DHT11.temperature * 9/5+32; //temp from DHT11
humidity= DHT11.humidity; //humidity from DHT11
battery = analogRead(ADC_BATTERY) * (4.3 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 4.3V):
Serial.print("Battery Voltage: "); Serial.println(battery);
Serial.print("Distance: "); Serial.println(distance);
Serial.print("Temperature: "); Serial.println(temperature);
Serial.print("Humidity: "); Serial.println(humidity);
Serial.print("duration: "); Serial.println(duration);
Serial.print("speedOfSound: "); Serial.println(speedOfSound);
Serial.print("Connected "); Serial.println(ArduinoCloud.connected());if (ArduinoCloud.connected() == 1) {
ArduinoCloud.update();
LowPower.sleep(20000); //sleeps for 20 seconds
}
ArduinoCloud.begin(ArduinoIoTPreferredConnection); // Connect to Arduino IoT Cloud
delay(15000);
}
arduino_secrets.h (98 Bytes)
dht11.cpp (2.01 KB)
dht11.h (737 Bytes)
stream_gauge_sleep.ino (2.26 KB)
thingProperties.h (821 Bytes)