Hello, I've posted here before and found the advice here very helpful. I'm new to Ignition and to coding and may need to seek clarification to understand any suggestions to this post.
I'm writing to try to pinpoint and understand why the steps below fail to execute a series of actions. My intention is for a Gateway Timer Script to constantly run and when certain conditions are met, call a Message Handler that will click a button.
Message Handler:
I've created a Message Handler on a button called "click_button_to_send_email" and written the following script (image also attached):
def onMessageReceived(self, payload):
# Simulate a button click on the same component
self.props.onClick()
Button Event Script:
On that button is also a Component Event>onActionPerformed* script that, when clicked, successfully executes and sends an email--this part works.
Gateway Timer Script:
I then created a Gateway Timer Script configured to run at 60,000ms delay at a fixed rate with the following script (image also attached):
from datetime import datetime
import system
def checkReportSettings_callMessageHandler():
# Get the current day and time
now = datetime.now()
current_day = now.strftime("%A") # Get the current day of the week
current_time = now.strftime("%m/%d/%y, %I:%M:%S %p") # Get the current time in the specified format
print("Current day:", current_day)
print("Current time:", current_time)
# Get the custom properties from the view
view = system.perspective.getView("ProjectName/ViewName")
selected_day = view.custom.selected_day
selected_time = view.custom.selected_time.strftime("%m/%d/%y, %I:%M:%S %p") # Format the selected time
print("Selected day:", selected_day)
print("Selected time:", selected_time)
# Compare the current day and time with the custom properties
if current_day == selected_day and current_time == selected_time:
print("Match found! Executing message handler.")
# Execute the message handler to click the button
system.perspective.sendMessage("click_button_to_send_email")
else:
print("No match found.")
# Call the function
checkReportSettings_callMessageHandler()
Is my script on the Message Handler incorrect? Am I missing a step?