Pass2PHP

Moderator: leecollings

poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

I get this error:

root@raspberrypi:/var/www/html/secure# php _fetchdomoticz.php
PHP Notice: Undefined variable: domoticzurl in /var/www/html/secure/_fetchdomoticz.php on line 14
PHP Warning: file_get_contents(/json.htm?type=devices&used=true): failed to open stream: No such file or directory in /var/www/html/secure/_fetchdomoticz.php on line 14

php is running correct with apache in my case

PHP Version 7.0.33-0+deb9u3

This is what I did not:

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache
sudo apt-get install mysql-server
sudo apt-get install phpmyadmin
sudo mysql_secure_installation 

mysql -u root -p

GRANT ALL PRIVILEGES ON *.* TO 'domotica'@'localhost' IDENTIFIED BY 'domotica';
CREATE DATABASE domotica;
Download the GitHub package zip file. In this zip file you have ‘Create-Update SQL Database.txt'

Code: Select all

mysql -u domotica -p domotica < 'Create-Update SQL Database.txt'
mysql -u root -p

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| domotica           |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

sudo ln -s /usr/share/phpmyadmin /var/www/html
Copy follow files from the ZIP file:

Code: Select all

pass2php.php
functions.php
_fetchdomoticz.php
config.php
To

Code: Select all

/var/html/secure
But then im lost. I have script_device_pass2php (OLD FILE) do I need copy this to :

Code: Select all

/domoitcz/script/lua
Also have a file called base64.lua .. do I need this one also and put info:

Code: Select all

/domoitcz/script/lua
This is maybe last part thats missing in a good explanation how to install pass2php?
Last edited by poudenes on Thursday 02 May 2019 12:11, edited 1 time in total.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

