Gateway Timer Event Script not working

My Usecase:

I just need to check one API response code 200 for every one minute. If connection lost need to trigger a pop up view.

Things I tired:
1.Tired using the system.net.httpget() , if response is None , it will trigger a popup. But not working .
2. Tired to execute velow scripts , but if response cut throwing error, I know its a simple one, but not able to achieve , Kindly help me on this !

client = system.net.httpClient()
		response = client.get("http://192.168.43.75:5000/data")
		if response.statusCode == 200:
			system.perspective.openPopup("testing", "popup1")
		else:
			system.util.getLogger("FlaskCheck").info("Received response but status not OK")

Where is this script placed?
Scripts like this should be in gateway scheduled scripts, then use a message handler to message the failure out of the gateway scope into the perspective session, where the system.perspective.* script will actually work.

2 Likes

Thank you for your reply. I placed in simple button event to check whether it was working . Anyway I will try in scheduled one .

Hey David, As instructed I have been placed the code in Gateway scheduled event. But somehow it is not working again. please guide me

		
		client = system.net.httpClient()
		response = client.get("http://192.168.0.101:5000/data")
		if response.statusCode == 200:
		
# Sends a message to all Message Handlers configured on the current view, indicating that a new item has been added to a list.
			system.perspective.sendMessage("NewItem", scope = "session",sessionId="6a181fdd-5c61-49de-8b5b-a49679447839")
		else:
			system.util.getLogger("FlaskCheck").info("Received response but status not OK")

My message handler was placed in one view's root container, there just need to open the popup.

What errors are in the logs when it triggers?

1 Like

Unless that is there for show, you have hard-coded the sessionId in your call to send a message.

You are also using a system.perspective.sendMessage in a scheduled event when you should be using system.util.sendMessage. There is a difference, they are not interchangable. You also need a session message handler, to capture the message from util.sendMessage and then call perspective.sendMessage.

4 Likes

Thank you for your reply. Will check that too