Hi,
I am looking for some help on getting a programming language to read the serial port.
Desired end result:
A deamon that fills a DB with key->value pairs from the serial port.
background:
I am using a number of Arduino based Jeenodes to power my home automation (heating system, sprinklers, wind turbine, etc)
I would like to do analysis on what's happening to improve.
I started with a pc (ubuntu linux) based setup which I would the like to replicate on my Linksys WRT160NL-EZ.
First try: php, not really suited to grab every relevant serial message, can just do polling. I have seen some interfaces with C programs but that doesn't feel right.
Then I looked at Ruby, which worked very simple on the PC:
require "rubygems"
require "serialport"
require "sqlite3"
# Open a database
db = SQLite3::Database.new "test.db"
# Create a database
#rows = db.execute <<-SQL
# create table readings (
# id varchar(30),
# val int
# );
#SQL
#params for serial port
port_str = "/dev/ttyUSB0" #may be different for you
baud_rate = 57600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new("/dev/ttyUSB1", 57600, data_bits, stop_bits, parity)
#wait for entire byte to come in
sp.read_timeout = 0
puts "print lines"
p Time.now.strftime("%F %T")
# recieve part
while true do
line = sp.gets.split(" ")
if(line[0].to_s == "##")
id = line[1]
value = line[2]
db.execute "insert into readings values ( ?, ?, ?)", id,value, Time.now.strftime("%F %T")
printf("%s : %s.%s @ %s\r\n", id, value[0..-2],value[-1,1],Time.now.strftime("%F %T"))
end
end
sp.close
However I cannot seem to get the gems (serialport & sqlite) working on openwrt. I have read on this forum that gems aren't really supported due to the difficulty porting them.
I have found a ipkg source which seems to have a ruby-serialport package: http://www.aprs4r.org/openwrt/backfire-10.03/brcm47xx/
It installs but when running the program it complains that the file serialport.so is not for MIPS.
This is apparently a "mipsel" package and won't run on my device. I am a novice so I don't really know how to compile my own.
Does anybody know how to read (and hopefully write) to aserial port under Ruby?
I am open to changing to something else like Python or Perl, any sugestions?
p.s. I am a newbe on the OpenWrt platform.