Push Agent as a subscriber
By default, Push Agent can send data to the cloud. Edit the Push Agent code to also receive data from the cloud.
Data reception function
The function in the following example is called each time a message is received. The function processes the received message according to the logic defined in the function and then updates the
messageVariable
variable value.private void SubscribeClientMqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { var messageVariable = Project.Current.GetVariable("Model/Message"); messageVariable.Value = "Message received: " + System.Text.Encoding.UTF8.GetString(e.Message); }
Subscriber configuration parameter
The following example shows the data reception function that is passed as a configuration parameter of the Subscriber. In addition to the base configuration of the Publisher, the subscriber method is configured in the
Start()
method.public void Start() { // PushAgent Default configuration // Add subscriber mqttClientConnector.AddSubscriber("my_custom_subscriber_topic", 1, SubscribeClientMqttMsgPublishReceived); }
Provide Feedback