Pass2PHP

Moderator: leecollings

User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

And you have the right path in functions.php?

Code: Select all

function lg($msg)
{
    global $log;
    if ($log==true) {
		$fp=fopen('/var/log/domoticz.log', "a+");
		$time=microtime(true);
		$dFormat="Y-m-d H:i:s";
		$mSecs=$time-floor($time);
		$mSecs=substr(number_format($mSecs, 3), 1);
		fwrite($fp, sprintf("%s%s %s\n", date($dFormat), $mSecs, $msg));
		fclose($fp);
	}
}
And the www-data user has write rights to the file?
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 »

Egregius wrote: Friday 09 August 2019 10:16
My path is /var/log/domoticz.log with full 777 rights(also for the funtions file)
you mean the owner of de log file or de functions file?

owner of the domoticz.log file is root root
owner of the functions file is pi pi

so I guess I going wrong in one of the two files :)
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Owner doesn't matter if the file has 777 rights. Should be 666 because you don't need execute rights on a log file.
Not 1 of the lg lines comes in the logfile?
No errors in the php error log?
Did it ever work?
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 »

Egregius wrote: Friday 09 August 2019 10:30
Yes, it always worked fine
I have no errors in the nginx error.log file
no, there is no line at all in the log file
I also checked if cron was running and its running fine with the following output:

Code: Select all


● cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-08-09 09:28:06 CEST; 1h 4min ago
     Docs: man:cron(8)
 Main PID: 343 (cron)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/cron.service
           └─343 /usr/sbin/cron -f

Aug 09 10:29:01 Domoticz-LIVE CRON[8603]: pam_unix(cron:session): session closed for user pi
Aug 09 10:30:02 Domoticz-LIVE CRON[8732]: pam_unix(cron:session): session opened for user pi by (uid=0)
Aug 09 10:30:02 Domoticz-LIVE CRON[8736]: (pi) CMD (/usr/bin/nice -n20 /var/www/html/secure/cron.sh > /dev/null 2>&1)
Aug 09 10:30:02 Domoticz-LIVE CRON[8732]: pam_unix(cron:session): session closed for user pi
Aug 09 10:31:01 Domoticz-LIVE CRON[8872]: pam_unix(cron:session): session opened for user pi by (uid=0)
Aug 09 10:31:01 Domoticz-LIVE CRON[8877]: (pi) CMD (/usr/bin/nice -n20 /var/www/html/secure/cron.sh > /dev/null 2>&1)
Aug 09 10:31:01 Domoticz-LIVE CRON[8872]: pam_unix(cron:session): session closed for user pi
Aug 09 10:32:01 Domoticz-LIVE CRON[8978]: pam_unix(cron:session): session opened for user pi by (uid=0)
Aug 09 10:32:01 Domoticz-LIVE CRON[8982]: (pi) CMD (/usr/bin/nice -n20 /var/www/html/secure/cron.sh > /dev/null 2>&1)
Aug 09 10:32:01 Domoticz-LIVE CRON[8978]: pam_unix(cron:session): session closed for user pi

User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Make a test file, include the functions.php file.
Add a lg call and execute the file in terminal with php /path/to/file.php
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 »

Egregius wrote: Friday 09 August 2019 10:42
ok cool!
I created a test file with following info:

Code: Select all

<?php
require 'functions.php';

lg('this is __cron --> a test-Cron'); 

?>
when I execute the file I get nothing :?

when I execute the cron60 file inthe CLI it get the following error:

Code: Select all

pi@Domoticz-LIVE:/var/www/html/secure $ php _cron60.php
PHP Fatal error:  Uncaught Error: Call to undefined function lg() in /var/www/html/secure/_cron60.php:3
Stack trace:
#0 {main}
  thrown in /var/www/html/secure/_cron60.php on line 3
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Of course you get notting in the terminal, there's nothing in the php code that provides output.
Add a echo 'Script executing'; or something similar to have some output.

About the cron60: you can't just execute that script because it must be started from within cron.php. There is the inclusion of the functions file.
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 »

