FlexSCADA Adds MQTT Support to V91 Firmware

FlexSCADA is pleased to announce support for the MQTT protocol across it’s Flexs Q5 product line.

Customers can now subscribe to topics and publish from the highly flexible and easy to use onboard logic.

Below we’ve shared an example logic script demonstrating how to use the MQTT functionality, documentation will be updated shortly for each of the additional functions

 

// MQTT Publish and Subscribe Example, Requires Firmware V91 or greater


// Callback function which runs whenever a subscribed topic is received
// The 'event' object contains the topic info, the message can be binary
// data or a json string, json strings should be parsed, let data = json.parse(event.message);
// binary data can be converted into numerical arrays with the binToArray function
// let array = binToArray(event.message,"U32"); // array = [2421,3424] 

function mqttSubscriberCallback(event) {
    print("MQTT EVENT: ", string(event));
    // MQTT EVENT:  {"retain":false,"qos":0,"message":"Hello World","topic":"power_system/relays/1"} 
}



while (run()) {


    // Connecting before each publish ensures that if the connection is ever disconnected it will reconnect,
    // If the client is connected it will just return code 207 (Already Connected)
    // return: Any response other than 0 indicates an error and the corresponding error code

    let ret = mqtt.connect({
        url: "mqtt://172.16.220.22:1883",
        client: "Nikiah Repeater",
        subscribe: ["power_system/relays/+"],
        callback: mqttSubscriberCallback
    });
    print("connect:", ret);


    let batteryVoltage = string(inputs(1).avg);

    // Publish an event to the MQTT broker, the message data can be binary or text, if you are pushing an object it should
    // be converted to a string first, let msg = string( { object: "value" } );  binary messages can also
    // be sent using the arrayToBin function, let msg = arrayToBin([14.3,12.3,43.23],"F32");

    ret = mqtt.publish("power_system/battery_voltage", batteryVoltage);
    print("publish:", ret);
    waitMS(5000);
}



mqtt.disconnect(); // Make sure the client is disconnected before exiting


 

 

Select your currency