1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | (* Primary Host Node ServerUrl : STRING; // eg:'test.mosquitto.org'; ServerPort : UINT := 1883; // eg: 1883 PrimaryHostID : WSTRING := ""; // eg:'PrimaryHost'; // * The client must get all messages from a certain topic, even if it is offline. // * You want the broker to store the subscription information of the client and restore the interrupted communication quickly. // * The client needs only to publish messages to topics, the client does not need to subscribe to topics. // * The client does not need to get messages that it misses offline. // CleanSession : BOOL := FALSE; Password : WSTRING := ""; // specify the password for the username (optional) ; // Handle to the client certificate (optional) and only used if UseTLS is TRUE ITLSContextProvider : MQTT.NBS.ITLSContext //Static initialization, as shown in the following code snippet; //VAR // commonName : STRING := 'MyRasPi'; IASyncPropertyProvider : MQTT.NBS.IAsyncProperty; // Runs the connect process in a own background task. Use this property if the connection setup takes longer than one task cycle (e.g. TLS connections) END_VAR VAR_OUTPUT Connected : BOOL; SessionState : SparkplugSessionStateType; xError : BOOL; eError : ERROR; itfPrimaryHost : IPrimaryHost := THIS^; VAR _groupIDFactory : GroupIDFactory; _groupIDs : List; // OF FB_GroupID - This is groupIDs with names _cPrimaryHostID : WSTRING; // Corrected PrimaryHostID, contains no illegal chars _Enabled : BOOL; _ConnectionTime : TIME := T#30S; _OutTimeRemaining : TIME; // Duration of Out Time Period = TRUE remaining _LockTimeRemaining : TIME; _SparkplugB : FB_SparkplugBSimple; // Handles SparkPlugB Stuff _BlobSize : UDINT; // current encoded message size _LastWillQos : MQTT.MQTT_QOS := MQTT.MQTT_QOS.QoS0; _LastWillRetain : BOOL := FALSE; _NDEATH : FB_Metric := (_dataType := MetricDataType.UInt64); // contains the current NDEATH BDSeq _IMessageSource_publishing : BOOL; _IMessageSource_published : BOOL; // TRUE when publish is complete. Is set false automatically in claimExclusivePublishingRights, but you can set it false yourself if you want //Publihser _xCMDSize : DINT; _xCMDEncxErr : BOOL; {attribute 'instance-path'} _POU : STRING; 2477 {8e575c5b-1d37-49c6-941b-5c0ec7874787} ChildObjectGuids AddAttributeSubsequent // Components _MQTT.IASyncPropertyProvider( IASyncPropertyProvider ); _MQTT.ITLSContextProvider( ITLSContextProvider ); _MQTT(); _MessageConsumer( pPrimaryHost := THIS, // Alternatively ADR( THIS^ ) pMQTT := ADR(_MQTT), xError => , eError => ); END_IF _ExponentialBackOff( Enable := (Connect AND NOT Connected), ConnectionTime := _ConnectionTime, LockTimesArray := _LockTimesArray, Enabled => _Enabled, OutTimeRemaining => _OutTimeRemaining, LockTimeRemaining => _LockTimeRemaining ); _StateMachine( Connect := _ExponentialBackOff.out, PrimaryHostConnected := Connected, pMQTT := ADR( _MQTT ), pSparkplugB := ADR( _SparkplugB ), pPrimaryHost := THIS, SessionState => SessionState ); Diag(); |