TrevorBlevins
Member
Hello,
I have a codesys controller which I am looking to communicate with an external. User interface via mqtt.
I subscribe to a topic and recieve a JSON Payload. It contains the variable to be updated as well as the value.
Example
My applications may have 10, or 100, or maybe 1000 variables that need to be updatable from the UI.
Is there a way to use the key (which is a string) as a reference to the variable that is to be updated so i can keep to code concise and not have to explicitly reference all variables.
Currently my only method of updating the value would be using a case select statement checking if the string value matches the tag. however this would need to be done for each tag.
This is the equivalent code I am using in python for an alien Bradley controller
Any thoughts would be appreciated
I have a codesys controller which I am looking to communicate with an external. User interface via mqtt.
I subscribe to a topic and recieve a JSON Payload. It contains the variable to be updated as well as the value.
Example
Code:
{"tag":"hmiStopReq","value":1}
My applications may have 10, or 100, or maybe 1000 variables that need to be updatable from the UI.
Is there a way to use the key (which is a string) as a reference to the variable that is to be updated so i can keep to code concise and not have to explicitly reference all variables.
Currently my only method of updating the value would be using a case select statement checking if the string value matches the tag. however this would need to be done for each tag.
This is the equivalent code I am using in python for an alien Bradley controller
Code:
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
payload = json.loads(msg.payload)
comm.Write(payload['tag'], payload['value'])
Any thoughts would be appreciated