Egregius wrote:Of course you get notting in the terminal, there's nothing in the php code that provides output.
Add a echo 'Script executing'; or something similar to have some output.

About the cron60: you can't just execute that script because it must be started from within cron.php. There is the inclusion of the functions file.
Haha yeah I knowImage but the test file also does not show up in the log file.

Script executing does work as an output by manually starting it but not in the domoticz logging. What do I need to do to get this working?Really appreciate your help with thisImage


Sent from my iPhone using Tapatalk
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 »

Hi Egregius or perhaps anyone else,

I went through all the files and thought I found the missing piece in the functions file as the following is not present in the new file.

Code: Select all

function lgsql($user='',$device='',$status='',$info='')
{
    global $db;
    $db->query(
        "INSERT INTO log (user,device,status,info)
        VALUES ('$user','$device','$status','$info');"
    );
}
everything else is the same.

I just did a complete new install but unfortunately my "lg" lines are not showing up in my domoticz log file.

any chance someone knows the solution to this?

thanks in advance!
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Pass2PHP

Post by Trigun »

Trigun wrote: Sunday 11 August 2019 0:22 Hi Egregius or perhaps anyone else,
Ok, thanks to the compare functionality of Notepadd++ I am one step closer :)
the testfile is working and showing up in my logfile:
the following lines caused it for me:
in de the functions file these were added for the lg functionality:

Code: Select all

global $log;
    if ($log==true) {
 
once I deleted these, the test file showed up in my logfile.

After a reboot everything else works as well!!

*learning the hard way ;)
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Wasn't it better to add $log=false; or $log=true; to your config file? Then you can easily disable logging.
Once everything runs as expected I disable logging as much as possible.
A reboot isn't nescessary for changes in php files.
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 »

Egregius wrote: Sunday 11 August 2019 7:31 Wasn't it better to add $log=false; or $log=true; to your config file? Then you can easily disable logging.
Once everything runs as expected I disable logging as much as possible.
A reboot isn't nescessary for changes in php files.
That would definitely be a good option :) will definitely take that into account since I am doing a reinstall as we speak :D

thanks!
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Ideal moment to verify your installation notes ;)
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 »

Egregius wrote: Wednesday 14 August 2019 11:21 Ideal moment to verify your installation notes ;)
Yess it definitly is :D

I am still still stuggling with automatically setting the time for the bathroom.
I want the lights at 30% before 8am and after 9PM and the lights at 100% after 8am and before 9PM.
there I made the following:

Code: Select all

<?php
if($status=='On'&&TIME<=strtotime('8:00')&&TIME>=strtotime('21:00')){
sl('Badkamer', 40);
}

elseif($status=='On'&&TIME>=strtotime('8:00')&&TIME<=strtotime('21:00')){
sl('Badkamer', 100);
}
for some reason it domoticz doesn't seems not to get it and is not working.

any tips or tricks?
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

A time can never be before 8 AND after 21h. Then you need to use OR ( || in php)

Code: Select all

if ($status=='On') {
	if (TIME<=strtotime('8:00')||TIME>=strtotime('21:00')) {
		sl('Badkamer', 40);
	} else {
		sl('Badkamer', 100);
	}
}
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 »

Egregius wrote: Friday 16 August 2019 6:54
aah ok, thank you!!! this will help with my headache around this topic :)
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

Allmost done renovating my house and now busy with building in the Fibaro modules :lol: :lol:

I see you're not using apcu anymore but a mysql database now, is this database running on the Raspberry Pi itself? Or is it running on a NAS for example?
Thanks.

Trying to study your code to begin with a fresh installation for my home ;)
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I run everything on a Intel Nuc with Proxmox and SSD.
I’ve installed it for my cousin on a Rpi3 several months ago and everything runs smooth and stable.
Advantage of Mysql is that the cache isn’t volatile and you can add more data to it.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

So if i run domoticz on my raspberri pi3, then its better to install the mysql database also on the Pi?
Now i'm saving all temperature data to my mysql on my nas server, so better don't save the domoticz data to here also?

I will loose speed advantage then i think?
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I would say test it ;)
Depends on your network and nas performance. Maybe it's even faster than on a Rpi.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest