How to set System.FriendlyName

HI All,

I use Kodi MusicRemote as my remote and I have a small inconvenience when using it with OSMC. The Server Conection only shows the IP address and not the System.FriendlyName.

On the OSMC boxes all I get is the IP address, but on the LibreElec boxes it returns the name.
The hostname command returns the correct name, guisettings.xml > services.devicename=the correct name.

Is there somewhere in OSMC that I can manually set the System.FriendlyName?

http://10.7.10.58:8080/jsonrpc?request=“jsonrpc”:“2.0”,“method”:“XBMC.GetInfoLabels”,“id”:1,“params”:{“labels”:[“System.FriendlyName”,%20"Network.IPAddress"]}}

It returns:

{“id”:1,“jsonrpc”:“2.0”,“result”:{“Network.IPAddress”:“10.7.10.58”,“System.FriendlyName”:“”}}

Thanks.

From Kodi’s source, we see:

///   \table_row3{   <b>`System.FriendlyName`</b>,
///                  \anchor System_FriendlyName
///                  _string_,
///     @return The Kodi instance name. 
///     @note It will auto append (%hostname%) in case
///     the device name was not changed. eg. "Kodi (htpc)"
///     <p>

SYSTEM_FRIENDLY_NAME only seems to be found in:

xbmc/GUIInfoManager.cpp
xbmc/guilib/guiinfo/SystemGUIInfo.cpp
xbmc/guilib/guiinfo/GUIInfoLabels.h

We have this patch for OSMC, to keep the Kodi device name in sync with the hostname:

From 7e0c2d40b6a24418740dab9f06bf39c6ba595f9f Mon Sep 17 00:00:00 2001
From: Sam Nazarko <email@samnazarko.co.uk>
Date: Sun, 20 Sep 2015 14:40:24 +0100
Subject: [PATCH] Ensure that Kodi's 'services.devicename' reflects
 /etc/hostname:

* Set the device name from the hostname at startup
* Ensure callback handles changes to this and updates /etc/hostname if changed in GUI

Do not worry about /etc/hosts as libnss-myhostname should handle this.

Signed-off-by: Sam Nazarko <email@samnazarko.co.uk>
---
 xbmc/Application.cpp                  |  1 +
 xbmc/guilib/guiinfo/SystemGUIInfo.cpp |  9 +++++++--
 xbmc/network/NetworkServices.cpp      | 20 +++++++++++++++++++-
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp
index 3bd24ef..ac1f4f5 100644
--- a/xbmc/Application.cpp
+++ b/xbmc/Application.cpp
@@ -542,6 +542,7 @@ bool CApplication::Create(const CAppParamParser &params)
     return false;
 
   CLog::Log(LOGINFO, "creating subdirectories");
+  CServiceBroker::GetSettingsComponent()->GetSettings()->SetString(CSettings::SETTING_SERVICES_DEVICENAME, hostname);
   const std::shared_ptr<CProfileManager> profileManager = m_pSettingsComponent->GetProfileManager();
   const std::shared_ptr<CSettings> settings = m_pSettingsComponent->GetSettings();
   CLog::Log(LOGINFO, "userdata folder: %s", CURL::GetRedacted(profileManager->GetProfileUserDataFolder()).c_str());
diff --git a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
index a27bda4..e76ed82 100644
--- a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
+++ b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
@@ -137,6 +137,7 @@ bool CSystemGUIInfo::InitCurrentItem(CFileItem *item)
 
 bool CSystemGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const
 {
+  std::string strLabel;
   switch (info.m_info)
   {
     ///////////////////////////////////////////////////////////////////////////////////////////////
@@ -277,8 +278,12 @@ bool CSystemGUIInfo::GetLabel(std::string& value, const CFileItem *item, int con
       value = g_langInfo.GetTemperatureUnitString();
       return true;
     case SYSTEM_FRIENDLY_NAME:
-      value = CSysInfo::GetDeviceName();
-      return true;
+    {
+       std::string hostname("osmc");
+       CServiceBroker::GetNetwork().GetHostName(hostname); 
+       strLabel = hostname.c_str();
+       return true;
+    }
     case SYSTEM_STEREOSCOPIC_MODE:
     {
       int iStereoMode = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOSCREEN_STEREOSCOPICMODE);
diff --git a/xbmc/network/NetworkServices.cpp b/xbmc/network/NetworkServices.cpp
index cbbac07..18faef5 100644
--- a/xbmc/network/NetworkServices.cpp
+++ b/xbmc/network/NetworkServices.cpp
@@ -131,7 +131,8 @@ CNetworkServices::CNetworkServices()
     CSettings::SETTING_SMB_WORKGROUP,
     CSettings::SETTING_SMB_MINPROTOCOL,
     CSettings::SETTING_SMB_MAXPROTOCOL,
-    CSettings::SETTING_SMB_LEGACYSECURITY
+    CSettings::SETTING_SMB_LEGACYSECURITY,
+    CSettings::SETTING_SERVICES_DEVICENAME
   };
   m_settings = CServiceBroker::GetSettingsComponent()->GetSettings();
   m_settings->GetSettingsManager()->RegisterCallback(this, settingSet);
@@ -448,6 +449,23 @@ void CNetworkServices::OnSettingChanged(std::shared_ptr<const CSetting> setting)
       CApplicationMessenger::GetInstance().PostMsg(TMSG_RESTARTAPP);
     }
   }
+
+  if (settingId == "services.devicename")
+  {
+     std::string newHostName = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString("services.devicename"); 
+     FILE *fp;
+     fp = fopen("/tmp/hostname", "w");
+     if (fp)
+     {
+         fprintf(fp, "%s", newHostName.c_str());
+         fclose(fp);
+     }
+     else
+         return;
+     system("/usr/bin/sudo /bin/mv /tmp/hostname /etc/hostname");
+     system("/usr/bin/sudo /bin/hostname -F /etc/hostname");
+  }
+
 }
 
 bool CNetworkServices::OnSettingUpdate(std::shared_ptr<CSetting> setting, const char *oldSettingId, const TiXmlNode *oldSettingNode)
-- 
2.7.4

Sam

HI Sam,

Thanks for the response, however it’s too complex for me.

It looks like the OSMC patch removed the Kodi code for GetDeviceName() so we no longer return ‘value’ so the GetInfoLabels request returns a blank. Is that correct?

Can we not return the value = CSysInfo::GetDeviceName(); in your code too (says the guy who opened the response with “too complex with me” - just trying to understand :smiley:)

Thanks

The issue is that value isn’t being assigned anymore.
I’ll sort this out.

Sorry for the late reply in getting this solved.
This should now be solved in the June update.

No worries, I confirm that the host name now shows up on the mobile app

Thanks for fixing

1 Like

Thanks for confirming.