Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Pi_Piper able to read DS18B20 heat sensor ? #67

Closed
Damaotimlin opened this issue Mar 8, 2016 · 4 comments
Closed

Is Pi_Piper able to read DS18B20 heat sensor ? #67

Damaotimlin opened this issue Mar 8, 2016 · 4 comments

Comments

@Damaotimlin
Copy link

Hi Folks,

Pi_piper is great !

I'm wondering is Pi_Piper able to read DS18B20 heat sensor ? If yes, how to do it ?
If not, any recommendation gem or solutions ?
My goal is to push the temperature data to Dashing dashboard.

My code works fine run in terminal.

def gettemp(id)

  filename = 'w1_slave'
  filepath = File.new("/sys/bus/w1/devices/#{id}/#{filename}", "w").path
  # “File” belongs to IO class, which contain I/O stream. http://ruby-doc.org/core-2.0.0/IO.html

  File.open(filepath) { |f|
    lines_arr = f.read.lines.to_a
    lines_arr.shift(1) 
    temp_arr = lines_arr.to_s.partition(/.t=/) # saperate the ["xx xx xx xx xx t=", "34.xxxx"]  
    @temp = temp_arr.last.to_f/1000
  }
  return @temp
end

# Use for startup the file
if __FILE__ == $0 then
  puts "Temp : #{gettemp('28-031581efbaff'})
end

pi@raspberry:~/dashing_project$: sudo ruby read_soil_temp.rb
Temp : 25.5

Below is I'm trying to read the sensor in Dashingm but it seems not able to fire the FILE correctly.

~/dashing_project/jobs/sample.rb

# For reading temp/humidity sensor DHT11 gem
require 'dht-sensor-ffi'
# For reading soil remp sensor        
def get_soil_temp(id)
    filename = 'w1_slave'
    filepath = File.new("/sys/bus/w1/devices/#{id}/#{filename}", "w").path
    File.open(filepath) { |f|
        lines_arr = f.read.lines.to_a 
        lines_arr.shift(1) 
        temp_arr = lines_arr.to_s.partition(/.t=/) 
        @temp = temp_arr.last.to_f/1000
    }
    return @temp
end
soil_temp_sensor_id = '28-031581efbaff'

current_air_temp = 0
current_air_humid = 0
current_soil_temp = 0

SCHEDULER.every '5s' do
  last_air_temp = current_air_temp
  last_air_humid = current_air_humid
  sensor_val = DhtSensor.read(17, 11)
  current_air_temp = sensor_val.temp
  current_air_humid = sensor_val.humidity

  if __FILE__ == $0 then
    current_soil_temp = get_soil_temp(soil_temp_sensor_id)
  end

  send_event('air_temp', { current: current_air_temp, last: last_air_temp })
  send_event('air_humid', { current: current_air_humid, last: last_air_humid })
  send_event('soil_temp',  value: current_soil_temp)
end

Please advice, thank you in advance !

@elmatou
Copy link
Contributor

elmatou commented Mar 8, 2016

I wrote a gem for one wire devices. it is backed by the kernel driver (/sys/bus/w1/devices stuff)

I need to polish it and publish it. if you can wait until sunday, you could use it.

@elmatou
Copy link
Contributor

elmatou commented Mar 8, 2016

take a look at https://github.com/asapp/one_wire
we can discuss on it later.

@Damaotimlin
Copy link
Author

Hey @elmatou
Great, thank you! I could wait and just let me know if you need some hand. Actually, I'm not good enough to do you some help, but I can test it after Sunday!

Looking forward to your Gem!!

@elmatou
Copy link
Contributor

elmatou commented Mar 8, 2016

You can check it now it should work for thermometer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants