ddamron
Alumni
wants to work for LinuxMCE

Posts: 962
|
 |
« Reply #15 on: January 24, 2008, 02:40:34 pm » |
|
Jason, I ran into the same thing. I don't know what it is.. but the work around is: var = "<" + "tag>" Be careful, As I found, when trying to LOG stuff... XML get's wiped in the log too.. I found out the hard way while trying to log var.inspect. it didn't work.. but the code was FINE in IRB. With regards to the log, putc '<' - ; putc 32; then finish your log...
HTH Dan
|
|
|
|
|
Logged
|
The only intuitive interface is the nipple. After that it's all learned. My other computer is your windows box. I'm out of my mind. Back in 5 minutes. Q: What's Red and smells like blue paint?
A: Red Paint.
|
|
|
|
jspeckman
|
 |
« Reply #16 on: February 03, 2008, 04:41:39 pm » |
|
Hi all, I've got a new version of the weather code. I've had this code running for a while now, just haven't had time to post it. I was going to post it now, but everytime I try I get a error message saying 'Cannot access attachments upload path'. I did a search, but no solutions to this were found. Anyway the auto retrieval code is working, and I fixed the problem I was having with the editor removing my xml tags. Since it was part of a regex I simply used the tag I am searching for without the first '<'. The editor likes it and the regex code finds only the data I'm looking for. Also added some more logging. I've had it running for a couple days now and it seems well behaved so far. I'd like to start adding data retrieval now so that other devices (and hopefully events) can get weather data whenever they want it, rather than waiting an hour to see if something changed.
Thanks, Jason
|
|
|
|
|
Logged
|
|
|
|
ddamron
Alumni
wants to work for LinuxMCE

Posts: 962
|
 |
« Reply #17 on: February 04, 2008, 01:37:19 am » |
|
Glad to hear that! Adding data retrieval is almost trivial.. simply create (or use existing) commands and pass data via the command..
Great Work!
|
|
|
|
|
Logged
|
The only intuitive interface is the nipple. After that it's all learned. My other computer is your windows box. I'm out of my mind. Back in 5 minutes. Q: What's Red and smells like blue paint?
A: Red Paint.
|
|
|
bulek
Administrator
wants to work for LinuxMCE
    
Posts: 868
Living with LMCE
|
 |
« Reply #18 on: February 05, 2008, 10:44:51 am » |
|
Hi all, I've got a new version of the weather code. I've had this code running for a while now, just haven't had time to post it. I was going to post it now, but everytime I try I get a error message saying 'Cannot access attachments upload path'. I did a search, but no solutions to this were found. Anyway the auto retrieval code is working, and I fixed the problem I was having with the editor removing my xml tags. Since it was part of a regex I simply used the tag I am searching for without the first '<'. The editor likes it and the regex code finds only the data I'm looking for. Also added some more logging. I've had it running for a couple days now and it seems well behaved so far. I'd like to start adding data retrieval now so that other devices (and hopefully events) can get weather data whenever they want it, rather than waiting an hour to see if something changed.
Thanks, Jason
Please post it... Regards, Bulek.
|
|
|
|
|
Logged
|
Thanks in advance,
regards,
Bulek.
|
|
|
|
jspeckman
|
 |
« Reply #19 on: February 06, 2008, 06:34:40 am » |
|
I tried again, but got the same error message 'Cannot access attachments upload path!' when trying to post with an attachment. Any ideas?
Jason
|
|
|
|
|
Logged
|
|
|
|
ddamron
Alumni
wants to work for LinuxMCE

Posts: 962
|
 |
« Reply #20 on: February 06, 2008, 09:17:39 am » |
|
Any spaces in the path? Try copying the code to root, then attach that.. HTH,
Dan
|
|
|
|
|
Logged
|
The only intuitive interface is the nipple. After that it's all learned. My other computer is your windows box. I'm out of my mind. Back in 5 minutes. Q: What's Red and smells like blue paint?
A: Red Paint.
|
|
|
|
jspeckman
|
 |
« Reply #21 on: February 07, 2008, 12:25:33 am » |
|
No luck. The forums are giving me the error, so I'm guessing the problem is not on my end. I did as you suggested though. I removed all spaces from the file name and moved it to the root of my local drive. I'm at a loss. Being over 250 line long I don't think pasting it into a message is the best of ideas. I'm open to suggestions though as to how to get my code up here.
Thanks, Jason
|
|
|
|
|
Logged
|
|
|
|
|
tschak909
|
 |
