Please Help!
Thanks
Code: Select all
--[[script_time_export_emoncms.lua
auteur : papoo
version : 1.00
date : 18/05/2016
Principe :
exporter les donn�es de compteurs, Temp�ratures, etc.. sur le site https://emoncms.org/
Le script est lu toutes les minutes mais n'exporte les donn�es que toutes les 2 minutes (temps modifiable ligne 74)
]]--
-- ============================================================================
-- Variables
local debugging = false -- true ou false
local url_emoncms = 'http://emoncms.org/api/'
local API_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx' -- API Write KEY emoncms 32 charact�res
local les_devices = {};
les_devices[1] = {name="HeatIt_play - Temperatura"}
les_devices[2] = {name="HeatIt_living - Temperatura"}
les_devices[3] = {name="HeatIt_ppal - Temperatura"}
les_devices[4] = {name="sensor pergola - TempHum"}
les_devices[5] = {name="hem3 - Total Whatts"}
local fields =""
-- ============================================================================
commandArray = {}
function voir_les_logs (s)
if (debugging) then
print ("<font color='#f3031d'>".. s .."</font>");
end
end
function sans_accent(str)
if (str) then
str = string.gsub (str,"�", "C")
str = string.gsub (str,"�", "c")
str = string.gsub (str,"[-����']+", "e")
str = string.gsub (str,"[-����']+", "E")
str = string.gsub (str,"[-������']+", "a")
str = string.gsub (str,"[-@������']+", "A")
str = string.gsub (str,"[-����']+", "i")
str = string.gsub (str,"[-����']+", "I")
str = string.gsub (str,"[-������']+", "o")
str = string.gsub (str,"[-�����']+", "O")
str = string.gsub (str,"[-����']+", "u")
str = string.gsub (str,"[-����']+", "U")
str = string.gsub (str,"[-��']+", "y")
str = string.gsub (str,"�", "Y")
end
return (str)
end
function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
now=os.date("*t")
if now.min % 1 == 0 then -- Exportar datos a emoncms cada 1 min
print('export_emoncms.lua')
voir_les_logs("--- --- --- Export vers emoncms : "..now.hour.. ":" ..now.min,debugging);
for i,d in ipairs(les_devices) do
v=otherdevices[d.name] -- v is the value attached to device d
voir_les_logs(sans_accent(d.name).." = "..(v or "nil"),debugging);
if v==nil or v=="" or v=="Open" then -- multi valued ?
v=otherdevices_svalues[d.name] or ""
voir_les_logs("--- --- --- ".. sans_accent(d.name) .." = ".. v,debugging);
end
fields = fields .. '{'.. d.name .. ':' .. v .. '},'
end
fields = string.gsub (fields, ",$", "") -- quitar la última coma
fields = urlencode(sans_accent(fields)) -- Remover acentos caracteres acentuados
voir_les_logs("--- --- --- ".. url_emoncms ..'post?apikey=' .. API_key .. '&json=' .. fields ,debugging);
commandArray[1]={['OpenURL']=url_emoncms ..'post?apikey=' .. API_key .. '&json=' .. fields }
end -- if now
-- ============================================================================
return commandArray