//internet connection checker
//this example checks out a certain internet server, every 15 minutes
 
//SERVER down:
//---------------
//1. log this in a logfile
//2. set error light -> IO13
//3. check now every minute
 
//if the server goes down, this will be logged
Timestep OFF
 CONNECT TCP,127.0.0.1,80
 
 
LABEL LOOP
     IF IO13 = 1 Then
          //error state
          WAIT 30000
          WAIT 30000
     ELSE
          //no error state
          //wait 15 minutes for new check
          CALL WAIT_15_MINUTES
     END IF
 
      //replace this server by your own server to test (this is a local webserver)
      CONNECT TCP,127.0.0.1,80
GOTO LOOP
 
 
SUB EVENT_CONNECTION_ESTABLISHED
     //connection succeeded, ClearIO 13
     IF IO13 = 1 Then
          LOGFILE = "C:\internetcheck.log"
          WRITELOG "<$xTIME> server is back online. clearing IO13"
          CLEARIO 13
     END IF
     DISCONNECT
END SUB
 
 
SUB EVENT_CONNECTION_ERROR
     //connection failed, SetIO 13
     LOGFILE = "C:\internetcheck.log"
     WRITELOG "<$xTIME> server was found down, setting IO13"
     SETIO 13
END SUB
 
 
SUB WAIT_15_MINUTES
     //Set minute counter to 0
     VAR1 = 0
     LABEL WAIT
          //wait 30 seconds, repeat 30 times
          WAIT 30000
          VAR1 = VAR1 + 1
     IF VAR1 < 0030 Then GOTO WAIT
END SUB

BACK TO SAMPLE OVERVIEW