alow using hostnames for the manual connection and improve connection a bit

This commit is contained in:
Michael Zanetti 2018-07-02 17:55:09 +02:00
parent 18d1c3c8cd
commit 24aca10d09
6 changed files with 36 additions and 18 deletions

View File

@ -37,6 +37,9 @@ QList<Device *> Devices::devices()
Device *Devices::get(int index) const
{
if (index < 0 || index >= m_devices.count()) {
return nullptr;
}
return m_devices.at(index);
}

View File

@ -244,7 +244,7 @@ void JsonRpcClient::sendRequest(const QVariantMap &request)
QVariantMap newRequest = request;
newRequest.insert("token", m_token);
// qDebug() << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(newRequest).toJson());
m_connection->sendData(QJsonDocument::fromVariant(newRequest).toJson());
m_connection->sendData(QJsonDocument::fromVariant(newRequest).toJson(QJsonDocument::Compact) + "\n");
}
void JsonRpcClient::onInterfaceConnectedChanged(bool connected)
@ -259,6 +259,7 @@ void JsonRpcClient::onInterfaceConnectedChanged(bool connected)
} else {
QVariantMap request;
request.insert("id", 0);
qDebug() << "Connected. Starting JSONRPC Handshake";
request.insert("method", "JSONRPC.Hello");
sendRequest(request);
}
@ -275,7 +276,7 @@ void JsonRpcClient::dataReceived(const QByteArray &data)
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(m_receiveBuffer.left(splitIndex), &error);
if (error.error != QJsonParseError::NoError) {
// qWarning() << "Could not parse json data from nymea" << data << error.errorString();
// qWarning() << "Could not parse json data from nymea" << m_receiveBuffer.left(splitIndex) << error.errorString();
return;
}
// qDebug() << "received response" << m_receiveBuffer.left(splitIndex);
@ -286,7 +287,6 @@ void JsonRpcClient::dataReceived(const QByteArray &data)
QVariantMap dataMap = jsonDoc.toVariant().toMap();
// Check if this is the initial handshake
if (dataMap.value("id").toInt() == 0 && dataMap.contains("params") && !dataMap.contains("notification")) {
dataMap = dataMap.value("params").toMap();

View File

@ -42,6 +42,9 @@ int Plugins::count() const
Plugin *Plugins::get(int index) const
{
if (index < 0 || index >= m_plugins.count()) {
return nullptr;
}
return m_plugins.at(index);
}

View File

@ -20,6 +20,12 @@ Page {
}
}
NymeaDiscovery {
id: discovery
objectName: "discovery"
discovering: pageStack.currentItem.objectName === "discoveryPage"
}
Connections {
target: Engine.connection
onVerifyConnectionCertificate: {
@ -37,7 +43,19 @@ Page {
case "SslHandshakeFailedError":
// silently ignore. They'll be handled by the SSL logic
return;
case "HostNotFoundError":
errorMessage = qsTr("The %1 box could not be found on this address. Please make sure you entered the address correctly and that the box is powered on.").arg(app.systemName);
break;
case "NetworkError":
errorMessage = qsTr("It seems you're not connected to the network.");
break;
case "RemoteHostClosedError":
errorMessage = qsTr("The %1 box has closed the connection. This probably means it has been turned off or restarted.").arg(app.systemName);
break;
default:
errorMessage = qsTr("Un unknown error happened. We're very sorry for that. (Error code: %1)").arg(error);
}
print("opening ErrorDialog with message:", errorMessage, error)
var comp = Qt.createComponent(Qt.resolvedUrl("components/ErrorDialog.qml"))
var popup = comp.createObject(app, {text: errorMessage})
popup.open()
@ -45,6 +63,12 @@ Page {
pageStack.pop(root)
pageStack.push(discoveryPage)
}
onConnectedChanged: {
if (!connected) {
pageStack.pop(root)
pageStack.push(discoveryPage)
}
}
}
Component {
@ -89,7 +113,7 @@ Page {
text: qsTr("Demo mode")
onTriggered: {
pageStack.push(connectingPage)
Engine.connection.connect("nymea://83.169.2.242:2222")
Engine.connection.connect("nymea://nymea.nymea.io:2222")
}
}
@ -258,7 +282,7 @@ Page {
text: qsTr("Demo mode (online)")
onClicked: {
pageStack.push(connectingPage)
Engine.connection.connect("nymea://83.169.2.242:2222")
Engine.connection.connect("nymea://nymea.nymea.io:2222")
}
}
@ -315,7 +339,6 @@ Page {
objectName: "addressTextInput"
Layout.fillWidth: true
placeholderText: "127.0.0.1"
validator: RegExpValidator { regExp: /^((?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.){0,3}(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$/ }
}
Label { text: qsTr("Port:") }

View File

@ -36,7 +36,6 @@ ApplicationWindow {
Component.onCompleted: {
pageStack.push(Qt.resolvedUrl("ConnectPage.qml"))
discovery.discovering = true
}
Connections {
@ -70,11 +69,8 @@ ApplicationWindow {
function init() {
print("calling init. Auth required:", Engine.jsonRpcClient.authenticationRequired, "initial setup required:", Engine.jsonRpcClient.initialSetupRequired, "jsonrpc connected:", Engine.jsonRpcClient.connected)
pageStack.clear()
discovery.discovering = false;
if (!Engine.connection.connected) {
pageStack.push(Qt.resolvedUrl("ConnectPage.qml"))
print("starting discovery")
discovery.discovering = true;
return;
}
@ -99,8 +95,6 @@ ApplicationWindow {
pageStack.push(Qt.resolvedUrl("MainPage.qml"))
} else {
pageStack.push(Qt.resolvedUrl("ConnectPage.qml"))
print("starting discovery")
discovery.discovering = true;
}
}
@ -129,11 +123,6 @@ ApplicationWindow {
}
}
NymeaDiscovery {
id: discovery
objectName: "discovery"
}
Connections {
target: Qt.application
enabled: Engine.jsonRpcClient.connected && settings.returnToHome

View File

@ -1,7 +1,7 @@
TEMPLATE = app
TARGET = meatestrunner
include(../../nymea-app.pri)
include(../../config.pri)
QT += core gui testlib bluetooth websockets
CONFIG += qmltestcase