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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | PROGRAM Edge1 VAR Init : BOOL := TRUE; TestScenario : USINT := 8; EoN : Sparkplug.FB_Edge; EoNConnectionState : Sparkplug.SparkplugSessionStateType; NumberOfDevices : UDINT; MyDevice1 : Sparkplug.FB_Device; Device1Healthy : BOOL := TRUE; MyDevice2 : Sparkplug.FB_Device; Device2Healthy : BOOL := TRUE; MyDevice3 : Sparkplug.FB_Device; Device3Healthy : BOOL := TRUE; MyDevice1State : Sparkplug.SparkplugSessionStateType; MyDevice2State : Sparkplug.SparkplugSessionStateType; MyDevice3State : Sparkplug.SparkplugSessionStateType; PlugIt : BOOL := TRUE; ItfEoN : Sparkplug.ISparkplugDeviceProtocol; ServerUrl : STRING; ServerPort : UINT; KeepAlive : UINT; CleanSession : BOOL := FALSE; Username : WSTRING := ""; Password : WSTRING := ""; UseTLS : BOOL := FALSE; publishPeriod : UINT := 500; // milliseconds interval so 1000 = 1s //Static initialization, as shown in the following code snippet; // //VAR // commonName : STRING := 'MyRasPi'; ciCertInfo : Sparkplug.MQTT.NBS.CERT_INFO := (psInfo := ADR( commonName ), udiSize := TO_UDINT( LEN( commonName ) )); sUseCaseName : STRING; ePurpose : Sparkplug.MQTT.NBS.PURPOSE; sHostname : Sparkplug.MQTT.NBS.HOSTNAME; udiVerificationMode : UDINT; ePurpose := ePurpose, udiVerificationMode := udiVerificationMode ); ItfTLSContext : Sparkplug.MQTT.NBS.ITLSContext; GenerateDataPeriod : TIME; GenerateDataElapsed : TIME; GenerateDataTimer : TON; Timestamp : Sparkplug.T_DateTime; Str : ChangingString; getClientCert : Sparkplug.GetClientCert; countClientCert : INT; StillGettingClientCertificate : BOOL; WaitForTheServerToRegisterCert : TON := (PT := T#1S); END_VAR 5106 {8e575c5b-1d37-49c6-941b-5c0ec7874787} ChildObjectGuids AddAttributeSubsequent IF Init THEN AddAllMetrics(); Scenario(); END_IF GenerateDataTimer( IN := NOT GenerateDataTimer.Q, PT := GenerateDataPeriod, ET => GenerateDataElapsed ); IF GenerateDataTimer.Q THEN GenerateEoNData(); GenerateDeviceData(); TON_DelayStartup( IN := TRUE ); PrimaryHostID := "Ignition-Sparky", //"Sparky", , // Please change this to your own PrimaryHostID! KeepAlive := KeepAlive, CleanSession := CleanSession, Username := Username, Password := Password, UseTLS := UseTLS, hCert := hCert, GroupId := GroupId, NodeName := NodeName, publishPeriod := publishPeriod, // ITLSContextProvider := ItfTLSContext, // We provide a reference to an instance of TLSContext IASyncPropertyProvider :=, SessionState => EoNConnectionState, NumberOfDevices => NumberOfDevices ); ELSIF StillGettingClientCertificate THEN //The below method creates a Client Certificate for you AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_org(); IF PlugIt THEN ItfEoN := EoN; ELSE ItfEoN := 0; MyDevice1( DeviceName := "SomeDevice001", DeviceHealthy := Device1Healthy, ItfEoNInstance := ItfEoN, PluggedIntoEoN =>, SessionState => MyDevice1State, publishPeriod := publishPeriod ); MyDevice2( DeviceName := "SomeDevice002", DeviceHealthy := Device2Healthy, SessionState => MyDevice2State, MyDevice3( DeviceName := "SomeDevice003", DeviceHealthy := Device3Healthy, SessionState => MyDevice3State, |