Communication Control

The configuration and use of the WAN interface is fully configurable by Basic Scripting or Java ETK.
For detailed info see: KB-0035-0-EN-(How to manage eWON communication using scripting).pdf 

A common example of controlling the WAN communication through scripting is enabling and disabling the WAN port based on the state of a tag.
In the example below, the boolean tag Switch enables the WAN port when it is high and disables it otherwise.

Basic script example enabling/disabling the WAN interface:

Rem --- eWON user (start)
DoSwitch:
IF (Switch@<>0) THEN
	REM Open Internet connection
	SETSYS COM,"load"
	REM --- WANCnx = 2 for Ethernet
	SETSYS COM,"WANCnx","2"
	SETSYS COM,”WANPermCnx”,”1”
	SETSYS COM,"save"
	PRINT Time$;" Connection opened"
ELSE
	REM Close Internet connection
	SETSYS COM,"load"
	REM – WANCnx = 0 for disabled
	SETSYS COM,"WANCnx","0"
	SETSYS COM,"save"
	PRINT Time$;" Connection closed"
ENDIF
END

Java example:

SysControlBlock SCB = new SysControlBlock(SysControlBlock.COM);
if (IOManager.readTag("Switch") == 1)
{
	SCB.setItem("WANCnx", "2");
    SCB.setItem("WANPermCnx", "1");
    SCB.saveBlock();
    System.out.println("Connection opened");
}
else
{
    SCB.setItem("WANCnx", "0");
    SCB.saveBlock();          
    System.out.println("Connection closed");
}

As an eWON can have multiple WAN interfaces, but only one active at any time, scripting can also be used for switching between interfaces.

If you have an eWON that typically uses the local LAN for its Internet access and the eWON must always have a VPN connection, then you might want it to automatically switch over to a cellular connection if the LAN network fails.

In the example below, the VPN connection is tested every 15 minutes while the eWON is using the factory LAN.
If the VPN connection is lost, the eWON switches over to the modem. After two hours, it checks to see if the LAN is available again and switches back if it is.

Rem --- eWON start section: Init Section
ewon_init_section:
Rem --- eWON user (start)
ONTIMER 1,"goto TestVPN"
TSET 1,900
REM --- WAN_ON is a MEM tag used to store the state of the Ethernet connection
WAN_ON@=1
ONTIMER 2,"goto ReturnToWAN"
TSET 2,0
Rem --- eWON user (end)
End
Rem --- eWON end section: Init Section

Rem --- eWON start section: Fallback
Rem --- eWON user (start)
TestVPN:
	SETSYS INF,"load"
	A$ = GETSYS INF,"VPNIP"
	PRINT Time$;" ";A$
	IF (A$="0.0.0.0") THEN
		REM WAN is broken, activate Fallback
		WAN_ON@=0
		TSET 1,0
		TSET 2,7200
		SETSYS COM,"load"
		SETSYS COM,"WanCnx",1
		SETSYS COM,"save"
		PRINT Time$;" Fallback activated"
		LOGEVENT "Fallback activated"
	ELSE
		WAN_ON@=1
	ENDIF
END

ReturnToWAN:
	TSET 2,0
	SETSYS COM,"load"
	SETSYS COM,"WanCnx",2 
	SETSYS COM,"save"
	PRINT Time$;"Fallback deactivated"
	LOGEVENT "Fallback deactivated"
	TSET 1,900
END
Rem --- eWON user (end)
End
Rem --- eWON end section: Fallback