First working prototype
This commit is contained in:
103
.gitignore
vendored
103
.gitignore
vendored
@ -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*
|
||||
|
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