Communication Control

The configuration and the use of the WAN interfaces are fully configurable through Basic script or Java ETK.
For detailed info see: KB-0035-00: How to manage eWON communication using scripting.

A common example of controlling WAN communication through scripting is changing which WAN interface is active on the Ewon gateway.

As the Ewon gateway can have multiple WAN interfaces, but only a single active one at a time, scripting can also be used to switch between interfaces.

If you have an Ewon gateway that typically uses the local Ethernet network (LAN of the remote site) for its Internet access and the Ewon gateway 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 gateway is using the factory LAN.
If the VPN connection is lost, the Ewon gateway 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

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

For your information, there is a built-in feature that covers this mechanism, check the WAN Fallback feature.
However, if you require better flexibility, you can also use BASIC or JAVA to script you own WAN fallback mechanism.

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 script example enabling/disabling the WAN interface:

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");
}