Changeset 11
- Timestamp:
- 2010-07-07 09:13:56 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified energy profiling/I_EnergyProfiler1.xml ¶
r10 r11 2 2 <implementation> 3 3 <functions> 4 <![CDATA[ 4 5 ---[[ 5 6 local socket = require "socket" … … 78 79 table.insert (o, string.format('%s=%s',url.escape(k),url.escape(v))) 79 80 end 80 return table.concat (o, '& amp;')81 return table.concat (o, '&') 81 82 end 82 83 … … 119 120 local taskhandle = -1 120 121 function taskandlog (msg, ...) 121 if select ('#', ...) >0 then122 if select ('#', ...) > 0 then 122 123 msg = msg:format (...) 123 124 end … … 263 264 local days_checked, 264 265 times_of_day, 265 params_to_check = configstring:match ('([^& amp;]*)&([^&]*)&(.*)$')266 params_to_check = configstring:match ('([^&]*)&([^&]*)&(.*)$') 266 267 if not days_checked then return end 267 268 luup.log (('days_checked="%s"'):format (days_checked)) … … 284 285 users_checked, 285 286 provider, 286 energy_scene = params_to_check:match ('([^& amp;]*)&([^&]*)&([^&]*)&([^&]*)&([^&]*)&([^&]*)&([^&]*)&([^&]*)')287 energy_scene = params_to_check:match ('([^&]*)&([^&]*)&([^&]*)&([^&]*)&([^&]*)&([^&]*)&(*)&([^&]*)') 287 288 if not lights_on then return end 288 289 luup.log (('lights_on="%s"'):format (lights_on)) … … 298 299 local on_lights = count_on_lights() 299 300 luup.log (string.format ("currently %s lights on", on_lights)) 300 if on_lights >=tonumber (lights_on_count) then301 if on_lights > tonumber (lights_on_count) then 301 302 send_alert (users_checked, string.format ("You've left %d lights on", on_lights)) 302 303 run_scene (energy_scene) … … 316 317 local current_watts = measure_watts() 317 318 luup.log (string.format ("you're using %s watts", current_watts)) 318 if current_watts >= tonumber (watts_count) then319 if current_watts >= tonumber (watts_count) then 319 320 send_alert (users_checked, string.format ("You're using %s watts", current_watts)) 320 321 run_scene (energy_scene) … … 455 456 if not profile_config or type(profile_config) ~= "string" then error ("no config") end 456 457 457 local meter_id, secs, email = profile_config:match("^([%d]*)& amp;([%d]*)&(.*)$")458 local meter_id, secs, email = profile_config:match("^([%d]*)&([%d]*)&(.*)$") 458 459 if not meter_id then error ("can't parse config") end 459 460 … … 568 569 luup.call_timer ('p_saveELog', 1, '30m', '','') 569 570 return 0 571 end 572 573 function report_Energy () 574 local query = { 575 PK_AccessPoint=luup.pk_accesspoint, 576 HW_Key=luup.hw_key, 577 DateTime=os.date('%Y-%m-%d %H:%M:%S'), 578 } 579 local now = os.time() 580 for k,v in pairs (digestedWattage) do 581 -- dummy change 582 w_watts (k, em_serv, "Watts", tostring(v.curWatt), tostring(v.curWatt)) 583 local tspan = os.difftime (now, v.startRep) 584 if tspan > 0 then 585 local avg = v.total / tspan 586 query[("PK_Device_%d"):format(k)] = ('%s:%s'):format (tostring(avg), tostring(v.peak)) 587 end 588 v.total = 0 589 v.startRep = now 590 v.peak = 0 591 end 592 local url = socket.url.build { 593 host = luup.luup.event_server, 594 path = 'report_energy_log_1.php', 595 query = params(query) 596 } 597 luup.log ('url: '..url) 570 598 end 571 599 … … 623 651 -- p_saveRooms (watchedDevices) 624 652 luup.call_timer ('p_saveELog', 1, '3s', '','') 653 luup.call_timer ('report_Energy', 1, '5s', '','') 625 654 luup.log ('EnergyMonitor initialized') 626 655 end … … 636 665 try_profiling (lul_device) 637 666 end 667 ]]> 638 668 </functions> 639 669 <startup>te_startup</startup>
Note: See TracChangeset
for help on using the changeset viewer.