Project

humble_rpi

0.0
No commit activity in last 3 years
No release in over 3 years
Controls components wired in through the Raspberry Pi's GPIO pins. see the Humble_rpi plugins.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.4.3, ~> 0.4
>= 0.1.0, ~> 0.1
 Project Readme

Introducing the Humble RPi gem

Example

require 'humble_rpi'

f = HumbleRPi.new device_name: 'fortina', led_pins: [17], sps_address: '192.168.4.170', motion_pin: '7'
rpi = f
blk = lambda do |msg,type|

  puts 'message received'
  #@logger.debug "#{topic}: #{raw_message}"

  topic, raw_message = msg.split(/\s*:\s*/,2)
  r = raw_message.match(/(\d+)\s*(on|off|blink)\s*([\d\.]+)?/)
  puts 'r : ' + r.inspect

  if r then
    index, state, seconds = r.captures
  elsif raw_message[/mpd|audio/] then
    
    h = {'mpd play' => :on, 'mpd stop' => :off, 
         'audio on' => :on, 'audio off' => :off}
    index, state = 0, h[raw_message]
    
  end
  #=begin                    
  # seconds should be nil unless state == blink
  if seconds then            
    rpi.led[index.to_i].blink seconds.to_f
  else
    rpi.led[index.to_i].send(state.to_sym)
  end
  #=end          

end

f.led_listener &blk
sleep 3 # wait for the client to connect to the SimplePubSub message broker
f.motion_detect

Messages are sent every minute from the Raspberry Pi (Rpi) if motion is detected. Indicator LEDs are changed on the RPi if a message is received matching the subscribed topic (e.g. fortina_led). If a message received by the RPi contains the keyword 'audio' or 'mpd play' it will set the 1st LED to on.

Resources

humblerpi gem motion simplepubsub messaging