Skip to main content

IoT & Networking

HIL provides built-in support for IoT connectivity through MQTT, WebSocket, and HTTP protocols. These capabilities enable real-time sensor data publishing, remote device control, and integration with cloud platforms (Al-Fuqaha et al., 2015).

Network Architecture​

Network API​

The network module is exposed through the registry API on port 3002:

Device Discovery​

# List all network devices
curl http://localhost:3002/api/network/devices

# Response:
{
"devices": [
{
"id": "hil-device-001",
"name": "Temp Sensor",
"type": "sensor",
"status": "online",
"ip": "192.168.1.100",
"lastSeen": "2026-01-15T10:30:00Z"
}
],
"total": 1
}

Topic Management​

# List active topics
curl http://localhost:3002/api/network/topics

# Response:
{
"topics": ["sensors/temperature", "actuators/fan", "system/status"]
}

Message Feed​

# Get recent network messages
curl http://localhost:3002/api/network/feed

# Response:
{
"messages": [
{
"topic": "sensors/temperature",
"payload": "25.5",
"timestamp": "2026-01-15T10:30:00Z",
"device": "hil-device-001"
}
]
}

MQTT Integration​

MQTT is the primary protocol for IoT communication in HIL. It provides lightweight publish/subscribe messaging ideal for constrained devices (Nawaz et al., 2020).

Topic Hierarchy​

hil/
├── devices/
│ ├── {deviceId}/
│ │ ├── status # online/offline
│ │ ├── telemetry/ # sensor data
│ │ │ ├── temperature
│ │ │ ├── humidity
│ │ │ └── pressure
│ │ └── commands/ # control messages
│ │ ├── led
│ │ ├── servo
│ │ └── motor
├── system/
│ ├── ota/ # firmware updates
│ ├── errors/ # error reports
│ └── discovery/ # device registration
└── broadcast/ # system-wide messages

Publishing Sensor Data​

; Publish temperature reading
(MQTT-PUBLISH "hil/devices/sensor01/telemetry/temperature" 25.5)

; Publish with QoS level 1
(MQTT-PUBLISH "hil/devices/sensor01/status" "online" 1)

Subscribing to Commands​

; Subscribe to LED control topic
(MQTT-SUBSCRIBE "hil/devices/sensor01/commands/led")

; Check for incoming messages
(SET msg (MQTT-RECEIVE))
(IF msg (LOG "Command: " msg))

QoS Levels​

LevelNameDescriptionUse Case
0At most onceFire and forgetTelemetry, non-critical data
1At least onceAcknowledged deliveryCommands, important updates
2Exactly onceGuaranteed deliveryFirmware updates, configuration

WebSocket Communication​

WebSocket provides full-duplex communication for real-time web applications:

HTTP API​

The HTTP API provides RESTful access to device data and control:

# Get device status
GET /api/devices/{id}

# Send command
POST /api/devices/{id}/command
Content-Type: application/json
{"action": "write", "pin": 13, "value": 1}

# Get sensor history
GET /api/devices/{id}/telemetry?from=2026-01-15&to=2026-01-16

# Trigger OTA update
POST /api/devices/{id}/ota
{"version": "2.0.0"}

Error Reporting​

The network module automatically reports device errors to the central registry:

# Report an error from device
curl -X POST http://localhost:3002/api/errors \
-H "Content-Type: application/json" \
-d '{
"device_id": "hil-device-001",
"error_type": "runtime",
"message": "ADC overflow on pin A0",
"severity": "medium"
}'

Security Considerations​

IoT deployments require attention to security at multiple layers (Sicari et al., 2015):

  1. Transport Encryption: Use TLS for MQTT (port 8883) and WSS for WebSocket
  2. Authentication: Device tokens for API access, MQTT username/password
  3. Authorization: Topic-level ACLs restrict device publish/subscribe scope
  4. Input Validation: All incoming messages are validated before execution

References

Al-Fuqaha, A., Guizani, M., Mohammadi, M., Aledhari, M., & Ayyash, M. (2015). Internet of Things: A survey on enabling technologies, protocols, and applications. IEEE Communications Surveys & Tutorials, 17(4), 2347–2376.

Nawaz, N., Ali, H., & Shah, M. A. (2020). MQTT-based IoT security: A survey. In Proceedings of the 2020 IEEE International Conference on Smart IoT (pp. 1–6).

Sicari, S., Rizzardi, A., Grieco, L. A., & Coen-Porisini, A. (2015). Security, privacy and trust in Internet of Things: The road ahead. Computer Networks, 76, 146–164.