Skip to main content
. 2020 Oct 23;20(21):6012. doi: 10.3390/s20216012
Algorithm 2. Logic Control of Gateway
Begin: JSON context of user request
1: msg is JSON context of user request
2: Get SDCname, SDCstate, SDCstate_Topic, and SDCcmd_Topic from JSON device state
3: Get device_name and device_state from JSON device state
4: if Controllable(device_name, device_state) is False then
5:  publish_message(‘False’, SDCstate_Topic)
6:  return
7: end if
8: set_device_state(SDCname, device_name)
9: Get device’s type from JSON device state
10: if msg == ‘switch controlled device’ then
11:  Update the device that SDC is controlling in JSON device state
12: elif msg == ‘control device’
13:  According user request set device_set_value and generate command
14:  Using device_name and device_set_value to update device’s state
15:  Get device_state after update
16: if device’s type is ‘smart device’ then
17:   publish_message(command and type, SDCcmd_Topic)
18: elif device’s type is ‘traditional device’
19:   Get TDCname, TDCstate, TDCstate_Topic, and TDCcmd_Topic from JSON device state
20:   publish_message(command and type, TDCcmd_Topic)
21: end if
22: end if
23: publish_message(device_state, SDCstate_Topic)
24: END