skip crearte/device logic for now
This commit is contained in:
parent
a2cffbc5fc
commit
94c2b90e4a
@ -45,6 +45,10 @@ AWSConnector::~AWSConnector()
|
|||||||
|
|
||||||
void AWSConnector::connect2AWS(const QString &endpoint, const QString &clientId, const QString &clientName, const QString &caFile, const QString &clientCertFile, const QString &clientPrivKeyFile)
|
void AWSConnector::connect2AWS(const QString &endpoint, const QString &clientId, const QString &clientName, const QString &caFile, const QString &clientCertFile, const QString &clientPrivKeyFile)
|
||||||
{
|
{
|
||||||
|
m_currentEndpoint = endpoint;
|
||||||
|
m_caFile = caFile;
|
||||||
|
m_clientCertFile = clientCertFile;
|
||||||
|
m_clientPrivKeyFile = clientPrivKeyFile;
|
||||||
m_reconnect = true;
|
m_reconnect = true;
|
||||||
m_networkConnection = std::shared_ptr<MbedTLSConnection>(new MbedTLSConnection(
|
m_networkConnection = std::shared_ptr<MbedTLSConnection>(new MbedTLSConnection(
|
||||||
endpoint.toStdString(),
|
endpoint.toStdString(),
|
||||||
@ -61,8 +65,20 @@ void AWSConnector::connect2AWS(const QString &endpoint, const QString &clientId,
|
|||||||
m_clientId = clientId;
|
m_clientId = clientId;
|
||||||
m_clientName = clientName;
|
m_clientName = clientName;
|
||||||
|
|
||||||
qCDebug(dcAWS()) << "Connecting to AWS with ID:" << m_clientId << "endpoint:" << endpoint;
|
m_client->SetAutoReconnectEnabled(true);
|
||||||
doConnect();
|
m_client->SetMaxReconnectBackoffTimeout(std::chrono::seconds(10));
|
||||||
|
|
||||||
|
qCDebug(dcAWS()) << "Connecting to AWS with ID:" << m_clientId << "endpoint:" << endpoint << m_client->GetMinReconnectBackoffTimeout().count() << (quint32)m_client->GetMaxReconnectBackoffTimeout().count();
|
||||||
|
m_connectingFuture = QtConcurrent::run([&]() {
|
||||||
|
ResponseCode rc = m_client->Connect(std::chrono::milliseconds(30000), true, mqtt::Version::MQTT_3_1_1, std::chrono::seconds(60), Utf8String::Create(m_clientId.toStdString()), nullptr, nullptr, nullptr);
|
||||||
|
if (rc == ResponseCode::MQTT_CONNACK_CONNECTION_ACCEPTED) {
|
||||||
|
emit connected();
|
||||||
|
} else {
|
||||||
|
qCWarning(dcAWS) << "Error connecting to AWS. Response code:" << QString::fromStdString(ResponseHelper::ToString(rc));
|
||||||
|
m_client.reset();
|
||||||
|
m_networkConnection.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DisconnectCallbackContextData::~DisconnectCallbackContextData() {}
|
DisconnectCallbackContextData::~DisconnectCallbackContextData() {}
|
||||||
@ -114,31 +130,22 @@ quint16 AWSConnector::publish(const QString &topic, const QVariantMap &message)
|
|||||||
return packetId;
|
return packetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWSConnector::doConnect()
|
|
||||||
{
|
|
||||||
qCDebug(dcAWS()) << "(re)connecting...";
|
|
||||||
m_connectingFuture = QtConcurrent::run([&]() {
|
|
||||||
ResponseCode rc = m_client->Connect(std::chrono::milliseconds(30000), true, mqtt::Version::MQTT_3_1_1, std::chrono::seconds(60), Utf8String::Create(m_clientId.toStdString()), nullptr, nullptr, nullptr);
|
|
||||||
if (rc == ResponseCode::MQTT_CONNACK_CONNECTION_ACCEPTED) {
|
|
||||||
emit connected();
|
|
||||||
} else {
|
|
||||||
qCWarning(dcAWS) << "Error connecting to AWS. Response code:" << QString::fromStdString(ResponseHelper::ToString(rc));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void AWSConnector::onConnected()
|
void AWSConnector::onConnected()
|
||||||
{
|
{
|
||||||
qCDebug(dcAWS()) << "AWS connected";
|
qCDebug(dcAWS()) << "AWS connected";
|
||||||
m_client->SetAutoReconnectEnabled(true);
|
m_client->SetAutoReconnectEnabled(true);
|
||||||
registerDevice();
|
registerDevice();
|
||||||
|
|
||||||
|
// TODO: remove this again. just using this for testing now to skip the registerDevice step
|
||||||
|
retrievePairedDeviceInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWSConnector::onDisconnected()
|
void AWSConnector::onDisconnected()
|
||||||
{
|
{
|
||||||
qCDebug(dcAWS()) << "AWS disconnected.";
|
|
||||||
if (m_reconnect) {
|
if (m_reconnect) {
|
||||||
QTimer::singleShot(10000, this, &AWSConnector::doConnect);
|
m_client->Disconnect(std::chrono::milliseconds(1000));
|
||||||
|
// m_networkConnection->Connect();
|
||||||
|
connect2AWS(m_currentEndpoint, m_clientId, m_clientName, m_caFile, m_clientCertFile, m_clientPrivKeyFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,8 +309,11 @@ ResponseCode AWSConnector::onSubscriptionReceivedCallback(util::String topic_nam
|
|||||||
|
|
||||||
ResponseCode AWSConnector::onDisconnectedCallback(util::String mqtt_client_id, std::shared_ptr<DisconnectCallbackContextData> p_app_handler_data)
|
ResponseCode AWSConnector::onDisconnectedCallback(util::String mqtt_client_id, std::shared_ptr<DisconnectCallbackContextData> p_app_handler_data)
|
||||||
{
|
{
|
||||||
qCDebug(dcAWS()) << "disconnected" << QString::fromStdString(mqtt_client_id) << p_app_handler_data.get();
|
Q_UNUSED(p_app_handler_data)
|
||||||
// AWSConnector* connector = dynamic_cast<AWSConnector*>(p_app_handler_data.get());
|
|
||||||
// emit connector->disconnected();
|
AWSConnector* connector = dynamic_cast<AWSConnector*>(p_app_handler_data.get());
|
||||||
|
qWarning() << connector->m_client->IsAutoReconnectEnabled();
|
||||||
|
qCDebug(dcAWS()) << "disconnected" << QString::fromStdString(mqtt_client_id) << connector << p_app_handler_data.get();
|
||||||
|
emit connector->disconnected();
|
||||||
return ResponseCode::SUCCESS;
|
return ResponseCode::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,6 @@ signals:
|
|||||||
void webRtcHandshakeMessageReceived(const QString &transactionId, const QVariantMap &data);
|
void webRtcHandshakeMessageReceived(const QString &transactionId, const QVariantMap &data);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void doConnect();
|
|
||||||
void onConnected();
|
void onConnected();
|
||||||
void onDisconnected();
|
void onDisconnected();
|
||||||
void retrievePairedDeviceInfo();
|
void retrievePairedDeviceInfo();
|
||||||
@ -71,6 +70,10 @@ private:
|
|||||||
std::shared_ptr<awsiotsdk::network::MbedTLSConnection> m_networkConnection;
|
std::shared_ptr<awsiotsdk::network::MbedTLSConnection> m_networkConnection;
|
||||||
std::shared_ptr<awsiotsdk::MqttClient> m_client;
|
std::shared_ptr<awsiotsdk::MqttClient> m_client;
|
||||||
bool m_reconnect = false;
|
bool m_reconnect = false;
|
||||||
|
QString m_currentEndpoint;
|
||||||
|
QString m_caFile;
|
||||||
|
QString m_clientCertFile;
|
||||||
|
QString m_clientPrivKeyFile;
|
||||||
|
|
||||||
QString m_clientId;
|
QString m_clientId;
|
||||||
QString m_clientName;
|
QString m_clientName;
|
||||||
|
|||||||
@ -122,7 +122,6 @@ void CloudManager::connect2aws()
|
|||||||
|
|
||||||
void CloudManager::onlineStateChanged()
|
void CloudManager::onlineStateChanged()
|
||||||
{
|
{
|
||||||
qWarning() << "online state changed" << m_networkManager->state();
|
|
||||||
if (m_networkManager->state() == NetworkManager::NetworkManagerStateConnectedGlobal) {
|
if (m_networkManager->state() == NetworkManager::NetworkManagerStateConnectedGlobal) {
|
||||||
if (m_enabled && !m_awsConnector->isConnected()) {
|
if (m_enabled && !m_awsConnector->isConnected()) {
|
||||||
connect2aws();
|
connect2aws();
|
||||||
|
|||||||
Reference in New Issue
Block a user