|
| 1 | +# go_eebus |
| 2 | +<img src="https://github.com/LMF-DHBW/go_eebus/blob/master/assets/eebus_logo.png" width="150"> |
| 3 | +This repository includes a framework of the EEBUS protocol in the Go programming language. |
| 4 | +The EEBUS protocol suite provides high-quality protocols, which allow efficient communication of smart home IoT devices, independent of device brand, type and other factors. |
| 5 | +It provides an open-source, future-proof solution that can be applied in many environments and for numerous applications. |
| 6 | + |
| 7 | +## About |
| 8 | +This framework is part of a student research project at DHBW Stuttgart and provides a partial implementation of the EEBUS protocols SHIP and SPINE. |
| 9 | + |
| 10 | +The documentation of the student research project can be found here: |
| 11 | + |
| 12 | +[GoEEBUS.pdf](https://github.com/LMF-DHBW/go_eebus/blob/main/assets/GoEEBUS.pdf) |
| 13 | + |
| 14 | +The other part of the research project was the implementation of device specific code. |
| 15 | +The GitHub repository can be found here: |
| 16 | + |
| 17 | +[https://github.com/LMF-DHBW/go_eebus_devices](https://github.com/LMF-DHBW/go_eebus_devices) |
| 18 | + |
| 19 | +## Explanation and examples |
| 20 | + |
| 21 | +The following code shows how the framework can be used in general: |
| 22 | + |
| 23 | +````go |
| 24 | +// Importing the framework |
| 25 | +import eebus "github.com/LMF-DHBW/go-eebus" |
| 26 | + |
| 27 | +// Configure EEBUS node |
| 28 | +eebusNode = eebus.NewEebusNode("100.90.1.102", true, "gateway", "0001", "DHBW", "Gateway") |
| 29 | + |
| 30 | +// IP-Adr, is gateway, ssl cert name, device ID, brand name, device type |
| 31 | +eebusNode.Update = update // set method called on subscription updates |
| 32 | + |
| 33 | +// Function that creates device structure |
| 34 | +buildDeviceModel(eebusNode) |
| 35 | + |
| 36 | +// Start node |
| 37 | +eebusNode.Start() |
| 38 | +```` |
| 39 | + |
| 40 | +The following code shows how the device structure for an EEBUS node can be created, in this example an ActuatorSwitch device is created: |
| 41 | + |
| 42 | +````go |
| 43 | +eebusNode.DeviceStructure.DeviceType = "Generic" |
| 44 | +eebusNode.DeviceStructure.DeviceAddress = "Switch1" |
| 45 | +eebusNode.DeviceStructure.Entities = []*resources.EntityModel{ |
| 46 | + { |
| 47 | + EntityType: "Switch", |
| 48 | + EntityAddress: 0, |
| 49 | + Features: []*resources.FeatureModel{ |
| 50 | + // Entitiy 0, Feature 0 always has to be node management |
| 51 | + eebusNode.DeviceStructure.CreateNodeManagement(false), |
| 52 | + { |
| 53 | + FeatureType: "ActuatorSwitch", |
| 54 | + FeatureAddress: 1, |
| 55 | + Role: "client", |
| 56 | + Functions: resources.ActuatorSwitch("button", "button for leds"), |
| 57 | + BindingTo: []string{"ActuatorSwitch"}, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | +} |
| 62 | + |
| 63 | +// Create node management again, in order to update discovery data |
| 64 | +eebusNode.DeviceStructure.Entities[0].Features[0] = eebusNode.DeviceStructure.CreateNodeManagement(false) |
| 65 | +```` |
| 66 | + |
| 67 | +The gateway device has a list of requests, the following code shows how requests can be accepted from the gateway: |
| 68 | + |
| 69 | +````go |
| 70 | +// Requests are saved in the following list: |
| 71 | +eebusNode.SpineNode.ShipNode.Requests |
| 72 | + |
| 73 | +i := 0 // Select the first entry as an example |
| 74 | + |
| 75 | +// Accept request by connecting with the device |
| 76 | +req := eebusNode.SpineNode.ShipNode.Requests[i] |
| 77 | +go eebusNode.SpineNode.ShipNode.Connect(req.Path, req.Ski) |
| 78 | + |
| 79 | +// Remove request from list |
| 80 | +eebusNode.SpineNode.ShipNode.Requests = append(eebusNode.SpineNode.ShipNode.Requests[:i], eebusNode.SpineNode.ShipNode.Requests[i+1:]...) |
| 81 | +```` |
| 82 | + |
| 83 | +How subscription messages can be read: |
| 84 | + |
| 85 | +````go |
| 86 | +func update(data resources.DatagramType, conn spine.SpineConnection) { |
| 87 | + entitySource := data.Header.AddressSource.Entity |
| 88 | + featureSource := data.Header.AddressSource.Feature |
| 89 | + if conn.DiscoveryInformation.FeatureInformation[featureSource].Description.FeatureType == "Measurement" { |
| 90 | + var Function *resources.MeasurementDataType |
| 91 | + err := xml.Unmarshal([]byte(data.Payload.Cmd.Function), &Function) |
| 92 | + // Function.Value contains measured value |
| 93 | + } |
| 94 | +} |
| 95 | +```` |
| 96 | + |
| 97 | +How the states of features can be read: |
| 98 | + |
| 99 | +````go |
| 100 | +for _, e := range eebusNode.SpineNode.Connections { |
| 101 | + for _, feature := range e.SubscriptionData { |
| 102 | + if feature.FeatureType == "ActuatorSwitch" && feature.EntityType == "LED" { |
| 103 | + var state *resources.FunctionElement |
| 104 | + err := xml.Unmarshal([]byte(feature.CurrentState), &state) |
| 105 | + // state.Function contains the state (on/off) |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | +```` |
| 110 | + |
| 111 | +How subscription messages can be send: |
| 112 | + |
| 113 | +````go |
| 114 | +for _, e := range eebusNode.SpineNode.Subscriptions { |
| 115 | + e.Send("notify", resources.MakePayload("actuatorSwitchData", |
| 116 | + resources.FunctionElement{ |
| 117 | + Function: "on", |
| 118 | + })) |
| 119 | +} |
| 120 | +```` |
| 121 | + |
| 122 | +How binding messages can be send: |
| 123 | + |
| 124 | +````go |
| 125 | +for _, e := range eebusNode.SpineNode.Bindings { |
| 126 | + e.Send("write", resources.MakePayload("actuatorSwitchData", |
| 127 | + resources.FunctionElement{ |
| 128 | + Function: "toggle", |
| 129 | + })) |
| 130 | +} |
| 131 | +```` |
| 132 | + |
| 133 | +## UML diagrams |
| 134 | + |
| 135 | +The framework is devided into the SHIP protocol, the SPINE protocol and defined EEBUS resources. |
| 136 | + |
| 137 | +The following images show the UML diagrams for the framework: |
| 138 | + |
| 139 | +<img src="https://github.com/LMF-DHBW/go-eebus/blob/main/assets/ship_uml.png" width="600"> |
| 140 | + |
| 141 | +<img src="https://github.com/LMF-DHBW/go-eebus/blob/main/assets/spine_uml.png" width="600"> |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
0 commit comments