Examples - VSMS using the RCH (simple)

Top  Previous  Next

//-----------------------------------------------------------------------------
// testvsms.vpl, created 2003-04-28 09:44
//
// Test of VSMS messages sent over the RTCU Gateway. In order to run this
// example, you need the following:
// 1. Install and configure the RTCU Gateway product
// 2. Insert a GPRS enabled SIM card in the RTCU device
// 3. Configure the TCP/IP and Gateway settings in the RTCU, using the RTCU IDE program
// 4. Download this project into the RTCU device
//
// When running correctly the LED1 will turn on after a few seconds, and then LED2
// should turn on after approx 30..50 seconds signalling that the device is now connected
// to the GPRS network (connected to the internet)
// The program will then send a VSMS message every 60 seconds to it self.
//-----------------------------------------------------------------------------
INCLUDE rtcu.inc
 
//  Output variables that can be configured via the configuration dialog (These are global)
VAR_OUTPUT
  gwOK   : BOOL; | Monitors connection to the RTCU Gateway
  gprsOK : BOOL; | Monitors connection to GPRS (The internet) connection
END_VAR;
 
PROGRAM testvsms;
VAR
  rc       : INT;
  sms       : gsmIncomingSMS; // Receives incoming VSMS messages
  ns       : DINT;   // Holds linsec time for next transmission
  sMyNodeID : STRING; // Contains this devices serialnumber (node ID) in the
                      // format of "@nnnn" where nnnn is the serialnumber
END_VAR;
 
// The next code will only be executed once after the program starts
gsmPower(power:=TRUE);
 
// Activate the GPRS support, and connect to the internet
DebugFmt(message:="gprsOpen=\1",v1:=gprsOpen());
 
// First VSMS will be sent in 60 seconds
ns:=clockNow()+60;
 
// Construct our own nodeid in the form of "@nnnn"
sMyNodeID:=strConcat(str1:="@", str2:=dintToStr(v:=boardSerialNumber()));
DebugMsg(message:=sMyNodeID);
 
// Code from this point until END will be executed repeatedly
BEGIN
  // Update function block
  sms();
 
// If it's time to send another VSMS message (this message is destined for this device)...
  if clockNow()>ns THEN
    DebugFmt(message:="gsmSendSMS()=\1", v1:=gsmSendSMS(phonenumber:=sMyNodeID, message:="Hello world"));
     ns:=clockNow()+60; // Next transmit is in 60 seconds
  END_IF;
 
  // If any incoming VSMS messages, just show them
  if sms.status>0 THEN
    DebugMsg(message:="SMS received");
    DebugMsg(message:=sms.phonenumber); // In the case of VSMS messages, this will be "@nnnn"
                                         // where nnnn is the nodenumber of the sending node
    DebugMsg(message:=sms.message);
  END_IF;
 
  gprsOK:=gprsConnected();
  gwOK:=gwConnected();
END;
 
END_PROGRAM;