Receive SMS message

Top  Previous  Next

//----------------------------------------------------------------------------
// Receive SMS.vpl, created 2000-08-06 11:14
//
// This program allows control of 8 outputs by sending a SMS-message
// to the RTCU unit. "ON" followed by a number in the interval 1..8 activates 
// the specified output. 
// "OFF" followed by a number in the interval 1..8 deactivates the specified
// output.
//----------------------------------------------------------------------------
INCLUDE rtcu.inc
 
VAR_OUTPUT
   outputs      : ARRAY[1..8] OF BOOL; | All 8 outputs
   connected    : BOOL;                | Connected to a Cellular basestation.
END_VAR;
 
VAR
   sms     : gsmIncomingSMS; // Receives incoming SMS messages
   extract : strGetValues;   // Matching of strings
END_VAR;
 
PROGRAM ReceiveSMS;
 
// The next code will only be executed once after the program starts
gsmPower(power:=ON);
 
BEGIN
   sms();
   connected := gsmConnected();
   IF sms.status > 0 THEN
     // Message received
     // Check if it is a "ON" message
     // !#"ON Test" SMS ON 1
     extract(format:="ON \1", str:=sms.message);
     IF extract.match AND extract.v1 >= 1 AND extract.v1 <= 8 THEN
       outputs[extract.v1] := ON;
     END_IF;
     
     // Check if it is a "OFF" message
     // !#"OFF Test" SMS OFF 1
     extract(format:="OFF \1", str:=sms.message);
     IF extract.match AND extract.v1 >= 1 AND extract.v1 <= 8 THEN
       outputs[extract.v1] := OFF;
     END_IF;
     DebugMsg(message:=strConcat(str1:="Message received from ", str2:=sms.phonenumber));
     DebugMsg(message:=strConcat(str1:="Message is ", str2:=sms.message));
   END_IF;
END;
 
END_PROGRAM;