Migrating to Docker - JSON.lua not working

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
PVuser
Posts: 33
Joined: Monday 30 March 2020 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: DE
Contact:

Migrating to Docker - JSON.lua not working

Post 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
User avatar
waltervl
Posts: 5711
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Migrating to Docker - JSON.lua not working

Post by waltervl »

Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
PVuser
Posts: 33
Joined: Monday 30 March 2020 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: DE
Contact:

Re: Migrating to Docker - JSON.lua not working

Post 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!???
PVuser
Posts: 33
Joined: Monday 30 March 2020 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: DE
Contact:

Re: Migrating to Docker - JSON.lua not working

Post 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: 
PVuser
Posts: 33
Joined: Monday 30 March 2020 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: DE
Contact:

Migrating to Docker - curl doesn't work

Post 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?
User avatar
waltervl
Posts: 5711
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Migrating to Docker - JSON.lua not working

Post 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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
PVuser
Posts: 33
Joined: Monday 30 March 2020 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: DE
Contact:

Migrating to Docker - How to install curl

Post 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?
User avatar
waltervl
Posts: 5711
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Migrating to Docker - JSON.lua not working

Post by waltervl »

I am no docker specialist but a search came to this: https://stackoverflow.com/questions/248 ... date-fails
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
PVuser
Posts: 33
Joined: Monday 30 March 2020 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: DE
Contact:

Re: Migrating to Docker - JSON.lua not working

Post 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
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Migrating to Docker - JSON.lua not working

Post 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.
PVuser
Posts: 33
Joined: Monday 30 March 2020 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: DE
Contact:

Re: Migrating to Docker - JSON.lua not working

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest