Skip to content

Commit 3e56512

Browse files
authored
Update ISP-RPi-mqtt-daemon.py
Added this pull request ironsheep#149
1 parent 77255a6 commit 3e56512

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ISP-RPi-mqtt-daemon.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,9 @@ def isPeriodTimerRunning():
15911591
K_RPI_DRV_NFS = "device-nfs"
15921592
K_RPI_DVC_IP = "ip"
15931593
K_RPI_DVC_PATH = "dvc"
1594+
# new block devices dictionary
1595+
K_RPI_BLK_DEVICES = "block_devices"
1596+
K_RPI_BLK_DEV_TEMP = "temperature_c"
15941597
# new memory dictionary
15951598
K_RPI_MEMORY = "memory"
15961599
K_RPI_MEM_TOTAL = "size_mb"
@@ -1647,6 +1650,10 @@ def send_status(timestamp, nothing):
16471650

16481651
rpiData[K_RPI_NETWORK] = getNetworkDictionary()
16491652

1653+
rpiBlockDevices = getBlockDevicesDictionary()
1654+
if len(rpiBlockDevices) > 0:
1655+
rpiData[K_RPI_BLK_DEVICES] = rpiBlockDevices
1656+
16501657
rpiDrives = getDrivesDictionary()
16511658
if len(rpiDrives) > 0:
16521659
rpiData[K_RPI_DRIVES] = rpiDrives
@@ -1685,10 +1692,25 @@ def forceSingleDigit(temperature):
16851692
tempInterp = '{:.1f}'.format(temperature)
16861693
return float(tempInterp)
16871694

1695+
def getBlockDevicesDictionary():
1696+
rpiDevices = OrderedDict()
1697+
1698+
smartctlHelper = os.path.join(os.path.dirname(__file__), 'smartctl-helper')
1699+
stdout, stderr, returncode = invoke_shell_cmd("sudo " + smartctlHelper)
1700+
if returncode != 0:
1701+
print_line('Could not query SMART data: {}'.format(stderr), warning=True)
1702+
return rpiDevices
1703+
1704+
for device in stdout.decode('utf-8').splitlines():
1705+
[ name, temp ] = device.split(':')
1706+
if len(temp) > 0:
1707+
rpiDevices[name] = { K_RPI_BLK_DEV_TEMP: float(temp) }
1708+
return rpiDevices
16881709

16891710
def getDrivesDictionary():
16901711
global rpi_filesystem
16911712
rpiDrives = OrderedDict()
1713+
16921714

16931715
# tuple { total blocks, used%, mountPoint, device }
16941716
for driveTuple in rpi_filesystem:

0 commit comments

Comments
 (0)