diff --git a/.ruby-version b/.ruby-version index 970977c..02f2617 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-1.9.3-p125 +ruby-1.9.3-p484 diff --git a/Gemfile.lock b/Gemfile.lock index a446b03..61e23e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,6 +16,9 @@ GEM builder (3.0.4) daemons (1.1.9) i18n (0.6.1) + mail (2.6.1) + mime-types (>= 1.16, < 3) + mime-types (2.3) multi_json (1.7.7) mysql2 (0.3.11) rufus-scheduler (2.0.19) @@ -30,6 +33,7 @@ PLATFORMS DEPENDENCIES activerecord (= 3.2.13) daemons + mail mysql2 rufus-scheduler serialport diff --git a/app/helpers/SearchingForSyncState.rb b/app/helpers/SearchingForSyncState.rb index b29a135..d33916b 100644 --- a/app/helpers/SearchingForSyncState.rb +++ b/app/helpers/SearchingForSyncState.rb @@ -10,4 +10,4 @@ class SearchingForSyncState < StatePattern::State # return return bytes[idx..-1] || "" end -end \ No newline at end of file +end diff --git a/app/helpers/Synchronizer.rb b/app/helpers/Synchronizer.rb index a171021..1eed956 100644 --- a/app/helpers/Synchronizer.rb +++ b/app/helpers/Synchronizer.rb @@ -1,8 +1,8 @@ class Synchronizer - include StatePattern + include StatePattern SYNC_PATTERN = "\n/ISk5\\2ME382-1003\n\n" - set_initial_state SearchingForSyncState + set_initial_state ::SearchingForSyncState end diff --git a/daemonize.rb b/daemonize.rb index cbb1646..7d63480 100644 --- a/daemonize.rb +++ b/daemonize.rb @@ -1,4 +1,4 @@ -require 'rubygems' +#require 'rubygems' require 'daemons' pwd = Dir.pwd diff --git a/etc/daily_mailer b/etc/daily_mailer index 0dc3e7c..80d8900 100755 --- a/etc/daily_mailer +++ b/etc/daily_mailer @@ -1,8 +1,8 @@ #!/usr/bin/env bash # load rvm ruby -source /usr/local/rvm/environments/ruby-1.9.3-p125@smartmeter +source /usr/local/rvm/environments/ruby-1.9.3-p484@smartmeter -cd /mnt/usb/ruby/smartmeter +cd /home/pcog/smartmeter ruby report_mailer.rb diff --git a/etc/smartmeter b/etc/smartmeter old mode 100644 new mode 100755 index ad83f8a..8eb1521 --- a/etc/smartmeter +++ b/etc/smartmeter @@ -5,7 +5,9 @@ # description: Starts Smartmeter as an unprivileged user. # -sudo -u www-data ruby /mnt/usb/ruby/smartmeter/daemonize.rb $1 +# Create a wrapper using 'rvm alias smartmeter ruby-1.9.3-p484@smartmeter' + +sudo -u www-data /usr/local/rvm/wrappers/smartmeter/ruby /home/pcog/smartmeter/daemonize.rb $1 RETVAL=$? exit $RETVAL diff --git a/smartmeter.rb b/smartmeter.rb index d48fb6e..6547b11 100644 --- a/smartmeter.rb +++ b/smartmeter.rb @@ -1,4 +1,4 @@ -require "rubygems" +#require "rubygems" require "bundler/setup" require "active_record" require "serialport" @@ -8,6 +8,7 @@ MAX_BYTES = 100 project_root = File.dirname(File.absolute_path(__FILE__)) Dir.glob(project_root + "/app/models/*.rb").each{|f| require f} +Dir.glob(project_root + "/app/helpers/SearchingForSyncState.rb").each{|f| require f} Dir.glob(project_root + "/app/helpers/*.rb").each{|f| require f} connection_details = YAML::load(File.open('config/database.yml')) @@ -16,7 +17,7 @@ ActiveRecord::Base.establish_connection(connection_details) def open_device begin # Open connection to serial port - io_device = SerialPort.new("/dev/ttyUSB1", 9600, 7, 1, SerialPort::EVEN) + io_device = SerialPort.new("/dev/ttyUSB0", 9600, 7, 1, SerialPort::EVEN) # Make reading blocking io_device.read_timeout = 0 rescue diff --git a/test-serial.rb b/test-serial.rb index d7f0a91..59bf644 100644 --- a/test-serial.rb +++ b/test-serial.rb @@ -7,6 +7,7 @@ require "state_pattern" project_root = File.dirname(File.absolute_path(__FILE__)) Dir.glob(project_root + "/app/models/*.rb").each{|f| require f} +Dir.glob(project_root + "/app/helpers/SearchingForSyncState.rb").each{|f| require f} Dir.glob(project_root + "/app/helpers/*.rb").each{|f| require f} connection_details = YAML::load(File.open('config/database.yml')) @@ -16,7 +17,7 @@ ActiveRecord::Base.establish_connection(connection_details) if __FILE__ == $0 #params for serial port - port_str = "/dev/ttyUSB1" #may be different for you + port_str = "/dev/ttyUSB0" #may be different for you baud_rate = 9600 data_bits = 7 stop_bits = 1