Page 53 of 76
Re: Pass2PHP
Posted: Friday 09 August 2019 10:16
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?
Re: Pass2PHP
Posted: Friday 09 August 2019 10:23
by Trigun
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

Re: Pass2PHP
Posted: Friday 09 August 2019 10:30
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?
Re: Pass2PHP
Posted: Friday 09 August 2019 10:36
by Trigun
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
Re: Pass2PHP
Posted: Friday 09 August 2019 10:42
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
Re: Pass2PHP
Posted: Friday 09 August 2019 10:59
by Trigun
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
Re: Pass2PHP
Posted: Friday 09 August 2019 14:14
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.
Re: Pass2PHP
Posted: Friday 09 August 2019 15:37
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 know

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 this
Sent from my iPhone using Tapatalk
Re: Pass2PHP
Posted: Sunday 11 August 2019 0:22
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!
Pass2PHP
Posted: Sunday 11 August 2019 1:27
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:
once I deleted these, the test file showed up in my logfile.
After a reboot everything else works as well!!
*learning the hard way

Re: Pass2PHP
Posted: Sunday 11 August 2019 7:31
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.
Re: Pass2PHP
Posted: Wednesday 14 August 2019 8:32
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
thanks!
Re: Pass2PHP
Posted: Wednesday 14 August 2019 11:21
by Egregius
Ideal moment to verify your installation notes

Re: Pass2PHP
Posted: Thursday 15 August 2019 21:40
by Trigun
Egregius wrote: ↑Wednesday 14 August 2019 11:21
Ideal moment to verify your installation notes
Yess it definitly is
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?
Re: Pass2PHP
Posted: Friday 16 August 2019 6:54
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);
}
}
Re: Pass2PHP
Posted: Friday 16 August 2019 8:45
by Trigun
aah ok, thank you!!! this will help with my headache around this topic

Re: Pass2PHP
Posted: Monday 02 September 2019 21:25
by ropske
Allmost done renovating my house and now busy with building in the Fibaro modules
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

Re: Pass2PHP
Posted: Tuesday 03 September 2019 6:08
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.
Re: Pass2PHP
Posted: Tuesday 03 September 2019 9:20
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?
Re: Pass2PHP
Posted: Tuesday 03 September 2019 17:01
by Egregius
I would say test it

Depends on your network and nas performance. Maybe it's even faster than on a Rpi.