Add websocket server
This commit is contained in:
parent
59b55d1868
commit
3e0ba165e8
3 changed files with 11 additions and 2 deletions
|
|
@ -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}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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(µ)
|
||||
{
|
||||
//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(µ, &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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue