# HG changeset patch # User Michiel Broek # Date 1656415611 -7200 # Node ID 449116c083bde8af4dc5ff60f09c83007bc43495 # Parent bdaac24b86edf1ba8323bfeec1c5c52959094ab9 Respond to websocket ping. Added iSpindels monitor overview. diff -r bdaac24b86ed -r 449116c083bd src/MainWindow.cpp --- a/src/MainWindow.cpp Mon Jun 27 21:12:19 2022 +0200 +++ b/src/MainWindow.cpp Tue Jun 28 13:26:51 2022 +0200 @@ -241,7 +241,7 @@ * Node message are detected by the group_id object. * Device messages are detected by the device object. * - * Messages can be connected to client widgets so we can emit messages to them. + * Signals can be connected from child widgets so we can emit messages to them. */ QString device = jsonMessage.object()["device"].toString(); QString group_id = jsonMessage.object()["group_id"].toString(); @@ -253,17 +253,21 @@ //qDebug() << "found co2meter" << jsonMessage.object()["node"].toString()+"/"+jsonMessage.object()["unit"].toString(); emit updateCO2meters(jsonMessage.object()["node"].toString()+"/"+jsonMessage.object()["unit"].toString()); } else if (device == "ispindels") { - qDebug() << "found iSpindel" << jsonMessage.object()["node"].toString()+"/"+jsonMessage.object()["unit"].toString(); + //qDebug() << "found iSpindel" << jsonMessage.object()["node"].toString()+"/"+jsonMessage.object()["unit"].toString(); emit updateiSpindels(jsonMessage.object()["node"].toString()+"/"+jsonMessage.object()["unit"].toString()); } else { qDebug() << "unknown device" << device; } } else if (group_id != "") { emit updateNodes(jsonMessage.object()["node"].toString()); -// } else if (jsonMessage.object()["ping"].toString() != "") { -// qDebug() << "ping" << jsonMessage; + } else if (jsonMessage.object()["ping"].toInt() ) { + /* + * Reply to ping message. Note that the bmsd ignore's + * our reply, but we send it anyway. + */ + webSocket->sendTextMessage(QString("{\"pong\":1}")); } else { - qDebug() << "unknown WS message" << message; + qDebug() << "unknown WS message" << message << jsonMessage; } } @@ -441,7 +445,7 @@ ui->mainStack->addWidget(MonFermentersWindow); ui->mainStack->setCurrentIndex(index); setWindowTitle( QString("BMSapp - %1 - Monitor Fermenters").arg(VERSIONSTRING)); -// ui->menuBar->setVisible(false); + ui->menuBar->setVisible(false); } @@ -483,7 +487,7 @@ ui->mainStack->addWidget(MoniSpindelsWindow); ui->mainStack->setCurrentIndex(index); setWindowTitle( QString("BMSapp - %1 - Monitor iSpindels").arg(VERSIONSTRING)); -// ui->menuBar->setVisible(false); + ui->menuBar->setVisible(false); } diff -r bdaac24b86ed -r 449116c083bd src/MoniSpindels.cpp --- a/src/MoniSpindels.cpp Mon Jun 27 21:12:19 2022 +0200 +++ b/src/MoniSpindels.cpp Tue Jun 28 13:26:51 2022 +0200 @@ -17,6 +17,7 @@ #include "MoniSpindels.h" #include "EditSupplier.h" #include "MainWindow.h" +#include "Utils.h" #include "config.h" @@ -31,16 +32,16 @@ gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - tableSuppliers = new QTableWidget(this); - tableSuppliers->setObjectName(QString::fromUtf8("tableSuppliers")); - tableSuppliers->setEnabled(true); + tableiSpindels = new QTableWidget(this); + tableiSpindels->setObjectName(QString::fromUtf8("tableiSpindels")); + tableiSpindels->setEnabled(true); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(tableSuppliers->sizePolicy().hasHeightForWidth()); - tableSuppliers->setSizePolicy(sizePolicy); - tableSuppliers->setMinimumSize(QSize(1054, 0)); - gridLayout->addWidget(tableSuppliers, 0, 0, 1, 1); + sizePolicy.setHeightForWidth(tableiSpindels->sizePolicy().hasHeightForWidth()); + tableiSpindels->setSizePolicy(sizePolicy); + tableiSpindels->setMinimumSize(QSize(1054, 0)); + gridLayout->addWidget(tableiSpindels, 0, 0, 1, 1); groupBox = new QGroupBox(this); groupBox->setObjectName(QString::fromUtf8("groupBox")); @@ -57,64 +58,83 @@ QIcon icon; icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); quitButton->setIcon(icon); - horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft); - - insertButton = new QPushButton(groupBox); - insertButton->setObjectName(QString::fromUtf8("insertButton")); - insertButton->setMinimumSize(QSize(80, 24)); - insertButton->setText(tr("New")); - QIcon icon1; - icon1.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off); - insertButton->setIcon(icon1); - horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); + horizontalLayout->addWidget(quitButton, 0, Qt::AlignCenter); gridLayout->addWidget(groupBox, 1, 0, 1, 1); connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromMoniSpindels())); - connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); + connect(parent, SIGNAL(updateiSpindels(QString)), this, SLOT(refreshiSpindels(QString))); emit refreshTable(); } void MoniSpindels::refreshTable() { + QTableWidgetItem *item; + qDebug() << "MoniSpindels reload"; - // query.exec("SELECT record,alias,online FROM mon_ispindels ORDER BY alias"); - QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name"); - const QStringList labels({tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")}); + QSqlQuery query("SELECT record,alias,node,online,mode,temperature,gravity,beercode,beername FROM mon_ispindels ORDER BY alias"); + const QStringList labels({tr("Unit"), tr("Node"), tr("Status"), tr("Beer"), tr("Temperature"), tr("SG"), tr("Edit")}); - this->tableSuppliers->setColumnCount(6); - this->tableSuppliers->setColumnWidth(0, 250); /* Name */ - this->tableSuppliers->setColumnWidth(1, 250); /* Address */ - this->tableSuppliers->setColumnWidth(2, 200); /* City */ - this->tableSuppliers->setColumnWidth(3, 120); /* Country */ - this->tableSuppliers->setColumnWidth(4, 120); /* Phone */ - this->tableSuppliers->setColumnWidth(5, 90); /* Edit button */ - this->tableSuppliers->setRowCount(query.size()); - this->tableSuppliers->setHorizontalHeaderLabels(labels); - this->tableSuppliers->verticalHeader()->hide(); + this->tableiSpindels->setColumnCount(7); + this->tableiSpindels->setColumnWidth(0, 150); /* Alias */ + this->tableiSpindels->setColumnWidth(1, 120); /* Node */ + this->tableiSpindels->setColumnWidth(2, 100); /* Status */ + this->tableiSpindels->setColumnWidth(3, 350); /* Beer */ + this->tableiSpindels->setColumnWidth(4, 90); /* Temperature */ + this->tableiSpindels->setColumnWidth(5, 90); /* Gravity */ + this->tableiSpindels->setColumnWidth(6, 90); /* Edit button */ + this->tableiSpindels->setRowCount(query.size()); + this->tableiSpindels->setHorizontalHeaderLabels(labels); + this->tableiSpindels->verticalHeader()->hide(); /* Set the widget size to 1054 x 575 in the ui. */ query.first(); - for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { - this->tableSuppliers->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); - this->tableSuppliers->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString())); - this->tableSuppliers->setItem(ridx, 2, new QTableWidgetItem(query.value(3).toString())); - this->tableSuppliers->setItem(ridx, 3, new QTableWidgetItem(query.value(5).toString())); - this->tableSuppliers->setItem(ridx, 4, new QTableWidgetItem(query.value(8).toString())); + for (int i = 0 ; i < query.size() ; i++ ) { + this->tableiSpindels->setItem(i, 0, new QTableWidgetItem(query.value("alias").toString())); + this->tableiSpindels->setItem(i, 1, new QTableWidgetItem(query.value("node").toString())); + + if (query.value("online").toInt()) { + item = new QTableWidgetItem(QString("Ok")); + } else { + item = new QTableWidgetItem(QString("Offline")); + item->setForeground(QBrush(QColor(Qt::red))); + } + item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + this->tableiSpindels->setItem(i, 2, item); + + if (query.value("mode").toString() == "ON") { + item = new QTableWidgetItem(query.value("beercode").toString()+" - "+query.value("beername").toString()); + this->tableiSpindels->setItem(i, 3, item); + } else { + this->tableiSpindels->setItem(i, 3, new QTableWidgetItem(QString(""))); + } + + if (query.value("online").toInt()) { + item = new QTableWidgetItem(QString("%1°C").arg(query.value("temperature").toDouble(), 4, 'f', 3, '0')); + item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + this->tableiSpindels->setItem(i, 4, item); + double sg = Utils::plato_to_sg(query.value("gravity").toDouble()); + item = new QTableWidgetItem(QString("%1").arg(sg, 5, 'f', 4, '0')); + item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + this->tableiSpindels->setItem(i, 5, item); + } else { + this->tableiSpindels->setItem(i, 4, new QTableWidgetItem(QString(""))); + this->tableiSpindels->setItem(i, 5, new QTableWidgetItem(QString(""))); + } /* Add the Edit button */ QWidget* pWidget = new QWidget(); QPushButton* btn_edit = new QPushButton(); - btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ - btn_edit->setText(tr("Edit")); + btn_edit->setObjectName(QString("%1").arg(query.value("record").toString())); /* Send record with the button */ + btn_edit->setText(tr("Details")); connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); QHBoxLayout* pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_edit); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - this->tableSuppliers->setCellWidget(ridx, 5, pWidget); + this->tableiSpindels->setCellWidget(i, 6, pWidget); query.next(); } emit setStatus(QString(tr("Total items: %1")).arg(query.size())); @@ -124,13 +144,20 @@ MoniSpindels::~MoniSpindels() {} +void MoniSpindels::refreshiSpindels(QString data) +{ + qDebug() << "refreshiSpindels" << data; + emit refreshTable(); +} + + void MoniSpindels::edit(int recno) { - EditSupplier dialog(recno, this); +// EditSupplier dialog(recno, this); /* Signal from editor if a refresh is needed */ - connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); - dialog.setModal(true); - dialog.exec(); +// connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); +// dialog.setModal(true); +// dialog.exec(); } @@ -142,8 +169,3 @@ } -void MoniSpindels::on_insertButton_clicked() -{ - edit(-1); -} - diff -r bdaac24b86ed -r 449116c083bd src/MoniSpindels.h --- a/src/MoniSpindels.h Mon Jun 27 21:12:19 2022 +0200 +++ b/src/MoniSpindels.h Tue Jun 28 13:26:51 2022 +0200 @@ -25,17 +25,18 @@ void setStatus(QString); private slots: - void on_insertButton_clicked(); void on_editButton_clicked(); void refreshTable(void); +public slots: + void refreshiSpindels(QString); + private: QGridLayout *gridLayout; - QTableWidget *tableSuppliers; + QTableWidget *tableiSpindels; QGroupBox *groupBox; QHBoxLayout *horizontalLayout; QPushButton *quitButton; - QPushButton *insertButton; void edit(int recno); };