# An Efficient Interface for the Integration of IoT Devices with Smart Grids
## 4 Architecture
The following abbreviations are used in this manuscript:

6 LoWPANIPv6 over Low power Wireless Personal Area Networks

ACSIAbstract Communication Service Interface

AMIAdvanced Metering Infrastructure

AMRAutomatic Meter Reading

AMQPAdvanced Message Queuing Protocol

APDUApplication Protocol Data Unit

APIApplication Interface Programming

CBORConcise Binary Object Representation

CoAPConstrained Application Protocol

COIIoTCoAP and OSGPIntegration for Internet of Things

CPSCyber-Physical System

DDSData Distribution Service

DNP3.0 Distributed Network Protocol 3.0

EPCElectronic Product Code

ETSIEuropean Telecommunications Standards Institute

GUIGraphical User Interface

HDLCHigh-level Data Link Control

HTTPHypertext Transfer Protocol

IECInternational Electrotechnical Commission
```
```
1 ETFInternet Engineering Task Force IoTInternet of Things IPv6 Internet Protocol v6 ITUInternational Telecommunication Union JSONJavaScript Object Notation M2 MMachine-to-Machine MQTTMessage Queue Telemetry Transport MSBMost Significant Byte OPCOpen Platform Communication OPCUAOPCUnified Architecture OSGPOpen Smart Grid Protocol OSIOpen System Interconnection PEDPending Event Descriptor PMUPhasor Measurement Unit QoSQuality of Service RFIDRadio-Frequency Identification RPLRouting Protocol for Low Power and Lossy Networks SGSmart Grid SOAPSimple Object Access Protocol TCPTransmission Control Protocol UDPUser Datagram Protocol URIUniform Resource Identifier WSNWireless Sensor Networks XaaSEverything-as-a-Service XMPPExtensible Messaging and Presence Protocol XMLExtensible Markup Language
```  
**Algorithm A1**Partial_Write_to_PUT_request  
This appendix present the algorithms designed for the methods implemented to map the requests from the OSGP domain to the CoAP domain (Algorithms A1-A4), as well as the responses between the two domains (Algorithms A5-A8). Algorithms A1 and A2 map a partial and full write operations from the OSGP domain to PUT and POST operations from the CoAP domain, respectively. These algorithms use a structure similar to that used in the algorithms described in Section 4. It is important to mention that the mapping of a partial write operation (Algorithm A1) concatenates the offset with the payload (line 8). ```
Input : OSGPpartial write request APDU Output : CoAPPUTrequest packet
1 packet.version \(\leftarrow\) CoAPVersion; packet.request_type \(\leftarrow\) PUT; packet.hdr.code \(\leftarrow\) WRITE; packet.id \(\leftarrow\) APDU.tableID; packet.command \(\leftarrow\) APDU.command; packet.options \(\leftarrow\) 0; packet.payload_length \(\leftarrow\) APDU.count_bytes; packet.payload_data \(\leftarrow\) APDU.offset \(\mathrel{+}\) APDU.payload; returnCoAPPUTrequestpacket
```  
**Algorithm A2**Partial_Write_to_PUT_request  
```
Input : OSGPpartial write request APDU Output : CoAPPUTrequest packet
1 packet.version \(\leftarrow\) CoAPVersion; packet.request_type \(\leftarrow\) PUT; packet.hdr.code \(\leftarrow\) WRITE; packet.id \(\leftarrow\) APDU.tableID; packet.command \(\leftarrow\) APDU.command; packet.options \(\leftarrow\) 0; packet.payload_length \(\leftarrow\) APDU.count_bytes; packet.payload_data \(\leftarrow\) APDU.offset \(\mathrel{+}\) APDU.payload; returnCoAPPUTrequestpacket
```  
**Algorithm A3**Partial_Write_to_PUT_request
```
Input : OSGP full write request APDU Output : CoAP POST request packet
1 packet.version \(\leftarrow\) CoAP Version;
2 packet.request_type \(\leftarrow\) POST;
3 packet.hdr.code \(\leftarrow\) WRITE;
4 packet.id \(\leftarrow\) APDU.tableID;
5 packet.command \(\leftarrow\) APDU.command;
6 packet.options \(\gets\) 0;
7 packet.payload_length \(\leftarrow\) APDU.count_bytes;
8 packet.payload.data \(\leftarrow\) APDU.payload;
9 return CoAP POST request packet
```  
**Algorithm A2**Full_Write_to_POST_request  
Algorithms A3 and A4 map read packets from OSGP to packets of CoAP which implement the GET method. As they deal with read operations, no data is loaded in the payload. However, in partial reads, it is necessary to inform the size of the offset.