Page 1 of 1

Migrating to Docker - JSON.lua not working

Posted: Sunday 27 June 2021 16:48
by PVuser
I migrated to Docker via Backup and Restore. All seems to work fine but my Fronius script. There I need to load JSON.lua

The orignial line was:

Code: Select all

JSON = (loadfile '/home/pi/domoticz/scripts/lua/JSON.lua')()  
Now I tried:

Code: Select all

JSON = (loadfile '/opt/domoticz/scripts/lua/JSON.lua')() 
and it seems to load. But I didn't get my data out of the fronius data with json. And I don't know any way to get deeper to find the error!

The part of code:

Code: Select all

   JSON = assert(loadfile '/opt/domoticz/scripts/lua/JSON.lua')()   -- For Linux
   if debug then print('JSON ~= nil?') end
   if debug then print("JSON: "..tostring(JSON~=nil)) end

   commandArray = {}
      -- Extract data from Fronius using API v1 
      -- from https://www.fronius.com/en/photovoltaics/products/all-products/system-monitoring/open-interfaces/fronius-solar-api-json-
      froniusURL   = 'curl "http://'..IPFronius..'/solar_api/v1/GetPowerFlowRealtimeData.fcgi"'
      jsonData    = assert(io.popen(froniusURL))
      froniusDevice = jsonData:read('*all')
      jsonData:close()
      froniusData = JSON:decode(froniusDevice)
      if debug then print("froniusData: "..tostring(froniusData~=nil)) end
      if debug then print("froniusData: "..tostring(froniusData)) end
  
And the debug output show me, that JSON is loaded, but froniusData is nil. I didn't change the code itself. Is there a change from Domoticz (2020.2/python 3.7.3) to current version?

Code: Select all

 2021-06-27 16:46:22.360 Status: LUA: JSON ~= nil?
2021-06-27 16:46:22.360 Status: LUA: JSON: true
2021-06-27 16:46:22.371 Status: LUA: froniusData: false
2021-06-27 16:46:22.371 Status: LUA: froniusData: nil 
I hope anyone can help me

Re: Migrating to Docker - JSON.lua not working

Posted: Sunday 27 June 2021 17:12
by waltervl

Re: Migrating to Docker - JSON.lua not working

Posted: Sunday 27 June 2021 17:41
by PVuser
Thanks, but this isn't the solution. I did:

Code: Select all

cp -r /opt/domoticz/scripts/lua /opt/domoticz/dzVents/runtime
and also checked, that copy was fine. And tried both, the old path and the new path
/opt/domoticz/dzVents/runtime.
None of this works.

And as you can see in the output I posted (it's still the same), the variable JSON was not nil, so I assume, that JSON was correct loaded!???

Re: Migrating to Docker - JSON.lua not working

Posted: Friday 02 July 2021 11:40
by PVuser
Is there another way to check, if JSON is loaded correctly? I think this will be the first entry point to narrow the error. But than I have no other idea, because the code is the same as in previoous domoticz version.

with:

Code: Select all

      froniusURL   = 'curl "http://'..IPFronius..'/solar_api/v1/GetPowerFlowRealtimeData.fcgi"'
      jsonData    = assert(io.popen(froniusURL))
      if debug then print("jsonData: "..tostring(jsonData)) end
I get the output:

Code: Select all

2021-07-02 11:43:43.761 Status: LUA: jsonData: file (0x72c18510) 
So it seems, that opening is also ok?


And

Code: Select all

      froniusDevice = jsonData:read('*all')
     if debug then print("froniusDevice: "..tostring(froniusDevice)) end
result in:

Code: Select all

2021-07-02 11:46:13.108 Status: LUA: froniusDevice: 

Migrating to Docker - curl doesn't work

Posted: Thursday 08 July 2021 17:16
by PVuser
Does nobody have an idea?

I'm sure now, that the error is in

Code: Select all

     froniusURL   = 'curl "http://'..IPFronius..'/solar_api/v1/GetPowerFlowRealtimeData.fcgi"'
The file content is empty! But why does it work outside a container?

Re: Migrating to Docker - JSON.lua not working

Posted: Thursday 08 July 2021 17:25
by waltervl
is curl installed in the docker container?
Did you try to run the command from the command prompt in the docker container to see what kind of error you get?

Migrating to Docker - How to install curl

Posted: Thursday 08 July 2021 17:41
by PVuser
many thanks @waltervl - thats it. But how to install??

Try to use it inside docker (via portainer) I get:

Code: Select all

root@6570a7555a37:/opt/domoticz# curl "http://192.168.178.200/solar_api/v1/GetPowerFlowRealtimeData.fcgi"
bash: curl: command not found
root@6570a7555a37:/opt/domoticz# apt-get update
Err:1 http://deb.debian.org/debian buster InRelease                  
  Temporary failure resolving 'deb.debian.org'
Err:2 http://security.debian.org/debian-security buster/updates InRelease
  Temporary failure resolving 'security.debian.org'
Err:3 http://deb.debian.org/debian buster-updates InRelease          
  Temporary failure resolving 'deb.debian.org'
Reading package lists... Done    
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease  Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
root@6570a7555a37:/opt/domoticz# apt-get install curl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package curl
Trying from outside I get nearly the same:

Code: Select all

pi@raspberrypi:~ $ docker exec -it domoticz apt-get update
Err:1 http://security.debian.org/debian-security buster/updates InRelease
  Temporary failure resolving 'security.debian.org'
Err:2 http://deb.debian.org/debian buster InRelease
  Temporary failure resolving 'deb.debian.org'
Err:3 http://deb.debian.org/debian buster-updates InRelease
  Temporary failure resolving 'deb.debian.org'
Reading package lists... Done
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease  Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
pi@raspberrypi:~ $

Trying the install Iget:

Code: Select all

pi@raspberrypi:~ $ docker exec -it domoticz apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package curl
pi@raspberrypi:~ $

So, how can I install it?

Re: Migrating to Docker - JSON.lua not working

Posted: Thursday 08 July 2021 19:51
by waltervl
I am no docker specialist but a search came to this: https://stackoverflow.com/questions/248 ... date-fails

Re: Migrating to Docker - JSON.lua not working

Posted: Friday 09 July 2021 18:44
by PVuser
I found this link also, and tried it, but it doesn't help. There is always the same error.
I miss some basic commands like ping, ssh, curl,.. perhaps it's a bad image/container and I have to ask in a docker forum for it.

But thanks for trying to help

Re: Migrating to Docker - JSON.lua not working

Posted: Sunday 11 July 2021 14:05
by EddyG
Perhaps you could try an other image: https://hub.docker.com/r/linuxserver/domoticz

OR do

docker exec -it <container name> /bin/bash
In the container do a

Code: Select all

apt-get update
apt-get install curl
You will lose curl after an update of the container.

Re: Migrating to Docker - JSON.lua not working

Posted: Thursday 15 July 2021 9:15
by PVuser
Thanks @EddyG for your suggestion. The first would be a solution, but I fear the installation on my running system for now. The second doesn't work.

My solution is now to do it in Node-Red and send the values via MQTT to Domoticz.