So I want to create an application where I can send data with a SIM-Module, and when it's not needed it should fall into a "standby-mode" because it's battery powered. But I always get this exact output, and I have no clue why:
wakeup condition fulfilled Tes
When it wants to print out "Testing ..." it always stops after three letters.
Here's my code:
/*
* PINOUT:
*
* UNO >> SIM800L
* RX (8) >> TX
* TX (9) >> RX
*
*/
#include <BareBoneSim800.h>
BareBoneSim800 sim800("hologram"); //APN of the carrier
void sendData(char *url)
{
sim800.enterSleepMode(false);
Serial.println("Testing GSM module For GPRS Connectivity");
delay(8000); // this delay is necessary, it helps the device to be ready and connect to a network
Serial.println("Should be ready by now");
bool deviceAttached = sim800.isAttached();
if (deviceAttached)
Serial.println("Device is Attached");
else
Serial.println("Not Attached");
// Connecting the the GPRS APN Network
Serial.println(" Connecting to APN");
bool netConnect = sim800.gprsConnect();
if (netConnect)
Serial.println("Connected to Network");
else
Serial.println("An Error Occured");
if (netConnect)
{
Serial.println("Making HTTP Get Request");
String result = sim800.sendHTTPData(url);
Serial.println("Received Info: ");
Serial.println(result);
Serial.println("Current time utc+0: ");
Serial.println(sim800.getTime());
}
sim800.closeHTTP(); // disconnect from server
sim800.gprsDisconnect();
sim800.enterSleepMode(true);
}
void wakingUp()
{
//hardware interrupt measurement goes here
}
void setup()
{
Serial.begin(9600);
sim800.begin();
while (!Serial)
;
//Save Power by writing all Digital IO LOW - note that pins just need to be tied one way or another, do not damage devices!
for (int i = 0; i < 20; i++)
{
if (i != 8 && i != 9 && i != 2)
{
// pin 2 is for waking the arduino up from deep sleep
//pin 8 and 9 are used to connect with the sim module,
//these pins must be exluded from power saving
pinMode(i, OUTPUT);
}
}
attachInterrupt(0, wakingUp, FALLING); //interrupt for waking up
/*
various flags for turning stuff down when not needed
based on this very good tutorial https://www.youtube.com/watch?v=urLSDi7SD8M
*/
//SETUP WATCHDOG TIMER
WDTCSR = (24); //change enable and WDE - also resets
WDTCSR = (33); //prescalers only - get rid of the WDE and WDCE bit
WDTCSR |= (1 << 6); //enable interrupt mode
//Disable ADC - don't forget to flip back after waking up if using ADC in your application ADCSRA |= (1 << 7);
//ADCSRA &= ~(1 << 7);
//ENABLE SLEEP - this enables the sleep mode
SMCR |= (1 << 2); //power down mode
SMCR |= 1; //enable sleep
//BOD DISABLE - this must be called right before the __asm__ sleep instruction
//MCUCR |= (3 << 5); //set both BODS and BODSE at the same time
//MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6); //then set the BODS bit and clear the BODSE bit at the same time
__asm__ __volatile__("sleep"); //in line assembler to go to sleep
}
void loop()
{
//do nothing, use ISR instead
}
char targetURL[] = "http://www.example.com/restAPI/";
ISR(WDT_vect)
{
//DON'T FORGET THIS! Needed for the watch dog timer. This is called after a watch dog timer timeout - this is the interrupt function called after waking up
//todo, turn on adc conversion again
int halfHourCounter = 0; //30 minutes => 225 8sec intervals
bool wakeUpCondition = (halfHourCounter % 225 == 0);
if (wakeUpCondition)
{
Serial.println("wakeup condition fulfilled");
//reset counter
halfHourCounter = 0;
//ADCSRA |= (1 << 7); // turn analog digital conversion back on
//... measure data and send it away :)
sendData(targetURL);
//ADCSRA &= ~(1 << 7); // disable ADC again
}
else
{
Serial.println("wakeup condition not fulfilled");
}
halfHourCounter += 1;
} // watchdog interrupt
I'm using an Arduino Uno in combination with a SIM800L evaluation board. If I call the sendData()-function without any standby-flags enabled everything works fine. Vice versa if I call just a print function for debugging with all the standby flags enabled