Can't get ping to work on Flexy?

I’m having trouble getting this script to work:
https://developer.ewon.biz/content/perform-ping-function-basic

@tomgiorgio

Can you please post the script you are using and describe the issue you are running into?

Sorry, I hit enter to make a new line and it submitted my post instead.

The console says

Operation failed (28) 8 : OPEN “tcp:10.0.0.22:80,10” FOR BINARY OUTPUT AS 1

10.0.0.22 is the IP address of my laptop. I’m going through a basic layer 2 switch.

I copy and pasted the script from the link and changed the IP to 10.0.0.22

I’m running it in the cyclic section.

My script:

rem — eWON start section: Cyclic Section
eWON_cyclic_section:
rem — eWON user (start)
Ping:
PRINT "ping ";Time$
CLOSE 1
ONSTATUS “goto ProcessStatus”
OPEN “tcp:10.0.0.22:80,10” FOR BINARY OUTPUT AS 1
a% = GETSYS PRG,“ACTIONID”
END

ProcessStatus:
PRINT "process ";Time$
b% = GETSYS PRG,“EVTINFO”
IF b%=a% THEN
SETSYS PRG,“ACTIONID”,a%
c% = GETSYS PRG,“ACTIONSTAT”
IF c%=0 THEN
PRINT “PING 10.0.0.22:80 success”
ELSE
PRINT “PING 10.0.0.22:80 failed”
ENDIF
CLOSE 1
ENDIF
END

@tomgiorgio

Is your PC in the same subnet as the eWON’s LAN IP and does your PC have its’ default gateway set as the eWON’s LAN IP?

You will not want to use the cyclic section for most scripting applications including this one.
This will run the script every time the processor cycles which is much too fast for opening a socket and can cause crashes in your device. Instead you will need to use a timer and do it periodically.

Example:

Init section
TSET 1,20 // every 20 seconds
ONTIMER 1, “goto Ping”

Ping:
PRINT "ping ";Time$
CLOSE 1
ONSTATUS “goto ProcessStatus”
OPEN “tcp:10.0.0.22:80” FOR BINARY OUTPUT AS 1
a% = GETSYS PRG,“ACTIONID”
END


ProcessStatus:
PRINT "process ";Time$
b% = GETSYS PRG,“EVTINFO”
IF b%=a% THEN
SETSYS PRG,“ACTIONID”,a%
c% = GETSYS PRG,“ACTIONSTAT”
IF c%=0 THEN
PRINT “PING 10.0.0.22:80 success”
ELSE
PRINT “PING 10.0.0.22:80 failed”
ENDIF
CLOSE 1
ENDIF
END

This is just for testing comms so I don’t mind running in the cylic section, the script won’t be used in production.

My laptop is on the same subnet (it’s the 10.0.0.22, and it’s a class C subnet) but I don’t have the eWON as my default gateway. That’s probably the issue.

I’m trying to set it up so I can send the customer an example script and let them ping their PLC from their Flexy. But does this mean they’ll have to set their PLCs default gateway to the IP of the Flexy?

@tomgiorgio

I cannot guarantee this will work if you use the cyclic section even in a non-production environment.

Yes, I’d set their default gateway to the eWON’s LAN IP so that the traffic has an explicit route.

edit -

Tom, after further investigation this may not work on your PC by default unless you allow port 80 traffic or specify a port in the script that is allowed on your PC. Just wanted to let you know as it still may not be working with your PC due to its firewall.