|
@@ -4,7 +4,6 @@
|
|
|
DmpDataCore::DmpDataCore(QObject *parent) : QObject(parent)
|
|
|
{
|
|
|
isSending1 = true;
|
|
|
- isSending2 = true;
|
|
|
|
|
|
bstrlist.clear();
|
|
|
pointstrlist.clear();
|
|
@@ -28,8 +27,13 @@ DmpDataCore::DmpDataCore(QObject *parent) : QObject(parent)
|
|
|
networkmanager1 = new QNetworkAccessManager(this);
|
|
|
connect(networkmanager1,&QNetworkAccessManager::finished,this,&DmpDataCore::finishedSlot1);
|
|
|
|
|
|
- networkmanager2 = new QNetworkAccessManager(this);
|
|
|
- connect(networkmanager2,&QNetworkAccessManager::finished,this,&DmpDataCore::finishedSlot2);
|
|
|
+ mqttIdx = 1;
|
|
|
+ m_client = new QMQTT::Client(QHostAddress("47.98.201.73"),1883,this);
|
|
|
+ connect(m_client,&QMQTT::Client::connected,this,&DmpDataCore::onConnected);
|
|
|
+ m_client->setUsername("usky");
|
|
|
+ m_client->setPassword("usky");
|
|
|
+ m_client->setCleanSession(true);
|
|
|
+ m_client->connectToHost();
|
|
|
}
|
|
|
|
|
|
DmpDataCore::~DmpDataCore()
|
|
@@ -44,6 +48,11 @@ void DmpDataCore::start()
|
|
|
dataserver->start();
|
|
|
}
|
|
|
|
|
|
+void DmpDataCore::onConnected()
|
|
|
+{
|
|
|
+ printf("mqtt connected\n");
|
|
|
+}
|
|
|
+
|
|
|
void DmpDataCore::time_out()
|
|
|
{
|
|
|
uint t = QDateTime::currentDateTime().toTime_t();
|
|
@@ -63,18 +72,15 @@ void DmpDataCore::time_out()
|
|
|
connect(pTimeout, SIGNAL(net_timeout()),this,SLOT(reply_timeout1()));
|
|
|
}
|
|
|
|
|
|
- if((pointstrlist.length()>0)&&(isSending2)){
|
|
|
- isSending2 = false;
|
|
|
+ if(pointstrlist.length()>0){
|
|
|
QString data = pointstrlist.first();
|
|
|
-
|
|
|
- QByteArray Report = data.toUtf8();
|
|
|
- QNetworkRequest *req = new QNetworkRequest();
|
|
|
- req->setUrl(QUrl("http://172.16.120.69:8086/write?db=USKTSDB_B&u=root&p=root"));
|
|
|
- req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json; charset=UTF-8");
|
|
|
- req->setHeader(QNetworkRequest::ContentLengthHeader,QString("%1").arg(Report.length()).toUtf8());
|
|
|
- QNetworkReply *reply = networkmanager2->post(*req,Report);
|
|
|
- QReplyTimeout *pTimeout = new QReplyTimeout(reply,10000);
|
|
|
- connect(pTimeout, SIGNAL(net_timeout()),this,SLOT(reply_timeout2()));
|
|
|
+ if((m_client->connectionState() == QMQTT::STATE_DISCONNECTED)||(m_client->connectionState() == QMQTT::STATE_INIT)){
|
|
|
+ m_client->connectToHost();
|
|
|
+ }
|
|
|
+ m_client->publish(QMQTT::Message(mqttIdx++,"data-collector",data.toUtf8()));
|
|
|
+ if(mqttIdx > 9999)
|
|
|
+ mqttIdx = 1;
|
|
|
+ pointstrlist.removeFirst();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -106,32 +112,6 @@ void DmpDataCore::finishedSlot1(QNetworkReply *reply)
|
|
|
isSending1 = true;
|
|
|
}
|
|
|
|
|
|
-void DmpDataCore::reply_timeout2()
|
|
|
-{
|
|
|
- if(pointstrlist.length()>0){
|
|
|
- pointstrlist.removeFirst();
|
|
|
- }
|
|
|
- isSending2 = true;
|
|
|
-}
|
|
|
-
|
|
|
-void DmpDataCore::finishedSlot2(QNetworkReply *reply)
|
|
|
-{
|
|
|
- if(pointstrlist.length()>0){
|
|
|
- if(reply->error()==QNetworkReply::NoError){
|
|
|
- QString bak_info = QString::fromUtf8(reply->readAll());
|
|
|
-
|
|
|
- }else{
|
|
|
- QString bak_info = QString::fromUtf8(reply->readAll());
|
|
|
- logthread->appendData(QString("QNetworkReply2::Error [%1]").arg(bak_info));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- pointstrlist.removeFirst();
|
|
|
- }
|
|
|
- reply->deleteLater();
|
|
|
- isSending2 = true;
|
|
|
-}
|
|
|
-
|
|
|
void DmpDataCore::CommData(QString data)
|
|
|
{
|
|
|
logthread->appendData(data);
|