Add device serial number to system api

pull/408/head
Michael Zanetti 2021-03-17 19:26:54 +01:00
parent 96ae3cd01a
commit fb90efb1de
7 changed files with 44 additions and 3 deletions

2
debian/control vendored
View File

@ -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

View File

@ -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 &params) const
return createReply(returns);
}
JsonReply *SystemHandler::GetSystemInfo(const QVariantMap &params) const
{
Q_UNUSED(params)
QVariantMap returns;
QString deviceSerial = m_platform->systemController()->deviceSerialNumber();
returns.insert("deviceSerialNumber", deviceSerial);
return createReply(returns);
}
void SystemHandler::onCapabilitiesChanged()
{
QVariantMap caps;

View File

@ -68,6 +68,8 @@ public:
Q_INVOKABLE JsonReply *SetTime(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *GetTimeZones(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *GetSystemInfo(const QVariantMap &params) const;
signals:
void CapabilitiesChanged(const QVariantMap &params);

View File

@ -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;
}

View File

@ -53,6 +53,8 @@ public:
virtual bool setAutomaticTime(bool automaticTime);
virtual bool setTimeZone(const QTimeZone &timeZone);
virtual QString deviceSerialNumber() const;
signals:
void availableChanged();

View File

@ -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

View File

@ -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": {