From cd52a6063eb56db0f2601e1b9081ea7c4d16d094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 14 Mar 2016 00:35:40 +0000 Subject: [PATCH] Add some debugging output when pairing. --- server.cpp | 16 ++++++++++++---- socket.cpp | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/server.cpp b/server.cpp index 5fd19c6..fc38ef1 100644 --- a/server.cpp +++ b/server.cpp @@ -62,7 +62,7 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password) for (auto & x : nc) { if (x.bearerType() == QNetworkConfiguration::BearerWLAN) { if (x.name() == "WiWo-S20") { - qWarning() << "Connecting to WiWo-S20 wireless"; + qDebug() << "Connecting to WiWo-S20 wireless"; cfg = &x; stop = true; } @@ -72,9 +72,9 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password) QNetworkSession *session = new QNetworkSession(*cfg, this); session->open(); - qWarning() << "Wait for connected!"; + qDebug() << "Wait for connected!"; if (session->waitForOpened()) - qWarning() << "Connected!"; + qDebug() << "Connected!"; QUdpSocket *udpSocketSend = new QUdpSocket(); udpSocketGet = new QUdpSocket(); @@ -82,20 +82,27 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password) QByteArray reply; + qDebug() << "Send: HF-A11ASSISTHREAD"; udpSocketGet->writeDatagram(QByteArray::fromStdString("HF-A11ASSISTHREAD"), QHostAddress::Broadcast, port); reply = listen(QByteArray::fromStdString("HF-A11ASSISTHREAD")); QList list = reply.split(','); QHostAddress ip(QString::fromLatin1(list[0])); - qWarning() << "IP: " << ip.toString(); + qDebug() << "IP: " << ip.toString(); + qDebug() << "Send: +ok"; udpSocketGet->writeDatagram(QByteArray::fromStdString("+ok"), ip, port); + qDebug() << "Send: AT+WSSSID=" + QString::fromLatin1(ssid) + "\r"; udpSocketGet->writeDatagram(QByteArray::fromStdString("AT+WSSSID=") + ssid + QByteArray::fromStdString("\r"), ip, port); listen(); + qDebug() << "Send: AT+WSKEY=WPA2PSK,AES," + QString::fromLatin1(password) + "\r"; udpSocketGet->writeDatagram(QByteArray::fromStdString("AT+WSKEY=WPA2PSK,AES,") + password + QByteArray::fromStdString("\r"), ip, port); // FIXME: support different security settings // OPEN, SHARED, WPAPSK......NONE, WEP, TKIP, AES listen(); + qDebug() << "Send: AT+WMODE=STA\\r"; udpSocketGet->writeDatagram(QByteArray::fromStdString("AT+WMODE=STA\r"), ip, port); listen(); + qDebug() << "Send: AT+Z\\r"; udpSocketGet->writeDatagram(QByteArray::fromStdString("AT+Z\r"), ip, port); // reboot + listen(); session->close(); // FIXME: discover the new socket qWarning() << "Finished"; @@ -122,6 +129,7 @@ QByteArray Server::listen(QByteArray message) while (udpSocketGet->hasPendingDatagrams()) { reply.resize(udpSocketGet->pendingDatagramSize()); udpSocketGet->readDatagram(reply.data(), reply.size(), &sender, &senderPort); + qDebug() << "Reply: " << QString::fromLatin1(reply.data()); if (reply != message) { stop = true; } diff --git a/socket.cpp b/socket.cpp index f4c9ce1..ffd804f 100644 --- a/socket.cpp +++ b/socket.cpp @@ -35,7 +35,7 @@ Socket::Socket(QHostAddress IPaddress, QByteArray reply) commandID[QueryAll] = QStringLiteral("qa").toLatin1(); commandID[Discover] = QStringLiteral("qg").toLatin1(); // qg - commandID[Subscribe] = QStringLiteral("cl").toLatin1(); // Login Command + commandID[Subscribe] = QStringLiteral("cl").toLatin1(); // Claim commandID[PowerOn] = QStringLiteral("sf").toLatin1(); // State Flip (change of power state) commandID[PowerOff] = commandID[PowerOn]; commandID[ReadTable] = QStringLiteral("rt").toLatin1(); @@ -49,7 +49,7 @@ Socket::Socket(QHostAddress IPaddress, QByteArray reply) datagram[Subscribe] = commandID[Subscribe] + mac + twenties + rmac + twenties; datagram[PowerOn] = commandIDPower + mac + twenties + zeros + one; datagram[PowerOff] = commandIDPower + mac + twenties + zeros + zero; - datagram[ReadTable] = commandID[ReadTable] + mac + twenties + /*zeros*/QByteArray::fromHex("72 00 00 00") + QByteArray::fromHex("01 00 00") + zeros; + datagram[ReadTable] = commandID[ReadTable] + mac + twenties + /*zeros*/QByteArray::fromHex("00 00 00 00") /*cookie*/ + QByteArray::fromHex("01 00") + zero + zeros; udpSocket = new QUdpSocket(); udpSocket->connectToHost(ip, 10000);