====== Access from WebHMI itself ======
To access the WebHMI DB data via API, you have to generate API key in the setup menu and use it in your requests.
You can use //localhost// address as a part of the resource address.
{{ :api:setup-menu-api-key.png?direct |}}
{{ :api:api-key-example.png?direct&800 |}}
===== Getting meter data example =====
function getMeterData(startTime, endTime)
local c = cURL.easy_init()
c : setopt{ url = 'http://127.0.0.1/api/meters-log/',
timeout = 15,
httpheader = { 'X-WH-APIKEY: 4025D32205ADC52E8604690FFADFB4600B8D41AA',
'X-WH-START: ' .. startTime,
'X-WH-END: ' .. endTime,
'Accept: application/json',
'Content-Type: application/json'
}
}
local res = ""
c:perform{writefunction = function(str)
res = res .. str
end}
c : close()
if (res == '') or (res == '%[%]')then
ERROR('No data in response!')
return false
else
DEBUG(res)
return res
end
end
===== Getting graph data example =====
function getGraphData(regId, startTime, endTime)
local c = cURL.easy_init()
c : setopt{ url = 'http://127.0.0.1/api/graph-data/',
timeout = 15,
httpheader = {'X-WH-APIKEY: 9833A5C553C5E05D944C28615EB252A6CB2E9322',
'X-WH-START: ' .. startTime,
'X-WH-END: ' .. endTime,
'X-WH-SLICES: ' .. 30,
'X-WH-REGISTERS: ' .. regId,
'Accept: application/json',
'Content-Type: application/json'
}
}
local res = ""
c:perform{writefunction = function(str)
res = res .. str
end}
c : close()
if (res == '') or (res == '%[%]')then
ERROR('No data in response!')
return false
else
return res
end
end