Ajouté console audio + chalet dev LTE
This commit is contained in:
@@ -23,6 +23,7 @@ CChaletDevice::CChaletDevice(int Address, CAbstractNetworkCommIF *NetworkInterfa
|
||||
|
||||
mDeviceWiFiParameters.fill(0xFF);
|
||||
mDeviceFirmwareVersion.fill(0xFF);
|
||||
mHomeServerInterface = 0;
|
||||
|
||||
ResetCommStats();
|
||||
}
|
||||
@@ -30,13 +31,21 @@ CChaletDevice::CChaletDevice(int Address, CAbstractNetworkCommIF *NetworkInterfa
|
||||
CChaletDevice::~CChaletDevice()
|
||||
{
|
||||
delete mChaletStatusTimer;
|
||||
if(mHomeServerInterface != 0)
|
||||
{
|
||||
delete mHomeServerInterface;
|
||||
}
|
||||
}
|
||||
|
||||
int CChaletDevice::Start()
|
||||
{
|
||||
ScheduleChaletStatusRequest();
|
||||
mChaletStatusTimer->start(1000);
|
||||
mThingsBoardInterface.RegisterThingsboardRPC();
|
||||
// mThingsBoardInterface.RegisterThingsboardRPC();
|
||||
if(mHomeServerInterface != 0)
|
||||
{
|
||||
mHomeServerInterface->Start();
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@@ -122,7 +131,12 @@ int CChaletDevice::NewDeviceFrameReceived(int DeviceID, int DeviceAddress, int M
|
||||
|
||||
// mThingsBoardInterface.UpdateChaletVoltage(mChaletMainStatus.mBatteryVoltage);
|
||||
//mThingsBoardInterface.UpdateChaletData(mChaletMainStatus.mInverterRelayStatus,mChaletMainStatus.mWiFiModuleStatus,mChaletMainStatus.mCurrentSensorStatus,mChaletMainStatus.mBatteryVoltage,mChaletMainStatus.mBatteryCurrent,mChaletMainStatus.mBatterySOC,mChaletMainStatus.mIsOnline);
|
||||
mThingsBoardInterface.UpdateChaletData(&mChaletMainStatus);
|
||||
//mThingsBoardInterface.UpdateChaletData(&mChaletMainStatus);
|
||||
|
||||
if(mHomeServerInterface != 0)
|
||||
{
|
||||
mHomeServerInterface->UpdateChaletData(&mChaletMainStatus);
|
||||
}
|
||||
|
||||
|
||||
// mChaletModbusRepo.WriteSingleReg(CHALET_MODBUS_ONLINE_STATE_REG,(quint16)mChaletMainStatus.mIsOnline);
|
||||
@@ -430,7 +444,7 @@ int CChaletDevice::CmdResponseReceived(int CmdID)
|
||||
|
||||
int CChaletDevice::ScheduleChaletStatusRequest()
|
||||
{
|
||||
return ScheduleChaletCommand(CHALET_GENERAL_STATUS_REQUEST,0,QByteArray());
|
||||
ScheduleChaletCommand(CHALET_GENERAL_STATUS_REQUEST,0,QByteArray());
|
||||
}
|
||||
|
||||
int CChaletDevice::ScheduleChaletCommand(int CmdID, int DataSize, QByteArray Data)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "ThingsBoardInterface.h"
|
||||
#include "ChaletModbusServer.h"
|
||||
#include "ModbusRepository.h"
|
||||
#include "ChaletHomeServerInterface.h"
|
||||
|
||||
|
||||
#define LORA_MAGIC_WORD 0xBAADCAFE
|
||||
@@ -52,6 +53,7 @@ public:
|
||||
QList<CChaletNetworkMessage> mPendingNetworkMsgList;
|
||||
CChaletDataLogger mChaletDataLogger;
|
||||
CChaletJFUbidotsInterface *mJFUbidotsInterface;
|
||||
CChaletHomeServerInterface *mHomeServerInterface;
|
||||
|
||||
unsigned long long int mNbLostRequest, mTotalNbRequest;
|
||||
float mLostRequestPercentage;
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
#include "ChaletHomeServerInterface.h"
|
||||
|
||||
CChaletHomeServerInterface::CChaletHomeServerInterface()
|
||||
{
|
||||
mConnectionTimer = new QTimer;
|
||||
connect(&mMQTTClient,&QMqttClient::stateChanged,this,&CChaletHomeServerInterface::StateChanged);
|
||||
connect(&mMQTTClient,&QMqttClient::errorChanged,this,&CChaletHomeServerInterface::MQTTClientError);
|
||||
connect(mConnectionTimer,&QTimer::timeout,this,&CChaletHomeServerInterface::ConnectionTimerExpired);
|
||||
|
||||
mConnectionTimer->setSingleShot(true);
|
||||
}
|
||||
|
||||
CChaletHomeServerInterface::~CChaletHomeServerInterface()
|
||||
{
|
||||
DisconnectFromServer();
|
||||
delete mConnectionTimer;
|
||||
}
|
||||
|
||||
int CChaletHomeServerInterface::Start()
|
||||
{
|
||||
mConnectionTimer->start(1000);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CChaletHomeServerInterface::UpdateChaletData(CChaletMainStatus *Data)
|
||||
{
|
||||
QByteArray JsonByteArray;
|
||||
qint64 TimeStamp = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000;
|
||||
|
||||
JsonByteArray.append(QString("{\"timestamp\":%1, ").arg(TimeStamp));
|
||||
JsonByteArray.append("\"Bat_Voltage\":");
|
||||
JsonByteArray.append((QString("%1, ").arg(Data->mBatteryVoltage)).toUtf8().data());
|
||||
|
||||
JsonByteArray.append("\"Bat_SOC\":");
|
||||
JsonByteArray.append((QString("%1, ").arg(Data->mBatterySOC)).toUtf8().data());
|
||||
|
||||
JsonByteArray.append("\"WiFi_State\":");
|
||||
JsonByteArray.append((QString("%1, ").arg(Data->mWiFiModuleStatus)).toUtf8().data());
|
||||
|
||||
JsonByteArray.append("\"CurrentSensor_State\":");
|
||||
JsonByteArray.append((QString("%1, ").arg(Data->mCurrentSensorStatus)).toUtf8().data());
|
||||
|
||||
JsonByteArray.append("\"Bat_Current\":");
|
||||
JsonByteArray.append((QString("%1, ").arg(Data->mBatteryCurrent)).toUtf8().data());
|
||||
|
||||
JsonByteArray.append("\"LoRa_State\":");
|
||||
JsonByteArray.append((QString("%1, ").arg(Data->mIsOnline)).toUtf8().data());
|
||||
|
||||
JsonByteArray.append("\"Inverter_State\":");
|
||||
JsonByteArray.append((QString("%1, ").arg(Data->mInverterRelayStatus)).toUtf8().data());
|
||||
|
||||
JsonByteArray.append("\"Temperature_Sensor\":");
|
||||
JsonByteArray.append((QString("%1}").arg(Data->mChaletTemperature)).toUtf8().data());
|
||||
|
||||
// qDebug("%s",qPrintable(JsonByteArray));
|
||||
|
||||
mMQTTClient.publish(QString("chalet/telemetry"),JsonByteArray,0,true);
|
||||
return RET_OK;
|
||||
|
||||
}
|
||||
|
||||
int CChaletHomeServerInterface::ConnectToServer()
|
||||
{
|
||||
//Setup the client before connecting.
|
||||
mMQTTClient.setAutoKeepAlive(true);
|
||||
mMQTTClient.setClientId("LeChalet");
|
||||
mMQTTClient.setHostname(MQTT_SERVER_IP);
|
||||
mMQTTClient.setPort(MQTT_SERVER_PORT);
|
||||
mMQTTClient.setPassword(MQTT_SERVER_PWD);
|
||||
mMQTTClient.setUsername(MQTT_SERVER_LOGIN);
|
||||
|
||||
qDebug("Trying to connect Chalet MQTT client...");
|
||||
mMQTTClient.connectToHost();
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CChaletHomeServerInterface::DisconnectFromServer()
|
||||
{
|
||||
mMQTTClient.disconnectFromHost();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CChaletHomeServerInterface::MQTTClientError(QMqttClient::ClientError error)
|
||||
{
|
||||
qDebug(qPrintable(QString("Erreur du client Chalet MQTT: %1").arg(error)));
|
||||
}
|
||||
|
||||
void CChaletHomeServerInterface::StateChanged()
|
||||
{
|
||||
switch(mMQTTClient.state())
|
||||
{
|
||||
case QMqttClient::Disconnected:
|
||||
{
|
||||
qDebug("Chalet MQTT client disconnected");
|
||||
mConnectionTimer->start(1000);
|
||||
mConnectionTimer->stop();
|
||||
break;
|
||||
}
|
||||
case QMqttClient::Connected:
|
||||
{
|
||||
qDebug("Chalet MQTT client connected!");
|
||||
mConnectionTimer->stop();
|
||||
break;
|
||||
}
|
||||
case QMqttClient::Connecting:
|
||||
{
|
||||
mConnectionTimer->start(20000);
|
||||
qDebug("Chalet MQTT client is connecting");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CChaletHomeServerInterface::ConnectionTimerExpired()
|
||||
{
|
||||
qDebug("connection timer expired");
|
||||
DisconnectFromServer();
|
||||
ConnectToServer();
|
||||
|
||||
mConnectionTimer->start(15000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef CHALETHOMESERVERINTERFACE_H
|
||||
#define CHALETHOMESERVERINTERFACE_H
|
||||
|
||||
#include <QtMqtt/QtMqtt>
|
||||
#include <QMqttClient>
|
||||
#include "ChaletData.h"
|
||||
#include <QTimer>
|
||||
|
||||
#define MQTT_SERVER_IP "192.168.51.32"
|
||||
#define MQTT_SERVER_PORT 1883
|
||||
#define MQTT_SERVER_LOGIN "jfmartel"
|
||||
#define MQTT_SERVER_PWD "roland"
|
||||
|
||||
class CChaletHomeServerInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CChaletHomeServerInterface();
|
||||
~CChaletHomeServerInterface();
|
||||
int UpdateChaletData(CChaletMainStatus *Data);
|
||||
int ConnectToServer();
|
||||
int DisconnectFromServer();
|
||||
|
||||
int Start();
|
||||
|
||||
|
||||
QMqttClient mMQTTClient;
|
||||
QTimer *mConnectionTimer;
|
||||
|
||||
public slots:
|
||||
void MQTTClientError(QMqttClient::ClientError error);
|
||||
// void MQTTMessageSent(qint32 MsgID);
|
||||
// void MQTTMessageStatusChanged(qint32 id, QMqtt::MessageStatus s, const QMqttMessageStatusProperties &properties);
|
||||
void StateChanged();
|
||||
void ConnectionTimerExpired();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // CHALETHOMESERVERINTERFACE_H
|
||||
Reference in New Issue
Block a user