Hello. I am having problems with my strings when I start implementing the sms.sendSMS. It seems that whenever I start using the sms.sendSMS, whatever i try to put inside the strings, nothing is stored.
without the sms.sendSMS, my serial monitor would print out:
09052391306
on 15
COMMAND GRABBED:
ON
NUMBER OF MINUTE(S):
15
IN MILLISECONDS:
900000
but with the sms.sendSMS, my serial monitor would print out:
09052391306
on 15
COMMAND GRABBED:
NUMBER OF MINUTE(S):
0
IN MILLISECONDS:
0
i need the the gsm module to tell me when the time is up, so i badly need the sms.sendSMS to work together with my strings.
here is my code:
#include "SIM900.h"
#include <SoftwareSerial.h>
#include<Servo.h>
#include "sms.h"
SMSGSM sms;
Servo myservo;
/****************************************************************************************************/
boolean GSMactive = false;
char smsbuffer[160];
char n[20];
char remoteNumber[20];
String intString = "";
String charString = "";
int minute = 0;
unsigned long int timeMillis = 0;
unsigned long int timeExact = 0;
unsigned long int activeRead = 0;
unsigned long int startRead = 0;
unsigned long int timeLeft = 0;
unsigned long int runTime = 0;
boolean timerActive = false;
boolean finalCount = false;
const int redLed = 4;
const int greenLed = 5;
const int blueLed = 6;
const int pwrON = 9;
/***************************************************************************************************/
void setup(){
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(pwrON, OUTPUT);
Serial.begin(9600);
digitalWrite(redLed, HIGH);
pwrOn();
Serial.println("DEVICE LOADING...");
if(gsm.begin(9600)){
Serial.println("STATUS = DEVICE READY");
GSMactive = true;
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
}
else{
Serial.println("STATUS = DEVICE IDLE");
digitalWrite(redLed, LOW);
digitalWrite(blueLed, HIGH);
}
}
/****************************************************************************************************/
void loop(){
intString = "";
charString = "";
minute = 0;
activeRead = millis();
if(timerActive){
runTime = activeRead - startRead;
timeLeft = timeExact - runTime;
Serial.println("TOTAL RUN TIME:");
Serial.println((float)runTime/60000);
Serial.println("TIME REMAINING:");
Serial.println((float)timeLeft/60000);
delay(500);
}
if(timeLeft < 30000 && timerActive){
Serial.println("LESS THAN A MINUTE LEFT");
finalCount = true;
GSMactive = false;
}
if(finalCount && timeLeft < 1000){
Serial.println("TIME UP!");
timerActive = false;
finalCount = false;
GSMactive = true;
switchOff();
sms.SendSMS(remoteNumber, "TIMER OUT. DEVICE DEACTIVATED!");
}
if(GSMactive){
if(gsm.readSMS(smsbuffer, 160, n, 20))
{
Serial.println(n);
Serial.println(smsbuffer);
for(int index = 0; smsbuffer[index] != '\0'; index++){
int thisChar = smsbuffer[index];
if(isDigit(thisChar)){
intString += (char)thisChar;
}
if(isAlpha(thisChar)){
charString += (char)thisChar;
}
if(isPunct(thisChar)){
charString += (char)thisChar;
}
}
for(int num = 0; n[num] != '\0'; num++){
remoteNumber[num] = n[num];
}
charString.toUpperCase();
minute = intString.toInt();
timeMillis = minute * 60000;
Serial.println("COMMAND GRABBED:");
Serial.println(charString);
Serial.println("NUMBER OF MINUTE(S):");
Serial.println(minute);
Serial.println("IN MILLISECONDS:");
Serial.println(timeMillis);
}
if(charString == "ON"){
Serial.println("TURNING DEVICE ON...");
if(minute <= 15 && minute > 0){
startRead = millis();
timerActive = true;
timeExact = timeMillis;
switchOn();
sms.SendSMS(remoteNumber, "DEVICE ACTIVATED!");
}
else Serial.println("ERROR!");
}
if(charString == "OFF"){
Serial.println("TURNING DEVICE OFF...");
if(timerActive){
timerActive = false;
switchOff();
sms.SendSMS(remoteNumber, "DEVICE DEACTIVATED!");
}
else Serial.println("ERROR!");
}
if(charString != "OFF" && charString != "ON"){
Serial.println("DO NOTHING.");
}
}
Serial.println("LOOP ENDED...");
}
/****************************************************************************************************/
void switchOn(){
myservo.attach(10);
for(int pos = 0; pos < 180; pos++){
myservo.write(pos);
delay(15);
}
myservo.detach();
return;
}
/****************************************************************************************************/
void switchOff(){
myservo.attach(10);
for(int pos = 180; pos >= 1; pos--){
myservo.write(pos);
delay(15);
}
myservo.detach();
return;
}
/****************************************************************************************************/
void pwrOn(){
digitalWrite(pwrON, LOW);
delay(1000);
digitalWrite(pwrON, HIGH);
delay(2000);
digitalWrite(pwrON, LOW);
delay(3000);
return;
}
/****************************************************************************************************/