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 Communication Hub. In order to run this 
// example, you need the following:
// 1. Install and configure the RTCU Communication Hub product
// 2. Insert a Cellular network enabled SIM card in the RTCU unit
// 3. Configure the TCP/IP and RCH settings in the RTCU, using the RTCU M2M Studio
// 4. Download this project into the RTCU unit
//
// 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 unit is now connected
// to the Cellular 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
   cnetworkOK  : BOOL; | Monitors connection to Cellular network (The internet) connection
   gwOK        : BOOL; | Monitors connection to the RCH
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 units 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 Cellular network support, and connect to the internet
DebugFmt(message:="netOpen=\1",v1:=netOpen(iface:=_NET_IFACE_CELLULAR));
 
// 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 unit)...
   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;
 
   cnetworkOK:=netConnected(iface:=_NET_IFACE_CELLULAR);
   gwOK:=gwConnected();
END;
 
END_PROGRAM;