Log Arduino sensor data to the cloud using an Onion Omega

A bit of background

More than a year ago, I backed the Onion Omega project on Kickstarter. When I eventually received the devices, life got in the way and I didn't have time to play around them. I also didn't originally order an Expansion Dock, which provides the 3.3V needed to power the Onion Omega along with a serial interface though USB. This further complicated any attempts to play with the Omega.

However, I recently received an Omega 2+ along with an Expansion Dock from a friend as a gift. With the expansion dock, I could easily set up the Omega and start playing around with it. Yay! \:D/

Hydroponic tomatoes!

As a hobby, I grow vegetables hydroponically in a very controlled environment. On an Arduino Uno, I have a probe to measure the pH of the nutrient water, as well as a DHT11 sensor to measure temperature and humidity inside of the grow room. I could now use the Omega to log the data streamed from the Arduino to a server somewhere for graphing and remote monitoring.

Thought the serial port, the Arduino sends a simple space delimited string containing the temperature, humidity and pH every second:

11.00 26.00 5.89

I primarily use Ruby for writing software, so it was the first choice for writing software on the Omega. However, you're extremely limited when using Ruby on the Omega, which runs OpenWRT. Due to various limitations, you're not able to compile native Ruby extensions. This includes all gems that read from a serial port. A way around this was to simply read from the TTY device directly - /dev/ttyACM0 in this case. I log the data using wget every 60 seconds. I had a bit of issues getting the Ruby script to start on boot reliably, so I'm cycling the colour of the RGB led on the Expansion Board every second so I know the Ruby script is running.

colours = ['007FFF', 'ff0000', '00ff00']  
current_colour = 0

seconds = 59

loop do  
  current_colour += 1
  current_colour = 0 if current_colour == 3
  system "expled 0x#{colours[current_colour]}" # cycle LED colour

  sleep 1

  reading=File.open(ARGV[0]).readline.strip # /dev/ttyACM0

  # Sometimes the serial output from the Arduino is weird and doesn't result in the correct, three item array
  readings = reading.split(' ')
  next unless readings.size == 3

  seconds += 1

  if seconds == 60
    seconds = 1
    system "wget -q \"http://data.sparkfun.com/input/STREAM_ID?private_key=PRIVATE_KEY&humidity=#{readings[0]}&ph=#{readings[2]}&temp=#{readings[1]}\"

For logging the actual data, I used data.sparkfun.com. Initially I wanted to use Google Sheets, but since native gems won't compile on the Omega, I was left with no tools to do oAuth with the Google API, or to format the data in a way Google expects. Without these gems, it quickly becomes quite a bit of work to log data to Google Sheets.

After some Googling, I came across https://data.sparkfun.com/, a free service to capture IOT data. It's pretty slow and frequently times out, but it works well enough for now:

Data logging on data.sparkfun.com

It supports export to various formats, as well as integration with https://analog.io - a super basic service that graphs data from any Phant service:

analog.io stream data

It's still a bit flakey (the Ruby script sometimes exists and doesn't get restarted), but I have successfully boarded the IOT hype train! :D