Check connectivity status bewtween two Flexy

Hi,
I have set up two Ewons, EwonA and EwonB, that share a couple of tag through the M2Web API implemented in BASIC, I followed Simon’s guide here https://techforum.ewon.biz/thread-85.html. Now on EwonA I want to check every 30 seconds if EwonB is online, to do so I want to use the “getewon” command and then parse the response string sending the request with REQUESTHTTPX and getting the response string with RESPONSEHTTPX (first time using them). This is the section that i call

StatoConnessioneEwonB:
T2MAccount$ = “myAccount”
T2MUsername$ = “myUser”
T2MPassword$ = “myPass”
Target_eWON_Name$ = “EwonB”
method$=“GET”
//Getewon
url3$= “https://m2web.talk2m.com/t2mapi/
url3$= url3$+ “getewon?name=”+Target_eWON_Name$+"&t2musername="+T2MUsername$+"&t2mpassword="+T2MPassword$
REQUESTHTTPX url3$, method$, “”, “”
getewonResponse$=RESPONSEHTTPX “RESPONSE-BODY”
PRINT getewonResponse$
END

In the console all I get is ???, any idea why?

Hello @pegu,

My first though is this could be an issue with the response format or you are getting an error.

update you requesthttpx to use the following to write the response to a file. You can then get it from the usr directory via FTP. This should show you the fill response and possibly show you exactly what is going on.

REQUESTHTTPX url3$, method$, "", "","","/usr/data.txt"

Hi @deryck_hms,
I used your method to write the message on the data.txt file and I found out that I forgot about including the DevId and the T2MAccount in the url. Now that I have included them in the console it still writes ??? but in data.txt i can see the JSON string with the data I need.
Thanks

To get the infromation I want I tried searching for the “online” string inside the response message with the function onlineStatus% = INSTR 1, getEwonResponse$, "online" but I get 0, I tried to use the same function with other strings like { but I always get 0. It seems like I can’t read or work with the response string directly. I noticed that the data.txt start at line 2, could that be the problem? data.txt (212 Bytes)

Hello Pegu,

The response is most likely to long to be printed in the console. You can use the OPEN function to open the file in the usr directory. image

It might also make sense to check the status using a different process. This solution might vary depending on how you are exchanging data with m2web but you could setup a tag that automatically increments and make sure that tag is changing each time you exchange data.

Deryck

Hi, thanks for the response.
I thought about the OPEN function and it can be a useful workaround.
I just wanted to test the M2Web API functionality within BASIC but the simpler solution you proposed, the tag increasing, probably makes more sense.

Pegu

The heartbeat option is how i have implemented it in project i have done myself. This also doen’t rely on the talk2m status which might not be updated immediately.

Deryck

Below is a function that gets the minutes out of the current date/time and places it into a tag on the Flexy. You could call this function every X minutes and then send the tag value to the other Flexy as the heartbeat.

FUNCTION FlexyHeartbeat()
A$ = Time$ // get the current time
M% = VAL(A$(15 To 16)) // get the minutes out of the date time
Print M%
HEARTBEAT_FROM_FLEXY@ = M%
ENDFN

2 Likes