This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Buienradar script
#2
Hi,

They probably changed the XML format.

Here is a more stable version that ignores the XML changes and with auto object creation:

Code:
-- Geef station naam op die gebruikt dient te worden station_naam = "Zwolle" -- Vul hier het weerstation naam in. (Zie tabel hieronder) --Beschikbare weerstations -- 1 = Venlo                                27 = Goeree -- 2 = Arnhem                                28 = Leeuwarden -- 3 = Berkhout                            29 = Lelystad -- 4 = Cadzand                            30 = West-Utrecht                                             -- 5 = Utrecht                            31 = Maastricht -- 6 = Den Helder                        32 = Noordoostpolder -- 7 = Eindhoven                        33 = Oost-Groningen -- 8 = Weert                                34 = Oosterschelde -- 10 = Gilzen Rijen                35 = Rotterdam -- 11 = Goes                                36 = Rotterdam Haven -- 12 = Oost-Overijssel            37 = Schaar -- 13 = Groningen                        38 = Amsterdam -- 14 = Oost-Zeeland                39 = Midden-Zeeland -- 15 = Zwolle                            40 = West-Friesland -- 16 = Gorinchem                        41 = Texel -- 17 = Hoek van Holland        42 = Tholen -- 18 = Zuid-Zeeland                43 = Twente -- 19 = Hoogeveen                        44 = West-Zeeland -- 20 = Wadden                            45 = Vlieland -- 21 = Enkhuizen-Lelystad    46 = Vlissingen -- 22 = Schiermonnikoog            47 = Uden -- 23 = IJmond                            48 = Terneuzen -- 24 = IJmuiden                        49 = Hoorn -- 25 = Katwijk                            50 = Wijk aan Zee -- 26 = Noord-Groningen            51 = Woensdrecht -- Geef adressen + namen op en activeer de te gebruiken items (actief J/N), objecten worden automatisch aangemaakt indien niet bestaand. adresmapping = {  ['stationnaam'] = {    actief = 'J',    adres = '40/1/0',    naam = 'Station naam',    objecttype = dt.text  },  ['datum'] = {    actief = 'J',    adres = '40/1/1',    naam = 'Tijd en datum laatste update van weerstation',    objecttype = dt.text  },  ['zin'] = {    actief = 'J',    adres = '40/1/2',    naam = 'Weer tekstueel',    objecttype = dt.text  },  ['temperatuurGC'] = {    actief = 'J',    adres = '40/1/3',    naam = 'Temperatuur',    objecttype = dt.text  },  ['temperatuur10cm'] = {    actief = 'J',    adres = '40/1/4',    naam = 'Temperatuur op 10 centimeter van maaiveld',    objecttype = dt.text  },  ['luchtdruk'] = {    actief = 'J',    adres = '40/1/5',    naam = 'Luchtdruk',    objecttype = dt.text  },  ['luchtvochtigheid'] = {    actief = 'J',    adres = '40/1/6',    naam = 'Luchtvochtigheid',    objecttype = dt.text  },  ['regenMMPU'] = {    actief = 'J',    adres = '40/1/7',    naam = 'Regen milimeter per uur',    objecttype = dt.text  },  ['windrichting'] = {    actief = 'J',    adres = '40/1/8',    naam = 'Windrichting',    objecttype = dt.text  },  ['windrichtingGR'] = {    actief = 'J',    adres = '40/1/9',    naam = 'Windrichting in graden',    objecttype = dt.text  },  ['windsnelheidMS'] = {    actief = 'J',    adres = '40/1/10',    naam = 'Windsnelheid in meters per seconde',    objecttype = dt.text  },  ['windstotenMS'] = {    actief = 'J',    adres = '40/1/11',    naam = 'Windstoten in meter per seconde',    objecttype = dt.text  },  ['zichtmeters'] = {    actief = 'J',    adres = '40/1/12',    naam = 'Zicht in meters',    objecttype = dt.text  },  ['zonintensiteitWM2'] = {    actief = 'J',    adres = '40/1/13',    naam = 'Zon intensitiet',    objecttype = dt.text  },  ['icoonactueel'] = {    actief = 'J',    adres = '40/1/14',    naam = 'URL actueel icoon',    objecttype = dt.text  },  ['icoonid'] = {    actief = 'J',    adres = '40/1/15',    naam = 'Icoon id',    objecttype = dt.text  },  ['icoon'] = {    actief = 'N',    adres = '40/1/16',    naam = 'Icoon',    objecttype = dt.text  },  ['windsnelheidBF'] = {    actief = 'N',    adres = '40/1/17',    naam = 'Windsnelheid in beaufort',    objecttype =    dt.text  },  ['regio'] = {    actief = 'N',    adres = '40/1/18',    naam = 'Regio',    objecttype = dt.text  },  ['stationcode'] = {    actief = 'N',    adres = '40/1/19',    naam = 'Station code',    objecttype = dt.text  },  ['stationid'] = {    actief = 'N',    adres = '40/1/20',    naam = 'Station id',    objecttype = dt.text  },  ['lat'] = {    actief = 'N',    adres = '40/1/21',    naam = 'Latitude',    objecttype = dt.text  },  ['latGraden'] = {    actief = 'N',    adres = '40/1/22',    naam = 'Latitude in graden',    objecttype = dt.text  },  ['lon'] = {    actief = 'N',    adres = '40/1/23',    naam = 'Longitude',    objecttype = dt.text  },  ['lonGraden'] = {    actief = 'N',    adres = '40/1/24',    naam = 'Longitude in graden',    objecttype = dt.text  },  ['url'] = {    actief = 'N',    adres = '40/1/25',    naam = 'URL',    objecttype = dt.text  }, } -- Load libs require('socket.http') -- Function to create objects function createobject(item)    grp.create({        name = item.naam,        address = item.adres,        datatype = item.objecttype,        --visparams = item.visparams,        --enums = item.enums,        --units = item.units,        tags = {'Buienradar'},                 comment = 'Automatisch aangemaakt door buienradar script',    }) end -- Set timeout socket.http.TIMEOUT = 15 -- Get data from API local data = socket.http.request('http://xml.buienradar.nl/') --log(data) if not data then  alert('Weerbericht kan niet worden opgehaald..')  return end -- Create result table weerstationtag = false result = {} -- callback for tag start function starttag(parser, tag, attributes)  -- create new storage in result table for each <item> tag  if tag == 'weerstation' then    weerstationtag = true    table.insert(result, {})  end  currtag = tag    -- Add attribute "id"  if attributes.id ~= nil then    if currtag then      result[ #result ].stationid = attributes.id    end  end  -- Add attribute "regio"  if attributes.regio ~= nil then    if weerstationtag and currtag then      result[ #result ].regio = attributes.regio    end  end    -- Add attribute "zin"  if attributes.zin ~= nil then    if weerstationtag and currtag then      result[ #result ].zin = attributes.zin    end  end    -- Add attribute "ID"  if attributes.ID ~= nil then    if weerstationtag and currtag then      result[ #result ].icoonid = attributes.ID    end  end   end -- callback for tag end function endtag(p, tag)  if tag == 'weerstation' then    weerstationtag = false  end  currtag = nil end -- callback for character data function cdata(parser, text, attributes)  -- check if parser is inside of <item> and either in <title> or <description>  if weerstationtag and currtag then    if currtag == 'stationcode' then      result[ #result ].stationcode = text    elseif currtag == 'stationnaam' then      result[ #result ].stationnaam = text      elseif currtag == 'lat' then        result[ #result ].lat = text    elseif currtag == 'lon' then      result[ #result ].lon = text    elseif currtag == 'datum' then      result[ #result ].datum = text      elseif currtag == 'luchtvochtigheid' then      result[ #result ].luchtvochtigheid = text      elseif currtag == 'temperatuurGC' then      result[ #result ].temperatuurGC = text      elseif currtag == 'windsnelheidMS' then      result[ #result ].windsnelheidMS = text      elseif currtag == 'windsnelheidBF' then      result[ #result ].windsnelheidBF = text      elseif currtag == 'windrichtingGR' then      result[ #result ].windrichtingGR = text      elseif currtag == 'windrichting' then      result[ #result ].windrichting = text      elseif currtag == 'luchtdruk' then      result[ #result ].luchtdruk = text      elseif currtag == 'zichtmeters' then      result[ #result ].zichtmeters = text      elseif currtag == 'windstotenMS' then      result[ #result ].windstotenMS = text    elseif currtag == 'regenMMPU' then      result[ #result ].regenMMPU = text    elseif currtag == 'zonintensiteitWM2' then      result[ #result ].zonintensiteitWM2 = text      elseif currtag == 'icoonactueel' then      result[ #result ].icoonactueel= text    elseif currtag == 'temperatuur10cm' then      result[ #result ].temperatuur10cm = text    elseif currtag == 'url' then      result[ #result ].url = text    elseif currtag == 'latGraden' then      result[ #result ].latGraden = text    elseif currtag == 'lonGraden' then      result[ #result ].lonGraden = text    end  end end -- create parser lxp = require('lxp') parser = lxp.new({  StartElement = starttag,  EndElement = endtag,  CharacterData = cdata, }) -- parse data if parser:parse(data) then  parseddata = result else  log('parse failed') end --log(parseddata) -- loop through LUA result table if #parseddata > 0 then  for _, item in ipairs(parseddata) do    -- Get item with selected station_naam    if item.regio == station_naam then      if adresmapping.zin.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.zin.adres)        if currentvalue == nil then            createobject(adresmapping.zin)        end        if item.zin ~= currentvalue then          grp.update(adresmapping.zin.adres, item.zin)        end      end            if adresmapping.temperatuurGC.actief == 'J' then              currentvalue = grp.getvalue(adresmapping.temperatuurGC.adres)        if currentvalue == nil then            createobject(adresmapping.temperatuurGC)        end        if item.temperatuurGC ~= currentvalue then          grp.update(adresmapping.temperatuurGC.adres, item.temperatuurGC)        end      end            if adresmapping.windstotenMS.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.windstotenMS.adres)        if currentvalue == nil then            createobject(adresmapping.windstotenMS)        end        if item.windstotenMS ~= currentvalue then          grp.update(adresmapping.windstotenMS.adres, item.windstotenMS)        end      end            if adresmapping.luchtdruk.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.luchtdruk.adres)        if currentvalue == nil then            createobject(adresmapping.luchtdruk)        end        if item.luchtdruk ~= currentvalue then          grp.update(adresmapping.luchtdruk.adres, item.luchtdruk)        end      end            if adresmapping.stationcode.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.stationcode.adres)        if currentvalue == nil then            createobject(adresmapping.stationcode)        end        if item.stationcode ~= currentvalue then          grp.update(adresmapping.stationcode.adres, item.stationcode)        end      end            if adresmapping.url.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.url.adres)        if currentvalue == nil then            createobject(adresmapping.url)        end        if item.url ~= currentvalue then          grp.update(adresmapping.url.adres, item.url)        end      end            if adresmapping.lonGraden.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.lonGraden.adres)        if currentvalue == nil then            createobject(adresmapping.lonGraden)        end        if item.lonGraden ~= currentvalue then          grp.update(adresmapping.lonGraden.adres, item.lonGraden)        end      end            if adresmapping.datum.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.datum.adres)        if currentvalue == nil then            createobject(adresmapping.datum)        end        if item.datum ~= currentvalue then          grp.update(adresmapping.datum.adres, item.datum)        end      end            if adresmapping.stationnaam.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.stationnaam.adres)        if currentvalue == nil then            createobject(adresmapping.stationnaam)        end        if item.stationnaam ~= currentvalue then          grp.update(adresmapping.stationnaam.adres, item.stationnaam)        end      end            if adresmapping.temperatuur10cm.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.temperatuur10cm.adres)        if currentvalue == nil then            createobject(adresmapping.temperatuur10cm)        end        if item.temperatuur10cm ~= currentvalue then          grp.update(adresmapping.temperatuur10cm.adres, item.temperatuur10cm)        end      end            if adresmapping.icoonactueel.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.icoonactueel.adres)        if currentvalue == nil then            createobject(adresmapping.icoonactueel)        end        if item.icoonactueel ~= currentvalue then          grp.update(adresmapping.icoonactueel.adres, item.icoonactueel)        end      end            if adresmapping.lat.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.lat.adres)        if currentvalue == nil then            createobject(adresmapping.lat)        end        if item.lat ~= currentvalue then          grp.update(adresmapping.lat.adres, item.lat)        end      end            if adresmapping.windrichtingGR.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.windrichtingGR.adres)        if currentvalue == nil then            createobject(adresmapping.windrichtingGR)        end        if item.windrichtingGR ~= currentvalue then          grp.update(adresmapping.windrichtingGR.adres, item.windrichtingGR)        end      end            if adresmapping.regio.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.regio.adres)        if currentvalue == nil then            createobject(adresmapping.regio)        end        if item.regio ~= currentvalue then          grp.update(adresmapping.regio.adres, item.regio)        end      end            if adresmapping.luchtvochtigheid.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.luchtvochtigheid.adres)        if currentvalue == nil then            createobject(adresmapping.luchtvochtigheid)        end        if item.luchtvochtigheid ~= currentvalue then          grp.update(adresmapping.luchtvochtigheid.adres, item.luchtvochtigheid)        end      end            if adresmapping.windrichting.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.windrichting.adres)        if currentvalue == nil then            createobject(adresmapping.windrichting)        end        if item.windrichting ~= currentvalue then          grp.update(adresmapping.windrichting.adres, item.windrichting)        end      end            if adresmapping.lon.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.lon.adres)        if currentvalue == nil then            createobject(adresmapping.lon)        end        if item.lon ~= currentvalue then          grp.update(adresmapping.lon.adres, item.lon)        end      end            if adresmapping.zichtmeters.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.zichtmeters.adres)        if currentvalue == nil then            createobject(adresmapping.zichtmeters)        end        if item.zichtmeters ~= currentvalue then          grp.update(adresmapping.zichtmeters.adres, item.zichtmeters)        end      end            if adresmapping.latGraden.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.latGraden.adres)        if currentvalue == nil then            createobject(adresmapping.latGraden)        end        if item.latGraden ~= currentvalue then          grp.update(adresmapping.latGraden.adres, item.latGraden)        end      end            if adresmapping.windsnelheidBF.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.windsnelheidBF.adres)        if currentvalue == nil then            createobject(adresmapping.windsnelheidBF)        end        if item.windsnelheidBF ~= currentvalue then          grp.update(adresmapping.windsnelheidBF.adres, item.windsnelheidBF)        end      end            if adresmapping.windsnelheidMS.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.windsnelheidMS.adres)        if currentvalue == nil then            createobject(adresmapping.windsnelheidMS)        end        if item.windsnelheidMS ~= currentvalue then          grp.update(adresmapping.windsnelheidMS.adres, item.windsnelheidMS)        end      end            if adresmapping.zonintensiteitWM2.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.zonintensiteitWM2.adres)        if currentvalue == nil then            createobject(adresmapping.zonintensiteitWM2)        end        if item.zonintensiteitWM2 ~= currentvalue then          grp.update(adresmapping.zonintensiteitWM2.adres, item.zonintensiteitWM2)        end      end            if adresmapping.regenMMPU.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.regenMMPU.adres)        if currentvalue == nil then            createobject(adresmapping.regenMMPU)        end        if item.regenMMPU ~= currentvalue then          grp.update(adresmapping.regenMMPU.adres, item.regenMMPU)        end      end            if adresmapping.stationid.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.stationid.adres)        if currentvalue == nil then            createobject(adresmapping.stationid)        end        if item.stationid ~= currentvalue then          grp.update(adresmapping.stationid.adres, item.stationid)        end      end            if adresmapping.icoonid.actief == 'J' then        currentvalue = grp.getvalue(adresmapping.icoonid.adres)        if currentvalue == nil then          createobject(adresmapping.icoonid)        end        if item.icoonid ~= currentvalue then          grp.update(adresmapping.icoonid.adres, item.icoonid)          if adresmapping.icoon.actief == 'J' then            if currentvalue == nil then              createobject(adresmapping.icoon)                end            if item.icoonid == 'a' then              grp.update(adresmapping.icoon.adres, 17)            elseif item.icoonid == 'aa' then              grp.update(adresmapping.icoon.adres, 6)            elseif item.icoonid == 'b'then              grp.update(adresmapping.icoon.adres, 12)            elseif item.icoonid == 'bb'then              grp.update(adresmapping.icoon.adres, 13)              elseif item.icoonid == 'c' or item.icoonid == 'cc' then              grp.update(adresmapping.icoon.adres, 7)            elseif item.icoonid == 'd' or item.icoonid == 'dd' then              grp.update(adresmapping.icoon.adres, 10)            elseif item.icoonid == 'e' or item.icoonid == 'ee' then              grp.update(adresmapping.icoon.adres, 9)            elseif item.icoonid == 'f' or item.icoonid == 'ff' then              grp.update(adresmapping.icoon.adres, 2)            elseif item.icoonid == 'g' or item.icoonid == 'gg' then              grp.update(adresmapping.icoon.adres, 5)            elseif item.icoonid == 'h' or item.icoonid == 'hh' then              grp.update(adresmapping.icoon.adres, 3)            elseif item.icoonid == 'i' or item.icoonid == 'ii' then              grp.update(adresmapping.icoon.adres, 3)            elseif item.icoonid == 'j' or item.icoonid == 'jj' then              grp.update(adresmapping.icoon.adres, 19)            elseif item.icoonid == 'k' or item.icoonid == 'kk' then              grp.update(adresmapping.icoon.adres, 16)            elseif item.icoonid == 'l' or item.icoonid == 'll' then              grp.update(adresmapping.icoon.adres, 16)            elseif item.icoonid == 'm' or item.icoonid == 'mm' then              grp.update(adresmapping.icoon.adres, 2)            elseif item.icoonid == 'n' or item.icoonid == 'nn' then              grp.update(adresmapping.icoon.adres, 1)            elseif item.icoonid == 'o' or item.icoonid == 'oo' then              grp.update(adresmapping.icoon.adres, 11)            elseif item.icoonid == 'p' or item.icoonid == 'pp' then              grp.update(adresmapping.icoon.adres, 11)            elseif item.icoonid == 'q' or item.icoonid == 'qq' then              grp.update(adresmapping.icoon.adres, 16)            elseif item.icoonid == 'r' or item.icoonid == 'rr' then              grp.update(adresmapping.icoon.adres, 19)            elseif item.icoonid == 's' or item.icoonid == 'ss' then              grp.update(adresmapping.icoon.adres, 5)            elseif item.icoonid == 't' or item.icoonid == 'tt' then              grp.update(adresmapping.icoon.adres, 8)            elseif item.icoonid == 'u' or item.icoonid == 'uu' then              grp.update(adresmapping.icoon.adres, 4)            elseif item.icoonid == 'v' or item.icoonid == 'vv' then              grp.update(adresmapping.icoon.adres, 1)            elseif item.icoonid == 'w' or item.icoonid == 'ww' then              grp.update(adresmapping.icoon.adres, 15)            elseif item.icoonid == 'x' or item.icoonid == 'xx' then              grp.update(adresmapping.icoon.adres, 9)            elseif item.icoonid == 'y' or item.icoonid == 'yy' then              grp.update(adresmapping.icoon.adres, 20)            elseif item.icoonid == 'z' or item.icoonid == 'zz' then              grp.update(adresmapping.icoon.adres, 20)            elseif item.icoonid == '0' or item.icoonid == '00' then              grp.update(adresmapping.icoon.adres, 19)            elseif item.icoonid == '1' or item.icoonid == '11' then              grp.update(adresmapping.icoon.adres, 20)            else              grp.update(adresmapping.icoon.adres, 19)            end          end        end        end    end  end end

BR,

Erwin
Reply


Messages In This Thread
Buienradar script - by hajoveen - 02.12.2017, 14:31
RE: Buienradar script - by Erwin van der Zwart - 02.12.2017, 17:45
RE: Buienradar script - by hajoveen - 02.12.2017, 18:41
RE: Buienradar script - by hajoveen - 03.12.2017, 00:47
RE: Buienradar script - by hajoveen - 03.12.2017, 15:43
RE: Buienradar script - by hajoveen - 20.12.2017, 17:29

Forum Jump: