5.1 KiB
SHinterface - Smart Home Interface
Overview
SHinterface is a Qt6-based smart home control application that interfaces with microcontrollers and various sensors to manage home automation devices. It supports both primary (master) and secondary (client) modes, allowing for distributed control across multiple devices.
Architecture
Core Components
-
Main Application (
main.cpp)- Entry point with command-line argument parsing
- Supports three modes:
PROGRAM_MODE_UI_ONLY: Secondary client modePROGRAM_MODE_PRIMARY: Master mode with GUIPROGRAM_MODE_HEADLESS_PRIMARY: Master mode without GUI (server only)
-
Main Object (
mainobject.h,mainobject.cpp)- Base class:
MainObject - Primary mode:
PrimaryMainObject- Manages microcontroller, sensors, and item sources - Secondary mode:
SecondaryMainObject- Connects to primary via TCP
- Base class:
-
Microcontroller Interface (
microcontroller.h,microcontroller.cpp)- Communicates with embedded devices via serial or TCP
- Handles relay control, sensor data, RGB lighting, and PWM outputs
- Implements a write queue to prevent buffer overflows
Key Systems
Items System
-
Item (
items/item.h,items/item.cpp): Base class for all controllable items- Supports different value types: boolean, unsigned integer, no value
- Tracks update sources (user, actor, remote, loaded, backend)
-
Item Types:
- Relay (
items/relay.h,items/relay.cpp): Switchable outputs - PowerItem: Power measurement items
- MessageItem: Display messages
- SystemItem: System-related controls
- AuxItem: Auxiliary PWM outputs
- RGBItem: RGB LED control
- Relay (
-
ItemStore (
items/itemstore.h,items/itemstore.cpp): Manages collection of items -
ItemSource (
items/itemsource.h): Interface for item providers- FixedItemSource: Static predefined items
- ItemLoaderSource: Loads items from configuration
Actors System
Actors trigger actions based on sensor conditions or timers:
-
Actor (
actors/actor.h,actors/actor.cpp): Base actor class- Can be active/inactive and exhausted (preventing repeated triggers)
-
Actor Types:
- FactorActor: Triggers when a factor crosses a threshold
- PolynomalActor: Uses polynomial calculations for triggering
- SensorActor: Reacts to specific sensor states
- TimerActor: Time-based triggering
- AlarmTime: Alarm/clock functionality
- Regulator: PID-like regulation control
Sensors System
-
Sensor (
sensors/sensor.h,sensors/sensor.cpp): Represents physical sensors- Sensor types: door, temperature, humidity, pressure, brightness, button, ADC, CO2, PM2.5, VOC, etc.
-
Sensor Sources:
- SunSensorSource (
sensors/sunsensor.h,sensors/sunsensor.cpp): Solar position calculations - MqttSensorSource (
sensors/mqttsensorsource.h,sensors/mqttsensorsource.cpp): MQTT-based sensor data
- SunSensorSource (
Networking Services
- TcpServer (
service/tcpserver.h,service/tcpserver.cpp): TCP server for remote control - WebSocketServer (
service/websocketserver.h,service/websocketserver.cpp): WebSocket interface - TcpClient (
service/tcpclient.h,service/tcpclient.cpp): Client for secondary instances
UI Components
- MainWindow (
ui/mainwindow.ui,ui/mainwindow.cpp): Main application window - ItemWidget: Visual representation of items
- ItemScrollBox: Scrollable container for items
- SensorListWidget: Displays sensor information
- ItemCreationDialog: Create new items
- ItemSettingsDialog: Configure item properties
- ActorSettingsDialog: Configure actor behavior
Data Flow
Primary Mode (Master)
Microcontroller ↔ Items ↔ Actors ↔ Sensors
↑ ↑ ↑ ↑
TCP/WebSocket │ │ │
└──────┬──────┘
↓
UI (MainWindow)
Secondary Mode (Client)
Secondary Client ↔ TCP Server (Primary) → Items → Microcontroller
Configuration
- Settings stored in JSON format
- Default location:
~/.config/shinterface.json - Command-line options:
-m,--master: Run in master mode-H,--host: Set server host IP-p,--port: Set server port (default: 38940)-c,--config: Specify config file path-e,--headless: Run without GUI (master mode only)
Build Requirements
- CMake 4.0+
- Qt6 (Core, Gui, Widgets, Network, Multimedia, SerialPort, Mqtt, WebSockets)
- libpipewire-0.3
- libnl-3.0
Communication Protocols
- Microcontroller: Text-based protocol over serial or TCP
- Networking: JSON messages over TCP/WebSocket
- Sensors: MQTT for remote sensors, calculated values for sun position
Key Features
- Distributed control with primary/secondary architecture
- Actor-based automation system
- Multi-protocol sensor support (MQTT, serial, calculated)
- Relay and PWM control
- RGB lighting control
- WebSocket API for remote access
- Configurable via JSON
- Cross-platform Qt application