diff --git a/debian/control b/debian/control index 0e33315e..1655d5d9 100644 --- a/debian/control +++ b/debian/control @@ -142,7 +142,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, Provides: nymea-update-plugin-api-1, nymea-zeroconf-plugin-api-1, - nymea-system-plugin-api-2 + nymea-system-plugin-api-3 Description: An open source IoT server - core library The nymea daemon is a plugin based IoT (Internet of Things) server. The server works like a translator for devices, things and services and diff --git a/libnymea-core/jsonrpc/systemhandler.cpp b/libnymea-core/jsonrpc/systemhandler.cpp index 86a4e4e2..a5dfbdd4 100644 --- a/libnymea-core/jsonrpc/systemhandler.cpp +++ b/libnymea-core/jsonrpc/systemhandler.cpp @@ -168,6 +168,11 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent): returns.insert("timeZones", enumValueName(StringList)); registerMethod("GetTimeZones", description, params, returns); + params.clear(); returns.clear(); + description = "Returns information about the system nymea is running on."; + returns.insert("deviceSerialNumber", enumValueName(String)); + registerMethod("GetSystemInfo", description, params, returns); + // Notifications params.clear(); description = "Emitted whenever the system capabilities change."; @@ -446,6 +451,15 @@ JsonReply *SystemHandler::GetTimeZones(const QVariantMap ¶ms) const return createReply(returns); } +JsonReply *SystemHandler::GetSystemInfo(const QVariantMap ¶ms) const +{ + Q_UNUSED(params) + QVariantMap returns; + QString deviceSerial = m_platform->systemController()->deviceSerialNumber(); + returns.insert("deviceSerialNumber", deviceSerial); + return createReply(returns); +} + void SystemHandler::onCapabilitiesChanged() { QVariantMap caps; diff --git a/libnymea-core/jsonrpc/systemhandler.h b/libnymea-core/jsonrpc/systemhandler.h index ee8e2043..ee1e17ae 100644 --- a/libnymea-core/jsonrpc/systemhandler.h +++ b/libnymea-core/jsonrpc/systemhandler.h @@ -68,6 +68,8 @@ public: Q_INVOKABLE JsonReply *SetTime(const QVariantMap ¶ms) const; Q_INVOKABLE JsonReply *GetTimeZones(const QVariantMap ¶ms) const; + Q_INVOKABLE JsonReply *GetSystemInfo(const QVariantMap ¶ms) const; + signals: void CapabilitiesChanged(const QVariantMap ¶ms); diff --git a/libnymea/platform/platformsystemcontroller.cpp b/libnymea/platform/platformsystemcontroller.cpp index 2666ff3e..2c75e216 100644 --- a/libnymea/platform/platformsystemcontroller.cpp +++ b/libnymea/platform/platformsystemcontroller.cpp @@ -92,3 +92,18 @@ bool PlatformSystemController::setTimeZone(const QTimeZone &timeZone) qCWarning(dcPlatform()) << "setTimeZone not implemented in platform plugin"; return false; } + +QString PlatformSystemController::deviceSerialNumber() const +{ + // Sadly there is no real standardized way to read the device's serial number, especially when it comes to ARM platforms. + // Because of this, even the most common platforms (e.g. systemd, all standard linux) differ when it comes to this. + // In order to not being forced to write a new backend plugin just for this serial number, one can also set this by + // using the DEVICE_SERIAL environment variable. + QByteArray serial; + if (qEnvironmentVariableIsSet("DEVICE_SERIAL")) { + serial = qgetenv("DEVICE_SERIAL"); + } else { + qCWarning(dcPlatform()) << "Platform plugin does not implement deviceSerialNumber and DEVICE_SERIAL is not set. Cannot determine device serial number."; + } + return serial; +} diff --git a/libnymea/platform/platformsystemcontroller.h b/libnymea/platform/platformsystemcontroller.h index 9206d475..3f370ae5 100644 --- a/libnymea/platform/platformsystemcontroller.h +++ b/libnymea/platform/platformsystemcontroller.h @@ -53,6 +53,8 @@ public: virtual bool setAutomaticTime(bool automaticTime); virtual bool setTimeZone(const QTimeZone &timeZone); + virtual QString deviceSerialNumber() const; + signals: void availableChanged(); diff --git a/nymea.pro b/nymea.pro index fcf3eea8..f51820af 100644 --- a/nymea.pro +++ b/nymea.pro @@ -5,7 +5,7 @@ NYMEA_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p" # define protocol versions JSON_PROTOCOL_VERSION_MAJOR=5 -JSON_PROTOCOL_VERSION_MINOR=4 +JSON_PROTOCOL_VERSION_MINOR=5 JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}" LIBNYMEA_API_VERSION_MAJOR=7 LIBNYMEA_API_VERSION_MINOR=0 diff --git a/tests/auto/api.json b/tests/auto/api.json index 1c5f22d6..e1fe8192 100644 --- a/tests/auto/api.json +++ b/tests/auto/api.json @@ -1,4 +1,4 @@ -5.4 +5.5 { "enums": { "BasicType": [ @@ -1783,6 +1783,14 @@ "repositories": "$ref:Repositories" } }, + "System.GetSystemInfo": { + "description": "Returns information about the system nymea is running on.", + "params": { + }, + "returns": { + "deviceSerialNumber": "String" + } + }, "System.GetTime": { "description": "Get the system time and configuraton. The \"time\" and \"timeZone\" properties give the current server time and time zone. \"automaticTimeAvailable\" indicates whether this system supports automatically setting the clock (e.g. using NTP). \"automaticTime\" will be true if the system is configured to automatically update the clock.", "params": {