Add websocket server

This commit is contained in:
Carl Philipp Klemm 2026-03-27 20:30:53 +01:00
parent 59b55d1868
commit 3e0ba165e8
3 changed files with 11 additions and 2 deletions

View file

@ -10,7 +10,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-Wall)
# Find Qt packages
find_package(Qt6 COMPONENTS Core Gui Widgets Network Multimedia SerialPort Mqtt REQUIRED)
find_package(Qt6 COMPONENTS Core Gui Widgets Network Multimedia SerialPort Mqtt WebSockets REQUIRED)
# Find dependencies using pkg-config
find_package(PkgConfig REQUIRED)
@ -51,6 +51,8 @@ target_sources(SHinterface
src/service/tcpclient.cpp
src/service/tcpserver.h
src/service/tcpserver.cpp
src/service/websocketserver.h
src/service/websocketserver.cpp
src/actors/actor.h
src/actors/actor.cpp
@ -166,6 +168,7 @@ target_link_libraries(SHinterface
Qt6::Multimedia
Qt6::SerialPort
Qt6::Mqtt
Qt6::WebSockets
${PIPEWIRE_LIBRARIES}
${LIBNL3_LIBRARIES}
)

View file

@ -72,13 +72,15 @@ PrimaryMainObject::PrimaryMainObject(QIODevice* microDevice, const QString& sett
MainObject(parent),
settingsPath(settingsPath),
micro(microDevice),
tcpServer(new TcpServer),
tcpServer(new TcpServer(this)),
webServer(new WebSocketServer("shinterface", this)),
sunSensorSource(49.824972, 8.702194),
fixedItems(&micro)
{
//connect sensors subsystem
connect(&globalSensors, &SensorStore::sensorChangedState, tcpServer, &TcpServer::sensorEvent);
connect(tcpServer, &TcpServer::gotSensor, &globalSensors, &SensorStore::sensorGotState);
connect(webServer, &WebSocketServer::gotSensor, &globalSensors, &SensorStore::sensorGotState);
connect(&sunSensorSource, &SunSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
connect(&micro, &Microcontroller::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
connect(&mqttSensorSource, &MqttSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
@ -98,7 +100,9 @@ PrimaryMainObject::PrimaryMainObject(QIODevice* microDevice, const QString& sett
mqttSensorSource.start(mqttJson);
tcpServer->launch(QHostAddress(host), port);
webServer->launch(QHostAddress(host), port+1);
connect(&globalItems, &ItemStore::itemUpdated, tcpServer, &TcpServer::itemUpdated);
connect(&globalItems, &ItemStore::itemUpdated, webServer, &WebSocketServer::itemUpdated);
}
PrimaryMainObject::~PrimaryMainObject()

View file

@ -19,6 +19,7 @@
#include "items/itemloadersource.h"
#include "service/tcpclient.h"
#include "service/tcpserver.h"
#include "service/websocketserver.h"
class MainObject : public QObject
{
@ -44,6 +45,7 @@ public:
Microcontroller micro;
TcpServer* tcpServer;
WebSocketServer* webServer;
//sensors
SunSensorSource sunSensorSource;