《基于MQTT的OPC UA快速開發.pdf》由會員分享,可在線閱讀,更多相關《基于MQTT的OPC UA快速開發.pdf(14頁珍藏版)》請在三個皮匠報告上搜索。
1、OPC Day International 2024June 17th 21st,2024Randy ArmstrongChair of OPC UA Security Working Grouprandy.armstrongopcfoundation.orgOPC Day International 2024June 17th 21st,2024Client-Server=tightly coupled applications.Browsing address space to discover;Client specific subscriptions.Subscriptions cha
2、nge frequently.Need to call Methods.PubSub=loosely coupled applications.No need to browse;Many Clients can use same subscription;Subscriptions change rarely;Limited need for Methods.ClientServerPublisherSubscriberSubscriberSubscriberMQTTBrokerOPC Day International 2024June 17th 21st,20243PubSub may
3、be an add-on to a Server.A Publisher is a Client subscribing for data which is it re-publishes.A Client is used to configure the Publisher.Same data and information models can be published with PubSubClientServerPublisherSubscriberPubSubConfigurationSubscriberSaved In StorageIndustrial ProcessMQTTBr
4、okerOPC Day International 2024June 17th 21st,20244PubSub stands on its own!Publisher configuration can be fixed or managed with a non-OPC UA applicationPublisher sends fixed messages and metadata to MQTT broker.Subscribers discover where and what is Published by subscribing to well known topics.Subs
5、criberPubSubConfigurationSubscriberSaved In StorageIndustrial ProcessPublisherMQTT BrokerOPC Day International 2024June 17th 21st,20245MeasurementDescriptionUnitsConsumptionThe energy consumed by the device during the calculation period.kWhDutyCycleThe fraction of the calculation period where the de
6、vice is consuming power.%CalculationPeriodThe period,in ms,over which power calculations are computed.sOPC Day International 2024June 17th 21st,20246JSON widely understood.Default data format for the web GZIPed JSON smaller than most binary formatsOPC UA over MQTT uses JSON as the primary interchang
7、e format.MQTT 5.0 ContentType used to indicate JSON or Compressed Data If MQTT 3.1 is used the Subscriber should check for GZIP header and assume JSON if not present.CalculationPeriod:3600,Consumption:42.161,DutyCycle:0.305A complete OPC UA PubSub Message!OPC Day International 2024June 17th 21st,202
8、47Status Messages If IsCycle=FALSE then MQTT Will message is reported if Publisher goes offline.If IsCycle=TRUE the message has an expiry and the Publisher must re-send periodically.MessageId:“,MessageType:ua-status,PublisherId:(Quickstart001),Status:2,IsCyclic:falseopcua/json/status/(Quickstart001)
9、OPC Day International 2024June 17th 21st,202481.Decide what Data to Publish2.Create JSON Representation3.Connect to MQTT Broker4.Send Status5.Periodically Send Data6.Done!What is missing?No dynamic metadata Fixed metadata can be published Schema can be inferred from JSON No information on Engineerin
10、g Units.No discovery of Publishers Subscribers need to be configured with topics Wildcards using standard topic namesopcua/json/data/(Quickstart001)/Conveyor/MotorOPC Day International 2024June 17th 21st,20249Add a header to tell Subscribers which metadata to use.PublisherId uniquely identifies the
11、Publisher within the BrokerDataSetWriterId uniquely identifies the message definition within the PublisherMinorVersion indicates the version of the Metadata that the Message complies with.PublisherId:(Quickstart002),DataSetWriterId:101,MinorVersion:1718358698,WriterGroupName:Conveyor,DataSetWriterNa
12、me:Motor,SequenceNumber:23,Timestamp:2024-06-14T09:51:49.1904155Z,Payload:CalculationPeriod:3600,Consumption:42.70423076116228,DutyCycle:0.46250786856701065 :opcua/json/metadata/(Quickstart002)/Conveyor/MotorOPC Day International 2024June 17th 21st,202410PubSub messages are Name/Value pairs called“F
13、ields”Fields have DataTypes which may be Structures.Structured DataTypes are completely define in the MetaData.Fields have additional Properties which provide context.i.e.EngineeringUnits.Metadata may be shared Important optimization for some systems.Simple devices can have a fixed file.VersionDescr
14、iptionFields 0 Name:Consumption DataType:Double Properties EURange:0,1000 EngineeringUnits:“kWh”1 Name:DutyCycle DataType:Double Properties EURange:0,100 EngineeringUnits:“%”2 Name:CalculationPeriod DataType:Double Properties EngineeringUnits:“s”Data+Status+Metadata=MVPOPC Day International 2024June
15、 17th 21st,202411Connection Messages report all messages provided by a PublisherInclude details such as what DataSets are published and how they can be GroupedAllow Publishers to use non-standard topic names for Data and MetaData Key feature needed to support UNSOther information control the frequen
16、cy of publication and the exact details on what appears in the NetworkMessagesWriterGroups 0 Name:Conveyor DataTopic:PublishingInterval:1000 KeepAliveInterval:30000 QualityOfService:AtLeastOnce DataSetWriters 0 Name:Motor DataSetWriterId:101 DataSetName:EnergyMetrics MetaDataTopic:KeyFrameCount:1 op
17、cua/json/connection/(Quickstart003)OPC Day International 2024June 17th 21st,202412WriterGroup Defines the NetworkMessage Allows bundling of DataSetMessages Name is unique with the PublisherDataSetWriters Defines the DataSetMessage Each DataSetMessage has a layout described by the MetaData.DataSetWri
18、terId unique within a Connection.Name is unique within the Group/WriterGroupDataSetMessage1Field1:Value1Field2:Value2DataSetMessage1Field3:Value3Field4:Value4DataSetMessage2NetworkMessage1nDataSetWriterDataSetWriterDataSetMetaDataDataSetMetaDataopcua/json/OPC Day International 2024June 17th 21st,202413Simple Quickstarts in GitHubC#code that implements OPC UA with special OPC UA libraries in 50-100 lines of code.Great way to get started with OPC UA.OPC Day International 2024June 17th 21st,202414Randy Armstrongrandy.armstrongopcfoundation.org