Logic Machine Forum
Script error json stack traceback: - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Script error json stack traceback: (/showthread.php?tid=1329)



Script error json stack traceback: - Domoticatorino - 05.04.2018

Hi there,
I use Always this script for weather condition

Code:
require('json')
require('socket.http')

socket.http.TIMEOUT = 5

local city = 716028
local data = socket.http.request('http://openrb.com/weather/?w=' .. city)

if not data then
 alert('Weather: cannot fetch data')
 return
end

data = json.pdecode(data)
if not data then
 alert('Weather: cannot parse data')
 return
end

-- current condition and temperature
-- grp.update('7/1/3', data.current.text, dt.string)
grp.update('7/1/4', data.current.temp)

-- forecast for today
grp.update('7/1/5', data.today.text, dt.string)
grp.update('7/1/6', data.today.low, dt.float16)
grp.update('7/1/7', data.today.high, dt.float16)

-- forecast for tomorrow
grp.update('7/1/8', data.tomorrow.text, dt.string)
grp.update('7/1/9', data.tomorrow.low, dt.float16)
grp.update('7/1/10', data.tomorrow.high, dt.float16)

grp.update('7/1/11', ((data.wind.chill-32)/1.8000), dt.float16)
grp.update('7/1/12', data.wind.direction, dt.angle)
grp.update('7/1/13', data.wind.speed, dt.float16)

grp.update('7/1/14', data.atmosphere.humidity, dt.float16)
grp.update('7/1/15', data.atmosphere.visibility, dt.float16)
grp.update('7/1/16', data.atmosphere.pressure, dt.float16)
grp.update('7/1/17', data.atmosphere.rising, dt.bool)

grp.update('7/1/18', data.astronomy.sunrise , dt.string)
grp.update('7/1/19', data.astronomy.sunset, dt.string)
I cannot understand the reason why in this case I read this following error:
Resident script:14: attempt to index global 'json' (a boolean value)

stack traceback:


What does it mean?

Thanks.


RE: Script error json stack traceback: - admin - 05.04.2018

There might be an issue in either common function library or a user library with automatic load enabled. Go to Scripting - Tools - Print and search for lines like "json =" or "json="


RE: Script error json stack traceback: - Domoticatorino - 05.04.2018

Thanks, I found it but even if I delated it, problem has been not sort it out.

Furthermore I have another problem in visualisation mode with this LM. When I push the icon button, telegram is sent to the bus but status object is not update hence button send always ON or OFF. It depends the status which I sent by KNX debug.

This is the first time that I find this kind of problem.

Ok, I sort it out the problem about object status disabling the bus sniffer.

But json problem still goes on.


RE: Script error json stack traceback: - admin - 05.04.2018

Try restarting the script via disable/enable


RE: Script error json stack traceback: - Domoticatorino - 05.04.2018

Hi Admin,
ok, I did what you suggested and everything is fine now. Thanks. But what was the problem exactly?

I checked system of other my customer and I found that in HL Schneider firmware 2.0.1 the problem has been not sort it out. Error message is always the same and alarm is "('Weather: cannot fetch data'). In fact all data are very hold.

How can I manage this kind of problem?

Thanks.


RE: Script error json stack traceback: - admin - 06.04.2018

It's an issue with your scripts/libraries. In Lua every variable is global unless prefixed with "local". If you override json global in any script library you cannot use it anywhere else. Another solution is to require library like this:
Code:
local json = require('json')

As for weather forecast not loading, check that you have valid gateway and dns settings in network config.


RE: Script error json stack traceback: - Domoticatorino - 06.04.2018

Thank you Admin.

Sort it out. I used local json = require ('json').

Thank you for your support.