• Ingen resultater fundet

Case Studies

9.2 Case study : BeagleBone Communication

9.2.2 BeagleBone

The BeagleBone consists of two boards:

Top Board

On the top board two light bulbs are located, along with two buttons.

Bottom Board

On the button board, three small light bulbs are located.

This can be seen in figure 9.2, where the actual BeagleBone is shown.

1BeagleBone:http://beagleboard.org/bone

108 CHAPTER 9. CASE STUDIES

Figure 9.2:BeagleBone

9.2.2.1 BeagleBone Client

To establish the communication from the BeagleBone to the cloud, four Python modules have been created:

Main.py

This is the main executable of the Python application. It setup the environment using the remaining python modules.

HardwareIO.py Handles the light state of each of the light bulbs on the board. It does so through direct communication with the system path, for example:

open("/sys/devices/platform/leds-gpio/leds/beaglebone::usr1/brightness", ’w’).write("1") would turn on the light and one of the LED’s on the bottom board. The modules also starts a thread running thepollButtonsfunction in ButtonsAndLights.py.

WebsocketClient.py

Establishes the connection to the cloud through an imported WebSocket library. It opens a WebSocket and runs in a continuous loop, posting data to the cloud. To connect the BeagleBone to the Cloud Service, only a little Python code is needed. Using PyPI WebSocket client2a connection is established, by entering the following code:

1 ws = websocket.WebSocketApp(ws://cloudsolution39.cloudapp.net :10101/communication)

2 ws.run_forever()

2Python WebSocket library:http://pypi.python.org/pypi/websocket-client

9.2. CASE STUDY : BEAGLEBONE COMMUNICATION 109 With the connection established, posting data is accomplished by the sending a DataTransfer command (Type:6) on the connection, along with the ID and the raw data in a JSON query.

1 ws.send(’{"Type":6,"Data":{"ID":"cf6cc8e9-df8b-4f05-8bf2-405 c06a15a44","Raw":"test data"}}’)

ButtonsAndLights.py

The modules3 helps establish communication with the button on the top board and for turning on the lights on the top board.

With the established connection, the raw data is transmitted using the following encoding:

dataid:value | dataid:value | ... | dataid:value | crc(md5)

The first part of the raw data string, consists of multiple sets of an unique data ID and its value, separated by a ’:’. Each of the data sets is separated with a ’|’, until the end where an MD5 hash of the data sets in the data string is added.

9.2.2.2 BeagleBone Module & SCL

To handle the raw string, the module first verifies that the data string (until the last ’|’) has the correct MD5 hash. This will verify, that the data has been transmitted correctly and the parsing can continue. The parser splits the raw data string and using theStorageBuilderand the data are passed into theAddValuefunction. At last, the added values are committed to the storage and the parser has completed its job.

To interpret the data from the BeagleBone, the following SCL configuration file has been created:

1 <IED name="BBDERC1">

2 <AccessPoint name="S1">

3 <Server>

4 <Authentication/>

5 <LDevice desc="Flexibility DER unit" inst="BBDERC1">

6 <LN0 lnClass="LLN0" inst="" lnType="LLN0a" />

7 <LN lnClass="FLEX" inst="" lnType="FLEXa">

8 <DOI name="Type"/>

9 <DOI name="ECP"/>

10 <DOI name="Status">

11 <DAI name="AllowRemCtrl">

12 <Val>1</Val>

13 </DAI>

14 <DAI name="ActivateRemCtrl">

15 <Val></Val>

16 </DAI>

17 </DOI>

18 </LN>

19 <LN lnClass="Light" inst="" lnType="LIGHT">

20 <DOI name="TopBoard" />

3http://www.gigamegablog.com/2012/03/16/beaglebone-coding-101-buttons-and-pwm/

110 CHAPTER 9. CASE STUDIES

21 <DOI name="BottomBoard" />

22 </LN>

23 </LDevice>

24 </Server>

25 </AccessPoint>

26 </IED>

With the data types:

1 <DataTypeTemplates>

2 <LNodeType id="LIGHT" lnClass="Light">

3 <DO name="TopBoard" type="TopBoard" />

4 <DO name="BottomBoard" type="BottomBoard" />

5 </LNodeType>

6 <DOType id="TopBoard" cdc="TopBoard">

7 <SDO name="Left" type="StatusValue" />

8 <SDO name="Right" type="StatusValue" />

9 </DOType>

10 <DOType id="BottomBoard" cdc="BottomBoard">

11 <SDO name="Left" type="StatusValue" />

12 <SDO name="Middle" type="StatusValue" />

13 <SDO name="Right" type="StatusValue" />

14 </DOType>

15 <DOType id="StatusValue" cdc="StatusValue">

16 <DA name="StVal" fc="ST" bType="INT32" />

17 </DOType>

18 <LNodeType id="FLEXa" lnClass="FLEX">

19 <DO name="Type" type="FLEXType"/>

20 <DO name="ECP" type="ECP"/>

21 <DO name="Status" type="FLEXStatus"/>

22 </LNodeType>

23 <DOType id="FLEXType" cdc="FLEXType">

24 <DA name="DERName" fc="DC" bType="Unicode255"/>

25 <DA name="DERType" fc="DC" bType="Unicode255"/>

26 </DOType>

27 <DOType id="ECP" cdc="ECP">

28 <DA name="GeoConPnt" fc="CF" bType="Unicode255"/>

29 <SDO name="VolConPnt" type="VolConPnt"/>

30 </DOType>

31 <DOType id="VolConPnt" cdc="VolConPnt">

32 <DA name="mag.f" fc="MX" bType="FLOAT32"/>

33 <DA name="mag.i" fc="MX" bType="INT32"/>

34 </DOType>

35 <DOType id="FLEXStatus" cdc="FLEXStatus">

36 <SDO name="DERStatus" type="StatusValue"/>

37 <SDO name="RemCtrlErr" type="StatusValue"/>

38 <SDO name="RemCtrlEnabled" type="StatusValue"/>

39 <DA name="AllowRemCtrl" fc="CO" bType="INT32"/>

40 <DA name="ActivateRemCtrl" fc="CO" bType="INT32"/>

9.2. CASE STUDY : BEAGLEBONE COMMUNICATION 111 41 </DOType>

42 </DataTypeTemplates>

The important parts in the SCL configuration file, are the three flexibility nodes, configured under the FLEX logical node. The FLEX node includes: Type, ECP (Electrical Connection Point) and Status. If more information was required, the FLEX logical node would simply be extended with more data objects. In addition to the FLEX logical node, the logical node Light has been configured. The Light node consists of a data object for each of the two boards and contains the status values of each led on the board.