« Reply #22 on: February 07, 2008, 03:06:50 am » |
|
yup, I had tried to upload a picture attachment, with the same problem.. there is a permissions problem on the attachments path.
-Thom
|
|
|
|
|
Logged
|
|
|
|
|
jspeckman
|
 |
« Reply #23 on: February 23, 2008, 03:41:56 pm » |
|
Ok, Here's the code. Sorry to post it inline, but uploading attachments is still broke and the original I posted is no longer available. Have a look and let me know what you all think. Thanks Jason NOAA Weather ruby code - current 0:require 'Ruby_Generic_Serial_Device' 1:class Command < Ruby_Generic_Serial_Device::RubyCommandWrapper 2:end 3:class Device_35 < Ruby_Generic_Serial_Device::RubySerialWrapper 4:#### 351 #################################################################### 5:def cmd_351(cmd=nil) 6:@returnParamArray.clear 7:### Auto check weather every quarter past the hour per NOAA 8:t = Time.now 9: 10:if t.min == 15 11: t -= (60 * 60) 12: 13: if $obs_time =~/(\d\d):\d\d:\d\d/ 14: obs_hour = $1 15: end 16: 17: if t.hour != obs_hour.to_i 18: log("Quarter past the hour and weather update needed") 19: check_weather() 20: end 21:end 22:return @returnParamArray 23:end 24:#### 355 #################################################################### 25:def cmd_355(cmd=nil) 26:@returnParamArray.clear 27:### 28:# NOAA Weather check 29:# 2008 Jason Speckman 30:### 31:require 'net/http' 32: 33:# Init Vars 34: 35:$logFile = File.new("/var/log/pluto/NOAA_Weather.log", "w") 36: 37:$DEVICEDATA_ICAO_CONST = 249 38:$DEVICEDATA_UNITS_CONST = 250 39: 40:$units = "" 41:$identifier = "" 42:$location = "" 43:$obs_time = "" 44:$weather = "" 45:$temp = "" 46:$pressure = "" 47:$dew_point = "" 48:$heat_index = "" 49:$windchill = "" 50:$humidity = "" 51:$wind = "" 52:$visibility = "" 53: 54:### Check for identifier and units 55:if device_.devdata_ != nil 56: if device_.devdata_[$DEVICEDATA_ICAO_CONST] != nil 57: $identifier = device_.devdata_[$DEVICEDATA_ICAO_CONST] 58: log("ICAO identifier: "+$identifier) 59: else 60: log("No ICAO identifier specified") 61: end 62: if device_.devdata_[$DEVICEDATA_UNITS_CONST] != nil 63: $units = device_.devdata_[$DEVICEDATA_UNITS_CONST] 64: else 65: $units = "F" 66: end 67:end 68: 69:log("Units in degrees "+$units) 70: 71:if $units == "F" 72: $press_units = "in. Hg" 73:else 74: $press_units = "hPa" 75:end 76: 77: 78:### Tell DCE we are a climate device 79:log("Starting NOAA Weather Check") 80:log("Setup message intercept for DCERouter") 81: 82:### 83:# devIDfrom: device_.devid_ = my device id 84:# devIDto: -1000 = dcerouter 85:# priority: 86:# type: 1 = command, 2 = event 87:# id: 88: 89:$devIDfrom = device_.devid_ 90:devIDto = -1000 91:priority = "" 92:type = 2 93:id = "" 94: 95:#cmd = Command.new(devIDfrom, devIDto, priority, type, id) 96:#cmd.params_[x] = y 97:#SendCommand(cmd) 98: 99:#ms = "/usr/pluto/bin/MessageSend dcerouter " + device_.devid_.to_s + " -1000 8 0 5 2 4 10" 100:#system(ms) 101: 102:log("Init complete") 103: 104:### Initial weather check 105:check_weather() 106:return @returnParamArray 107:end 108:#### 356 #################################################################### 109:def cmd_356(cmd=nil) 110:@returnParamArray.clear 111:if ($logFile != nil) then 112: $logFile.close 113:end 114:return @returnParamArray 115:end 116:#### PRIVATE METHODS #################################################################### 117:### Logging function 118:def log(word) 119: $logFile.print( word + "\n" ) 120: $logFile.flush() 121:end 122: 123:### Weather check function 124:def check_weather() 125: log("Backing up previous data") 126: oldweather = $weather 127: oldtemp = $temp 128: oldpressure = $pressure 129: olddew_point = $dew_point 130: oldheat_index = $heat_index 131: oldwindchill = $windchill 132: oldhumidity = $humidity 133: oldwind = $wind 134: oldvisibility = $visibility 135: 136: log("Checking for weather updates") 137: 138:### Get xml file from NOAA 139:# xmlPath = "www.weather.gov/data/current_obs/"+$identifier+".xml" 140:# h = "GET "+xmlPath+" HTTP/1.0\r\n" 141:# log("HTTP Request: #{h}") 142:# conn_.Send(h) 143:# resv = "" 144:# while(true) 145:# buff = conn_.Recv(16384, 5000) 146:# if buff.length() == 0 147:# break 148:# end 149:# recv = recv + buff 150:# end 151: h = Net::HTTP.new('www.weather.gov', 80) 152: data_loc = "/data/current_obs/"+$identifier+".xml" 153: resp, data = h.get(data_loc, nil) 154: 155: if resp.message == "OK" 156: 157:# if recv =~ /^HTTP[^\r\n]+200\sOK.+?\r\n\r\n(.+)$/m 158:# data = $1 159:# log("Recieved:\n#{data}") 160: 161: data.each_line {|line| 162: if line =~/location>(.*)<\/location>/ 163: $location = $1 164: end 165: if line =~/observation_time_rfc822>(.*)<\/observation_time_rfc822>/ 166: $obs_time = $1 167: end 168: if line =~/weather>(.*)<\/weather>/ 169: $weather = $1 170: end 171: if $units == "F" 172: if line =~/temp_f>(.*)<\/temp_f>/ 173: $temp = $1 174: end 175: if line =~/pressure_in>(.*)<\/pressure_in>/ 176: $pressure = $1 177: end 178: if line =~/dewpoint_f>(.*)<\/dewpoint_f>/ 179: $dew_point = $1 180: end 181: if line =~/heat_index_f>(.*)<\/heat_index_f>/ 182: $heat_index = $1 183: end 184: if line =~/windchill_f>(.*)<\/windchill_f>/ 185: $windchill = $1 186: end 187: else 188: if line =~/temp_c>(.*)<\/temp_c>/ 189: $temp = $1 190: end 191: if line =~/pressure_mb>(.*)<\/pressure_mb>/ 192: $pressure = $1 193: end 194: if line =~/dewpoint_c>(.*)<\/dewpoint_c>/ 195: $dew_point = $1 196: end 197: if line =~/heat_index_c>(.*)<\/heat_index_c>/ 198: $heat_index = $1 199: end 200: if line =~/windchill_c>(.*)<\/windchill_c>/ 201: $windchill = $1 202: end 203: end 204: if line =~/relative_humidity>(.*)<\/relative_humidity>/ 205: $humidity = $1 206: end 207: if line =~/wind_string>(.*)<\/wind_string>/ 208: $wind = $1 209: end 210: if line =~/visibility_mi>(.*)<\/visibility_mi>/ 211: $visibility = $1 212: end 213: } 214: end 215: 216:### Send out events for weather changes 217: if $weather != oldweather 218: ms = "/usr/pluto/bin/MessageSend dcerouter "+device_.devid_.to_s+" -1001 2 75 13 \""+$weather+"\"" 219: system(ms) 220: log("Message sent: #{ms}") 221: end 222: if $temp != oldtemp 223: ms = "/usr/pluto/bin/MessageSend dcerouter "+device_.devid_.to_s+" -1001 2 25 13 \""+$temp+"\"" 224: system(ms) 225: log("Message sent: #{ms}") 226: end 227: 228: check_weather_done() 229:end 230: 231:### Post weather check 232:def check_weather_done() 233: log("Weather data from: "+$obs_time) 234: log("Weather check complete") 235:end 236:#### 395 #################################################################### 237:def cmd_395(cmd=nil) 238:@returnParamArray.clear 239:check_weather() 240:return @returnParamArray 241:end 242:#### 396 #################################################################### 243:def cmd_396(failed, cmd=nil) 244:@returnParamArray.clear 245:check_weather_done() 246:return @returnParamArray 247:end 248:#### START SETTERS #################################################################### 249:def initialize() 250:super 251:@returnParamArray=Array.new 252:end 253:#### END SETTERS #################################################################### 254:end
|
|
|
|
|
Logged
|
|
|
|
ddamron
Alumni
wants to work for LinuxMCE

Posts: 962
|
 |
« Reply #24 on: February 23, 2008, 09:10:17 pm » |
|
jspeckman
Nice!
That is a *great* piece of code. If I were you, I'd document that in the wiki! the more 'sample' code we have in the wiki, the more people can see how easy Ruby really is..
Great Work!
Dan
|
|
|
|
|
Logged
|
The only intuitive interface is the nipple. After that it's all learned. My other computer is your windows box. I'm out of my mind. Back in 5 minutes. Q: What's Red and smells like blue paint?
A: Red Paint.
|
|
|
|