weather~gov/documentation/services-web-api
api~weather~gov/stations/kmpo/observations/latest
--periods exchanged for tlides due to forum
i'm working on trying to get an http poller and lua parser for it.
needless to say it is not working. I'd appreciate any guidence that can be provided but will eventually figure it out.
Error: CLuaHandler: attempt to call a table value (global 'request')
i'm thinking the poller is not actually pulling the data but am not sure where it would be saved.
most of the code is pulled from others on this site.
Code: Select all
--[[Sample json data
"properties": {
"presentWeather": [
{
"intensity": "light",
"modifier": null,
"weather": "rain",
"rawString": "-RA"
}
],
"windDirection": {
"unitCode": "wmoUnit:degree_(angle)",
"value": 90,
"qualityControl": "V"
},
"windSpeed": {
"unitCode": "wmoUnit:km_h-1",
"value": 18.~359999999999999, --tlide added due to forum
"qualityControl": "V"
},
"barometricPressure": {
"unitCode": "wmoUnit:Pa",
"value": 100410,
"qualityControl": "V"
},
"precipitationLastHour": {
"unitCode": "wmoUnit:mm",
"value": 0,
"qualityControl": "C"
}
}
]]
-- Define device IDs
local wind_id = 330
local bar_id = 331
local rain_id = 329
-- Retrieve the content
s = request['content'];
-- Access JSON data using the domoticz_applyJsonPath function
--local WB = domoticz_applyJsonPath(s, '~properties~windspeed~value')
--api has no value for above entry
local WD = domoticz_applyJsonPath(s, '~properties~windDirection~value')
local WS = domoticz_applyJsonPath(s, '~properties~windSpeed~value')
local WG = domoticz_applyJsonPath(s, '~properties~windGust~value')
local TP = domoticz_applyJsonPath(s, '~properties~temperature~value')
local WC = domoticz_applyJsonPath(s, '~properties~windChill~value')
local BAR = domoticz_applyJsonPath(s, '~properties~barometricPressure~value')
local BAR_FOR = domoticz_applyJsonPath(s, '~properties~presentWeather~weather')
local RAINRATE = domoticz_applyJsonPath(s, '~properties~precipitationLastHour~value')
--all periods in above section replaced with tlides for forum
-- Update the devices in domoticz
domoticz_updateDevice(wind_id,'',WB .. ";" .. WD .. ";" .. WS .. ";" .. WG .. ";" .. TP .. ";" .. WC)
domoticz_updateDevice(bar_id,'',BAR .. ";" .. BAR_FOR)
domoticz_updateDevice(rain_id,'',RAINRATE)
removed the sample code from script, now begins at --define device id's
I've fixed s = request which had ( ) to [ ]
updated the device updateDevice's to match domoticz api/json page and changed function names in script to also more closely match.
still throwing various errors, closest i've gotten was basically it telling me there were not enough values in wind, expected 5 had 2, so that was revised as above which brings us to concatenate nil values errors.