# SpecTalk: Conforming IoT Implementations to Sensor Specifications
## 3 The SpecTalk Architecture and Procedures
### Generation of the SA Interface  
SpecTalk automatically generates the test procedures for acceptance of a contract in two steps. At Step 1, SpecTalk generates a Sensor and Actuator (SA) interface (Figure 2 (6)). The vendor fills the API of the DUT (Figure 2 (7)) into the SA interface. At Step 2, the vendor executes the SA interface code generated by SpecTalk, and the IoT DUT is connected to the Test Engine (Figure 2 (8)). Then, SpecTalk conducts an acceptance test and automatically generates the test report (Figure 2 (9)). The Test Engine is modified from an IoT application development platform called IoTtalk [19]. By switching from the Device Feature/Model window (Figure 6 (1)) to the IoTtalk project window (Figure 6 (2)), we create the Generator-Test project (Figure 6 (3)). The Model list of the project window (Figure 6 (4)) provides the device model indexes stored in the SpecTalk Database. When we select \"Generator\" (Figure 6 (5)), the Generator window pops up. The features of the vendor's generator are a subset of the Generator device model. Therefore, SpecTalk allows the selection of the DF number to set up the actual configuration of the generator under test (Figure 6 (6)). After we save the setups (Figure 6 (7)), the graphical representation of the generator under test is shown in the Project window (Figure 6 (8)). We can click the DF icon (Figure 6 (9)), and further set up the parameters of the DF, e.g., the max and the min values of the DF (Figure 6 (10)). Figure 4: The Device Model (DM) window. Figure 5: Device Feature (DF) creation. When we complete the IoTtalk project (Figure 7 (1)), SpecTalk automatically generates the code for Device Application (DA; Figure 7 (2)) and the incomplete code for the Sensor and Actuator Application (SA) interface (Figure 7 (3)). Then, the vendor (Figure 7 (4)) fills the API of the IoT DUT to complete the code for the SA interface. The DA is responsible for communication between the DUT and the Test Engine. The protocols include HTTPS and MQTT. The lower-layer communications can be Ethernet, WiFi, LTE, or 5G. The code for the SA interface is listed below:  
1. import time, random, requests
2. import DA
3. import Your-API
4. ServerURL = 'https://DomainName'
5. Reg_addr = \"**GEN-0012**\"
6. DA.profile['dm_name'] = '**Generator'**  
Figure 6: Specifying the generator under test. Figure 7: Automatic generation of the codes for the DA and the SA interface. * (07) D.A.profile['df_list'] = ['oilSts-I', 'batSts-I','ventSts-I',]
* (08) D.profile['d_name'] = 'Your-Device-Name'
* (09) D.register(ServerURL, Reg_addr)
* (10) while True:
* (11) try:
* (12) **oilSts_data = Your-oilSts-function**
* (13) D.push ('oilSts-I', 'oilSts_data)
* (14) **batSts_data = Your-batSts-function**
* (15) D.push ('batSts-I', **batSts_data)
* (16) **ventSts_data = Your-ventSts-function**
* (17) D.push ('ventSts-I', **ventSts_data)
* (18) except Exception as e:
* (19) print(e)
* (20) if str(e).find('mac_addr not found:')! = -1:
* (21) print('Reg_addr is not found. Try to re-register.') * (22) DA.register (ServerURL, Reg_addr)
* (23) else:
* (24) print('Connection fails.') * (25) time.sleep(1)
* (26) time.sleep(0.2)  
In the above program, the black lines with normal font are a general template for any IoT device to follow the TAICS specification. The boldface codes are generated through the steps described in Figure 6. The red parts are the codes to be typed in by the vendor (Figure 7 (4)) through the GUI for the SA interface (Figure 8). This GUI tailored for the IoT DUT is automatically generated by SpecTalk. Specifically, the values of the fields \"Name\", \"API\", \"oilSts\", \"batSts\", and \"ventSts\" are inserted into the code for the SA interface by the Device Application Generation (Figure 8 (1)). At Line 5, \"your-API\" provided by the vendor is used to access the functions for the IoT DUT (Lines 12, 14, and 16). The complete code for the SA interface (Figure 8 (2)) is saved in the file \"File-for-SA-code\", specified in Figure 8 (3).