First working prototype
This commit is contained in:
103
.gitignore
vendored
103
.gitignore
vendored
@ -1,52 +1,73 @@
|
|||||||
# C++ objects and libs
|
# This file is used to ignore files which are generated
|
||||||
*.slo
|
# ----------------------------------------------------------------------------
|
||||||
*.lo
|
|
||||||
*.o
|
*~
|
||||||
|
*.autosave
|
||||||
*.a
|
*.a
|
||||||
*.la
|
*.core
|
||||||
*.lai
|
*.moc
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
*.so
|
*.so
|
||||||
*.so.*
|
*.so.*
|
||||||
*.dll
|
*_pch.h.cpp
|
||||||
*.dylib
|
*_resource.rc
|
||||||
|
*.qm
|
||||||
# Qt-es
|
.#*
|
||||||
object_script.*.Release
|
*.*#
|
||||||
object_script.*.Debug
|
core
|
||||||
*_plugin_import.cpp
|
!core/
|
||||||
|
tags
|
||||||
|
.DS_Store
|
||||||
|
.directory
|
||||||
|
*.debug
|
||||||
|
Makefile*
|
||||||
|
*.prl
|
||||||
|
*.app
|
||||||
|
moc_*.cpp
|
||||||
|
ui_*.h
|
||||||
|
qrc_*.cpp
|
||||||
|
Thumbs.db
|
||||||
|
*.res
|
||||||
|
*.rc
|
||||||
/.qmake.cache
|
/.qmake.cache
|
||||||
/.qmake.stash
|
/.qmake.stash
|
||||||
*.pro.user
|
|
||||||
*.pro.user.*
|
|
||||||
*.qbs.user
|
|
||||||
*.qbs.user.*
|
|
||||||
*.moc
|
|
||||||
moc_*.cpp
|
|
||||||
moc_*.h
|
|
||||||
qrc_*.cpp
|
|
||||||
ui_*.h
|
|
||||||
*.qmlc
|
|
||||||
*.jsc
|
|
||||||
Makefile*
|
|
||||||
*build-*
|
|
||||||
*.qm
|
|
||||||
*.prl
|
|
||||||
|
|
||||||
# Qt unit tests
|
# qtcreator generated files
|
||||||
target_wrapper.*
|
*.pro.user*
|
||||||
|
|
||||||
# QtCreator
|
# xemacs temporary files
|
||||||
*.autosave
|
*.flc
|
||||||
|
|
||||||
# QtCreator Qml
|
# Vim temporary files
|
||||||
*.qmlproject.user
|
.*.swp
|
||||||
*.qmlproject.user.*
|
|
||||||
|
|
||||||
# QtCreator CMake
|
# Visual Studio generated files
|
||||||
CMakeLists.txt.user*
|
*.ib_pdb_index
|
||||||
|
*.idb
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.vcproj
|
||||||
|
*vcproj.*.*.user
|
||||||
|
*.ncb
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.vcxproj
|
||||||
|
*vcxproj.*
|
||||||
|
|
||||||
# QtCreator 4.8< compilation database
|
# MinGW generated files
|
||||||
compile_commands.json
|
*.Debug
|
||||||
|
*.Release
|
||||||
|
|
||||||
|
# Python byte code
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
# --------
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
|
||||||
# QtCreator local machine specific files for imported projects
|
|
||||||
*creator.user*
|
|
||||||
|
53
main.cpp
Normal file
53
main.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QWebSocket>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
QWebSocket webSocket;
|
||||||
|
QObject::connect(&webSocket, &QWebSocket::connected, [&](){ qDebug() << "connected()"; });
|
||||||
|
QObject::connect(&webSocket, &QWebSocket::disconnected, [&](){ qDebug() << "disconnected()"; });
|
||||||
|
// QObject::connect(&webSocket, &QWebSocket::textFrameReceived, [&](const QString &frame, bool isLastFrame){
|
||||||
|
// qDebug() << "textFrameReceived()";
|
||||||
|
// });
|
||||||
|
// QObject::connect(&webSocket, &QWebSocket::binaryFrameReceived, [&](const QByteArray &frame, bool isLastFrame){
|
||||||
|
// qDebug() << "binaryFrameReceived()";
|
||||||
|
// });
|
||||||
|
QObject::connect(&webSocket, &QWebSocket::textMessageReceived, [&](const QString &message){
|
||||||
|
qDebug() << "textMessageReceived()" << message;
|
||||||
|
});
|
||||||
|
QObject::connect(&webSocket, &QWebSocket::binaryMessageReceived, [&](const QByteArray &message){
|
||||||
|
qDebug() << "binaryMessageReceived()" << message;
|
||||||
|
});
|
||||||
|
QObject::connect(&webSocket, qOverload<QAbstractSocket::SocketError>(&QWebSocket::error), [&](QAbstractSocket::SocketError error){
|
||||||
|
qDebug() << "error()" << error;
|
||||||
|
});
|
||||||
|
webSocket.open(QUrl{"ws://licht.realraum.at/sock"});
|
||||||
|
|
||||||
|
const auto sendMQTT = [&](const QString &ctx, const QJsonValue &data){
|
||||||
|
const QJsonObject m{{"ctx", ctx}, {"data", data}};
|
||||||
|
const auto text = QJsonDocument{m}.toJson();
|
||||||
|
qDebug() << "sendTextMessage()" << text;
|
||||||
|
webSocket.sendTextMessage(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto mqtttopic_golightctrl = [](const QString &lightname){
|
||||||
|
return QString{"action/GoLightCtrl/%0"}.arg(lightname);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto sendYmhButton = [&](const QString &btn){
|
||||||
|
sendMQTT(mqtttopic_golightctrl(btn), QJsonObject{{"Action", "send"}});
|
||||||
|
};
|
||||||
|
|
||||||
|
QTimer::singleShot(1000, [&](){
|
||||||
|
sendYmhButton("ymhvolup");
|
||||||
|
});
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
Reference in New Issue
Block a user