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 | // Components _MQTT.IASyncPropertyProvider( IASyncPropertyProvider ); _MQTT.ITLSContextProvider( ITLSContextProvider ); _MQTT(); _RecvMesg REF= _MQTT.GetSubscriberMessage(MetricList := THIS^._AllMetricsList, MessageTopic => _RecvTopic ); //onSubscribeMessage( pTopic := ADR( _RecvTopic ), // pMessage := _RecvMesg ); SparkplugMessageTypes.NBIRTH: //Birth certificate for MQTT EoN nodes. EdgeId := _TopicParser.EdgeId, _MyGroupId REF= THIS^.allocGroupId( GroupId := _TopicParser.GroupId, _MyEdge REF= THIS^.allocEdgetoGroupId( EdgeId := _TopicParser.EdgeId, eError => eError ); IF eError = ERROR.NO_ERROR THEN pMessage := _RecvMesg, eError => eError ); ELSE xError := TRUE; //eError := eError; END_IF ELSE xError := TRUE; //eError := eError; END_IF ERROR.EdgeIDNotFound: // ==> NEW EDGE! eError => eError ); ERROR.NO_ERROR: // ==> UPDATE EXISTING EDGE pMessage := _RecvMesg, xError => xError, eError => eError ); ELSE ; //{info 'TODO: maybe some sort of error??'} END_CASE SparkplugMessageTypes.NDATA: //Node data message. _MyEdge.ProcessNDATA( itfPrimaryHost := THIS^, xError := TRUE; eError := Error.MetricNotFound; 'PrimaryHost process NDATA metric error: %s', TO_STRING( _HandledError ) ); END_CASE SparkplugMessageTypes.DBIRTH: //Birth certificate forDevices. EdgeId := _TopicParser.EdgeId, eError => _HandledError ); ERROR.EdgeIDNotFound: // ==> NEW EDGE! must rebirth the edge ERROR.DeviceIDNotFound: // ==> NEW DEVICE! SparkplugMessageTypes.DDEATH, //Death certificate for Devices. SparkplugMessageTypes.NCMD, //Node command message. SparkplugMessageTypes.STATE: //Critical application state message Allows you to concenrate Edge of Network Data sent by various Edges or other Sparkplug compatible nodes *) {attribute 'reflection'} FUNCTION_BLOCK FB_PrimaryHost IMPLEMENTS IPrimaryHost VAR_INPUT // Persistent Session (FALSE = DEFAULT) // * The client must get all messages from a certain topic, even if it is offline. // * You want the broker to queue the messages for the client and deliver them as soon as the client is back online. // // hCert : SysTypes.RTS_IEC_HANDLE ; // Handle to the client certificate (optional) and only used if UseTLS is TRUE //VAR // myTLSContext : NBS.TLSContext := ( // sUseCaseName:='NBSTest', // ciCertInfo:=ciCertInfo, // ); END_VAR Connected : BOOL; xError : BOOL; itfPrimaryHost : IPrimaryHost := THIS^; |