Skip to content

Instantly share code, notes, and snippets.

@markjlorenz
Last active January 3, 2016 07:38
Show Gist options
  • Save markjlorenz/8430252 to your computer and use it in GitHub Desktop.
Save markjlorenz/8430252 to your computer and use it in GitHub Desktop.
Kegmotron Lunch and Learn Outline

Kegmotron Lunch and Learn

What's a keg motron?

  • A wireless scale that the keg sits on.
  • Measures the weight of the beer.
  • Not overly accurate.

Demo

  • devmotron is there beer?
  • charts

Pictures

Outside

Inside

FSR Closeup

Xbee Closeup

How Does it fit togeather?

      +
      |=~
    __|___
   { keg  }
   {______}
   {      }
   {______}
  ^~~^
  (fsr)
   |
   |
   ------\
   | xbee ] ~~UDP~~> +xbee_hex.rb+
   ------/                |
                          V
                +campfire_notifier.rb+
                   └- ~~HTTP~~> +hubot-kegmotron.coffee+ -> campfire
                   |
                   └- keg-log.dat
                       |
                       V
                  +keg-log.ru+

Electronics 101.

   1kΩ resistor
      |       fsr (variable)
      |       |
     ^^^^   ^~~~^
     |  \  |    |
  (+)║    \║    ║(gnd)
     ------------\
     |1    4    9 \
     |   (ADC)     ]
     |xbee        /
     ------------/
  • pin 1 is always 3.3v
  • pin 9 is always 0v
  • pin 4 voltage is the ratio of 1kΩ to the fsr resistance

Show some code you are proud of.

Show some code you hate.

Why I hate Ruby (Appendix 1):

  • Strings are not real IO, do not use them as buffers.

    rd, wr  = IO.pipe
    spawn "./xbee-hex.rb -p -c", out: wr
    
    puts "[Setting up Xbee Read Pipe]"
    rd.each_line do |status_update|
      # do something each time there's a \n on stdout
    end
    

    Ok, Take a file and turn it into stdin. Usefull when you want to give the file a generic name inside the program (this_plotter):

    #!/usr/bin/env gnuplot
    set term dumb
    plot "/dev/stdin"

    usage:

    ./this_plotter < file_of_the_moment.dat

    Now, do it in Ruby:

    spawn "this_plotter", out: in_memory_buffer, in: File.open("file_of_the_moment.dat")
    puts in_memory_buffer
    # No such object exists that can be used as `in_memory_buffer`
    # Why can I not use a string, if strings are ruby's buffers?
    # Why is there no IO::Buffer?
    # Why is StringIO not an IO!?

    Maybe a different way?

    require 'open3'
    stdout, _ = Open3.capture2 "this_plotter", stdin_data: File.read("file_of_the_moment.dat")

    This is not great, we have to read the entire file!

    ~ Maybe that makes sense spawn is non-blocking capture2 is blocking ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment