Changeset 11


Ignore:
Timestamp:
2010-07-07 09:13:56 (15 years ago)
Author:
javier_guerra
Message:

put lua code in a <![CDATA[ .... ]]>
start to get rid of curlqueue

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified energy profiling/I_EnergyProfiler1.xml

    r10 r11  
    22<implementation> 
    33    <functions> 
     4    <![CDATA[ 
    45---[[ 
    56        local socket = require "socket" 
     
    7879                table.insert (o, string.format('%s=%s',url.escape(k),url.escape(v))) 
    7980            end 
    80             return table.concat (o, '&amp;') 
     81            return table.concat (o, '&') 
    8182        end 
    8283         
     
    119120            local taskhandle = -1 
    120121            function taskandlog (msg, ...) 
    121                 if select ('#', ...) &gt; 0 then 
     122                if select ('#', ...) > 0 then 
    122123                    msg = msg:format (...) 
    123124                end 
     
    263264            local days_checked, 
    264265                times_of_day, 
    265                 params_to_check = configstring:match ('([^&amp;]*)&amp;([^&amp;]*)&amp;(.*)$') 
     266                params_to_check = configstring:match ('([^&]*)&([^&amp;]*)&(.*)$') 
    266267            if not days_checked then return end 
    267268            luup.log (('days_checked="%s"'):format (days_checked)) 
     
    284285                users_checked, 
    285286                provider, 
    286                 energy_scene = params_to_check:match ('([^&amp;]*)&amp;([^&amp;]*)&amp;([^&amp;]*)&amp;([^&amp;]*)&amp;([^&amp;]*)&amp;([^&amp;]*)&amp;([^&amp;]*)&amp;([^&amp;]*)') 
     287                energy_scene = params_to_check:match ('([^&]*)&([^&]*)&([^&]*)&([^&]*)&amp;([^&]*)&([^&]*)&amp;(*)&amp;([^&amp;]*)') 
    287288            if not lights_on then return end 
    288289            luup.log (('lights_on="%s"'):format (lights_on)) 
     
    298299                local on_lights = count_on_lights() 
    299300                luup.log (string.format ("currently %s lights on", on_lights)) 
    300                 if on_lights &gt;= tonumber (lights_on_count) then 
     301                if on_lights > tonumber (lights_on_count) then 
    301302                    send_alert (users_checked, string.format ("You've left %d lights on", on_lights)) 
    302303                    run_scene (energy_scene) 
     
    316317                local current_watts = measure_watts() 
    317318                luup.log (string.format ("you're using %s watts", current_watts)) 
    318                 if current_watts &gt;= tonumber (watts_count) then 
     319                if current_watts >= tonumber (watts_count) then 
    319320                    send_alert (users_checked, string.format ("You're using %s watts", current_watts)) 
    320321                    run_scene (energy_scene) 
     
    455456            if not profile_config or type(profile_config) ~= "string" then error ("no config") end 
    456457             
    457             local meter_id, secs, email = profile_config:match("^([%d]*)&amp;([%d]*)&amp;(.*)$") 
     458            local meter_id, secs, email = profile_config:match("^([%d]*)&([%d]*)&(.*)$") 
    458459            if not meter_id then error ("can't parse config") end 
    459460             
     
    568569                luup.call_timer ('p_saveELog', 1, '30m', '','') 
    569570                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) 
    570598            end 
    571599 
     
    623651        --          p_saveRooms (watchedDevices) 
    624652                luup.call_timer ('p_saveELog', 1, '3s', '','') 
     653                luup.call_timer ('report_Energy', 1, '5s', '','') 
    625654                luup.log ('EnergyMonitor initialized') 
    626655            end 
     
    636665            try_profiling (lul_device) 
    637666        end 
     667    ]]> 
    638668    </functions> 
    639669    <startup>te_startup</startup> 
Note: See TracChangeset for help on using the changeset viewer.