sincze wrote: Thursday 02 May 2019 10:44 Don't forget the lua file in the Domoticz directory later.
Can you echo the string (line12l that is failing so we can see what the problem is?
There seems to be a typo.
ok, i think I was to enthusiatic with putting in my personal info(eg. domoticz ipadresses in the different files/
I changed it all back to the usual files and now I get the following error based on line 12.

line 12 is:

Code: Select all

$domoticz=json_decode(file_get_contents($domoticzurl.'/json.htm?type=devices&used=true'), true);
error is:

Code: Select all

PHP Notice:  Undefined variable: domoticzurl in /var/www/html/secure/_fetchdomoticz.php on line 12
PHP Warning:  file_get_contents(/json.htm?type=devices&used=true): failed to open stream: No such file or directory in /var/www/html/secure/_fetchdomoticz.php on line 12
so I thought the "."was wrong after the $domoticzurl part.
after removing that I got the following error.

Code: Select all

PHP Parse error:  syntax error, unexpected ''/json.htm?type=devices&used=t' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ')' in /var/www/html/secure/_fetchdomoticz.php on line 12
Last edited by Trigun on Thursday 02 May 2019 12:18, edited 1 time in total.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Trigun wrote: Thursday 02 May 2019 12:07
sincze wrote: Thursday 02 May 2019 10:44 Don't forget the lua file in the Domoticz directory later.
Can you echo the string (line12l that is failing so we can see what the problem is?
There seems to be a typo.
line 12 looks like this:

Code: Select all

$domoticz=json_decode(file_get_contents($http://127.0.0.1:8080.'/json.htm?type=devices&used=true'), true);
indeed. I also put the "script_device_pass2php.lua" file in the following directory: /home/pi/domoticz/schrips/lua

I hope this helps.

thnx!

Code: Select all

$domoticz=json_decode(                                                                                                                                                                       
    file_get_contents(                                                                                                                                                                       
        $domoticzurl.'/json.htm?type=devices&used=true'                                                                                                                                      
    ),                                                                                                                                                                                       
    true                                                                                                                                                                                     
); 
must be ok. because $domoticzurl is configured in config.php
But I don't see a include or need to use config.php


EDIT:

Code: Select all

$domoticz=json_decode(file_get_contents($http://127.0.0.1:8081.'/json.htm?type=devices&used=true'), true); 
gives me

Code: Select all

PHP Parse error:  syntax error, unexpected ':', expecting ',' or ')' in /var/www/html/secure/_fetchdomoticz.php on line 12
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Tried this as well: Add

Code: Select all

require '/var/www/config.php';  
to

Code: Select all

_fetchdomoticz.php

Code: Select all

then I get error:

PHP Fatal error:  Uncaught Error: Call to undefined function store() in /var/www/html/secure/_fetchdomoticz.php:58
Stack trace:
#0 {main}
  thrown in /var/www/html/secure/_fetchdomoticz.php on line 58

Fatal error: Uncaught Error: Call to undefined function store() in /var/www/html/secure/_fetchdomoticz.php:58
Stack trace:
#0 {main}
  thrown in /var/www/html/secure/_fetchdomoticz.php on line 58
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

poudenes wrote: Thursday 02 May 2019 12:13
Trigun wrote: Thursday 02 May 2019 12:07
sincze wrote: Thursday 02 May 2019 10:44 Don't forget the lua file in the Domoticz directory later.
Can you echo the string (line12l that is failing so we can see what the problem is?
There seems to be a typo.
line 12 looks like this:

Code: Select all

$domoticz=json_decode(file_get_contents($http://127.0.0.1:8080.'/json.htm?type=devices&used=true'), true);
indeed. I also put the "script_device_pass2php.lua" file in the following directory: /home/pi/domoticz/schrips/lua

I hope this helps.

thnx!

Code: Select all

$domoticz=json_decode(                                                                                                                                                                       
    file_get_contents(                                                                                                                                                                       
        $domoticzurl.'/json.htm?type=devices&used=true'                                                                                                                                      
    ),                                                                                                                                                                                       
    true                                                                                                                                                                                     
); 
must be ok. because $domoticzurl is configured in config.php
But I don't see a include or need to use config.php


EDIT:

Code: Select all

$domoticz=json_decode(file_get_contents($http://127.0.0.1:8081.'/json.htm?type=devices&used=true'), true); 
gives me

Code: Select all

PHP Parse error:  syntax error, unexpected ':', expecting ',' or ')' in /var/www/html/secure/_fetchdomoticz.php on line 12

quick question:
do all files need to be put in /var/www/html/secure or /var/www/secure?
this might be a crucial part :)
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

In my case nginx base directory is
/var/www/html

So everything behind that / deeper is accessible via http calls.

So I would suggest /var/www/html/secure
At the moment no access to @egregius latest files to check what the current files look like.

If I look at your error message it seems he is unable to find the specific functions like 'store' those are defined in functions.php if I am correct
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

sincze wrote: Thursday 02 May 2019 13:03 In my case nginx base directory is
/var/www/html

So everything behind that / deeper is accessible via http calls.

So I would suggest /var/www/html/secure
At the moment no access to @egregius latest files to check what the current files look like.

If I look at your error message it seems he is unable to find the specific functions like 'store' those are defined in functions.php if I am correct
thats where I stored all the files, so thats ok.
In all the files though, the reference is made to a different path.
I'll change that first.

thanks for you help!
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

There is a difference if files should be available via a web call.../ web Request.:)

Vs

Or the file should just be available for reading.. like it should not be served by the webserver... However it should be available for PHP to read it :)
Be careful with modifying. If they are in the path as requested it should go okay.
You are using the exact setup of @egregius so a working solution.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Beside this all. We had config a mysql database, where in the files do you add the user/pass/db name information
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

sincze wrote: Thursday 02 May 2019 14:04 There is a difference if files should be available via a web call.../ web Request.:)

Vs

Or the file should just be available for reading.. like it should not be served by the webserver... However it should be available for PHP to read it :)
Be careful with modifying. If they are in the path as requested it should go okay.
You are using the exact setup of @egregius so a working solution.
I replaced all the files with the standard @egregius files again.
If I understand correctly I only need to change the domoticzurl of the config.php file which is stored in the /var/www folder?
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Did a full clear try:

unzip the ZIP total in /var/www/html/

changed the Domoticz info

still I have the error:

Code: Select all

PHP Notice:  Undefined variable: domoticzurl in /var/www/html/secure/_fetchdomoticz.php on line 14
PHP Warning:  file_get_contents(/json.htm?type=devices&used=true): failed to open stream: No such file or directory in /var/www/html/secure/_fetchdomoticz.php on line 14
So didn't change anything just Domoticz path
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

poudenes wrote: Thursday 02 May 2019 14:27 Did a full clear try:

unzip the ZIP total in /var/www/html/

changed the Domoticz info

still I have the error:

Code: Select all

PHP Notice:  Undefined variable: domoticzurl in /var/www/html/secure/_fetchdomoticz.php on line 14
PHP Warning:  file_get_contents(/json.htm?type=devices&used=true): failed to open stream: No such file or directory in /var/www/html/secure/_fetchdomoticz.php on line 14
So didn't change anything just Domoticz path
I Guess we're stuck at the same point :)
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Your issues seems similar indeed.
Variable is not found... And the file_get_content executes the wrong url .

Debug is needed here. :)

a. Declare temporarily the missing variable in the _fetch.php file to find the next clue.

As I don't have access to my pc / GitHub I have to work with your feedback to get it up and running. Only have my mobile phone screen. :)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

I just remember @egregius saying... He is calling the _fetch from a button on his floorplan... That would imply that the file already knows all variables and functions.

If you call the _fetch file by hand... You are missing key peaces of the pass2php puzzle...

Like the fetch file by itself would need :

require '/var/www/config.php';
require 'functions.php';
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

sincze wrote: Thursday 02 May 2019 15:11 I just remember @egregius saying... He is calling the _fetch from a button on his floorplan... That would imply that the file already knows all variables and functions.

If you call the _fetch file by hand... You are missing key peaces of the pass2php puzzle...

Like the fetch file by itself would need :

require '/var/www/config.php';
require 'functions.php';

Add this in _fetch and still I get the error :(
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

The current version of _fetchdomoticz is functioning, just tested and didn't get any errors.
There's a example config.php file in the secure folder.
Mine is placed outside my webroot at

Code: Select all

require '/var/www/config.php';
Either place it there, or change the files referring to it.
In the config file you must have a line like:

Code: Select all

$domoticzurl='http://127.0.0.1:8080';
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Remember Domoticz needs to accept these changes via 127.0.0.1 as well without username or password. (Local network)

@egregius if you call the _fetchdomicz.php via a browser. Does that also work for you? I guess the guys are trying that. In that case I guess _fetch is unaware of the config file and functions location as the file by itself if I remember correctly has no link to these config and functions files and will fail with the same error message as currently being experienced.

A wrongly placed config file as you describe will cause the same error message indeed.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: Pass2PHP

Post by Trigun »

poudenes wrote: Thursday 02 May 2019 15:22
sincze wrote: Thursday 02 May 2019 15:11 I just remember @egregius saying... He is calling the _fetch from a button on his floorplan... That would imply that the file already knows all variables and functions.

If you call the _fetch file by hand... You are missing key peaces of the pass2php puzzle...

Like the fetch file by itself would need :

require '/var/www/config.php';
require 'functions.php';

Add this in _fetch and still I get the error :(

GOT IT!!
my database is filled! whoehoo!
I put the config file in the www folder and added require '/var/www/config.php'; and require 'functions.php'; in the _fetch file.

i see the following output for all my devices.

Code: Select all

Notice: Undefined index: Temperature Garage in /var/www/html/secure/functions.php on line 368
PHP Notice:  Undefined index: Tuinsproeier(1hour) in /var/www/html/secure/functions.php on line 368
when I check the database i can see all the devices are added but am sure if the output is correct because of the undefined index?
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Pass2PHP

Post by poudenes »

Trigun wrote: Thursday 02 May 2019 16:53
poudenes wrote: Thursday 02 May 2019 15:22
sincze wrote: Thursday 02 May 2019 15:11 I just remember @egregius saying... He is calling the _fetch from a button on his floorplan... That would imply that the file already knows all variables and functions.

If you call the _fetch file by hand... You are missing key peaces of the pass2php puzzle...

Like the fetch file by itself would need :

require '/var/www/config.php';
require 'functions.php';

Add this in _fetch and still I get the error :(

GOT IT!!
my database is filled! whoehoo!
I put the config file in the www folder and added require '/var/www/config.php'; and require 'functions.php'; in the _fetch file.

i see the following output for all my devices.

Code: Select all

Notice: Undefined index: Temperature Garage in /var/www/html/secure/functions.php on line 368
PHP Notice:  Undefined index: Tuinsproeier(1hour) in /var/www/html/secure/functions.php on line 368
when I check the database i can see all the devices are added but am sure if the output is correct because of the undefined index?
Where did you add the mysql credentials? so php knows how to connect?
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

@trigun: excellent job.
Now have a look if all devices (domoticz) idx are there as well.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests