Module: RaspberryPi

Defined in:
lib/thermal_sensor.rb,
lib/raspberry_pi.rb

Overview

ThermalSensor - Raspberry Pi internal SoC temperature sensor

Defined Under Namespace

Classes: ThermalSensor

Class Method Summary collapse

Class Method Details

.disk_space(mounted = '/', hash = false) ⇒ Object

Return used and free disk space in KB on a file system or on all (with ‘*’)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/raspberry_pi.rb', line 47

def self.disk_space(mounted='/', hash=false)
  disk_memory = []
  lines = `df -k`
  lines.split("\n").each do |line|
    disk_memory << line.chomp.split(" ")
  end
  disk_memory.shift # deleie 1st array with titles

  if mounted == '*'
    return hash ? self.matrix2hash(disk_memory) : disk_memory
  else
    disk_memory.each do |fs|
      if fs[-1] == mounted
        return hash ? self.list2hash(fs) : fs
      end
    end
  end
end

.hardware_infoObject

Return hardware info as a hash



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/raspberry_pi.rb', line 19

def self.hardware_info
  info = {"Model" => self.model_name}
  lines = ` pinout | grep ': '`
  lines << `cat /proc/cpuinfo | grep ': '`
  lines.split("\n").each do |line|
    key, value = line.split(':')
    key.strip!
    if key == 'processor'
      value = (value.to_i+1).to_s
      key = 'Cores'
    end
    key = 'CPU name' if key == 'model name'
    info[key] = value.strip
  end
  info
end

.host_ipObject

Return host ip-addresses as an Array



42
43
44
# File 'lib/raspberry_pi.rb', line 42

def self.host_ip
  `hostname -I`.chomp.split " "
end

.host_nameObject

Return host name as a string



37
38
39
# File 'lib/raspberry_pi.rb', line 37

def self.host_name
  `hostname`.chomp
end

.model_name(source = 'proc') ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/raspberry_pi.rb', line 7

def self.model_name(source='proc')
  info = if source == 'proc'
    `cat /proc/device-tree/model`
  elsif
    `pinout | grep -Eo "Pi Model[^|]+"`
  else
    'N/A'
  end
  info.strip
end