Compare commits

..

2 commits

Author SHA1 Message Date
Ansraer
1d738f3c3c
Merge 201b13a20a into 0d8a8daddd 2024-08-20 02:30:25 -04:00
Nicolas Mailloux
0d8a8daddd Telemetry: improvements 2024-08-18 17:45:42 -04:00

View file

@ -33,9 +33,7 @@ QJsonObject Telemetry::collectDeviceInformation() {
bool Telemetry::sendDeviceInformation(QJsonObject data) { bool Telemetry::sendDeviceInformation(QJsonObject data) {
log("Telemetry data to be sent to server: " + QJsonDocument(data).toJson(QJsonDocument::Compact), className); log("Telemetry data to be sent to server: " + QJsonDocument(data).toJson(QJsonDocument::Compact), className);
// NOTE: This URL *will* change in the future QNetworkRequest request(QUrl("http://23.163.0.39:4317/"));
// TODO: Add error-handling
QNetworkRequest request(QUrl("http://192.168.3.1:8080/"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QNetworkAccessManager nam; QNetworkAccessManager nam;
@ -45,8 +43,14 @@ bool Telemetry::sendDeviceInformation(QJsonObject data) {
} }
QByteArray responseData = reply->readAll(); QByteArray responseData = reply->readAll();
reply->deleteLater(); reply->deleteLater();
QString responseDataQstring = QString(responseData);
return true; log("Telemetry server's response data was: '" + responseDataQstring + "'", className);
if(responseDataQstring != "Data received successfully") {
return false;
}
else {
return true;
}
} }
void Telemetry::telemetrySlot() { void Telemetry::telemetrySlot() {
@ -54,6 +58,9 @@ void Telemetry::telemetrySlot() {
if(sendDeviceInformation(data)) { if(sendDeviceInformation(data)) {
writeFile("/mnt/onboard/.adds/inkbox/.config/24-telemetry/asked", "true"); writeFile("/mnt/onboard/.adds/inkbox/.config/24-telemetry/asked", "true");
writeFile("/mnt/onboard/.adds/inkbox/.config/24-telemetry/enabled", "true"); writeFile("/mnt/onboard/.adds/inkbox/.config/24-telemetry/enabled", "true");
showToast("Data successfully sent\nThank you!"); showToast("Data sent successfully\nThank you!");
}
else {
showToast("Error while sending data");
} }
} }