Skip to content

Instantly share code, notes, and snippets.

@seki
Last active October 11, 2022 10:38
Show Gist options
  • Save seki/964ff441e41a4bef95ec1a532b0e2411 to your computer and use it in GitHub Desktop.
Save seki/964ff441e41a4bef95ec1a532b0e2411 to your computer and use it in GitHub Desktop.
epea ndir-07 reader
require 'serialport'
require 'json'
class EpeaNdir07
def initialize
@dev = "/dev/tty.usbserial-12210"
end
def get_ppm
sp = SerialPort.new(@dev, 115200)
while line = sp.gets
begin
ppm = JSON.parse(line)['CO2']
yield(ppm) if ppm && ppm > 400
rescue
p $!
end
end
ensure
sp.close if sp
end
end
if __FILE__ == $0
e = EpeaNdir07.new
e.get_ppm do |ppm|
puts ppm
if ppm < 500
pp Time.now
system("osascript reminder.scpt")
exit
end
end
end
tell application "Reminders"
set notification to make new reminder in list "notify"
set name of notification to "換気終了"
set body of notification to "換気できたよ"
set remind me date of notification to (current date) + (0.25 * minutes)
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment