From 874f3797a987c66f9b91b8bc3cdcb2f793bdc105 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sun, 3 May 2020 01:40:24 +0200 Subject: [PATCH] First working prototype --- .gitignore | 103 ++++++++++++++++++++++++++++++++--------------------- main.cpp | 53 +++++++++++++++++++++++++++ r3ctl.pro | 8 +++++ 3 files changed, 123 insertions(+), 41 deletions(-) create mode 100644 main.cpp create mode 100644 r3ctl.pro diff --git a/.gitignore b/.gitignore index f147edf..fab7372 100644 --- a/.gitignore +++ b/.gitignore @@ -1,52 +1,73 @@ -# C++ objects and libs -*.slo -*.lo -*.o +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave *.a -*.la -*.lai +*.core +*.moc +*.o +*.obj +*.orig +*.rej *.so *.so.* -*.dll -*.dylib - -# Qt-es -object_script.*.Release -object_script.*.Debug -*_plugin_import.cpp +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc /.qmake.cache /.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 -target_wrapper.* +# qtcreator generated files +*.pro.user* -# QtCreator -*.autosave +# xemacs temporary files +*.flc -# QtCreator Qml -*.qmlproject.user -*.qmlproject.user.* +# Vim temporary files +.*.swp -# QtCreator CMake -CMakeLists.txt.user* +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* -# QtCreator 4.8< compilation database -compile_commands.json +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe -# QtCreator local machine specific files for imported projects -*creator.user* diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..35f591c --- /dev/null +++ b/main.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include +#include + +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(&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(); +} diff --git a/r3ctl.pro b/r3ctl.pro new file mode 100644 index 0000000..2622e72 --- /dev/null +++ b/r3ctl.pro @@ -0,0 +1,8 @@ +QT = core network websockets + +CONFIG += c++14 + +DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 + +SOURCES += \ + main.cpp