Hi Arduino community!
I am trying to develop an application for reading some sensors, upload via POST to a REST service and sleep my device, it is using batteries so for me is very important to be able to stay alive as much as we can.
RTCZero rtc;
const byte seconds = 0;
const_byte minutes = 0;
const byte hours = 0;
const byte day = 27;
const byte month = 11;
const byte year = 18;
int transmisionStatus = 0;
char rxBuf[64];
int rxBufIndex;
bool matched = false;
#define DHTPIN 7 // Pin which is connected to the DHT sensor.
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define FAHRENHEIT 0
GSM gsmAccess; // GSM access: include a 'true' parameter for debug enabled
GPRS gprsAccess; // GPRS access
GSMClient gsmClient;
GSMClient client; // Client service for TCP connection
DHT dht(DHTPIN, DHTTYPE);
String response = "";
String okmsg = "ok";
String errormsg = "error";
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Serial.begin(115200);
Serial.println(F("Starting Adafruit TSL2591 Test!"));
if (tsl.begin())
{
Serial.println(F("Found a TSL2591 sensor"));
}
else
{
Serial.println(F("No sensor found ... check your wiring?"));
while (1);
}
/* Display some basic information on this sensor */
displaySensorDetails();
/* Configure the sensor */
configureSensor();
// Wait for 1mins to see if Serial is connected, otherwise run the Sktech without Serial debugging
int i;
for (i = 0; i < 60; i++) {
if (Serial) break;
delay(1000);
}
rtc.begin();
rtc.setTime(hours, minutes, seconds);
rtc.setDate(day, month, year);
rtc.setAlarmTime(00, 00, 00);
rtc.enableAlarm(rtc.MATCH_SS);
// rtc.enableAlarm(rtc.MATCH_MMSS);
//rtc.enableAlarm(rtc.MATCH_HHMMSS);
// minutes+=1;
rtc.attachInterrupt(alarmMatch);
rtc.standbyMode();
}
void unifiedSensorAPIRead(void)
{
sensors_event_t event;
tsl.getEvent(&event);
Serial.print(F("[ ")); Serial.print(event.timestamp); Serial.print(F(" ms ] "));
if ((event.light == 0) |
(event.light > 4294966000.0) |
(event.light < -4294966000.0))
{
Serial.println(F("Invalid data (adjust gain or timing)"));
}
else
{
Serial.print(event.light); Serial.println(F(" lux"));
lux = event.light;
}
}
void loop() {
if (matched){
matched = false;
delay(9000);
digitalWrite(LED_BUILTIN, LOW);
if (gsmAccess.begin(PINNUMBER) != GSM_READY) {
while (true);
} else {
if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY) {
} else {
float h = dht.readHumidity();
float t;
if (FAHRENHEIT) {
t = dht.readTemperature(true);
} else {
t = dht.readTemperature();
}
unifiedSensorAPIRead();
if (client.available()) {
char c = client.read();
// Serial.print(c);
}
if (!client.connected() && conexion) {
client.stop();
}
if (!client.connected() && !conexion) {
conexion = client.connected();
sendDATA;
}
}
int alarmMinutes = rtc.getSeconds();
alarmMinutes += 1;
if (alarmMinutes >= 60){
alarmMinutes -=60;
}
gsmAccess.shutdown();
delay(1000);
rtc.standbyMode();
}
}
}
void alarmMatch()
{
matched = true;
}
This is more and less my code, I have deleted some parts and I have commented all the if serial on my code for checking if it was something that was making some trouble.
My main problem is that device is not responding good for waking up and sending the data, it makes like 1 cycle and it works perfect but then it stops to work and never ever again send the sensors readed to the server.
Other problem is that when standbyMode is called serial via command line is dead so I am not able to read if something is happening or no.
Can anyone help me debbuging and looking best solution to provide more life to the batteries?
Thank you and regards!