Page 70 of 76

Re: Pass2PHP

Posted: Friday 23 October 2020 8:02
by Egregius
Yes, maybe just the previous model.

Re: Pass2PHP

Posted: Monday 09 November 2020 20:58
by gimic
The old xiaomi works with the round sensor types. The new one does not i think. I am happy with my 6 xiaomi temperature sensors and the old gw. It was cheap 😊

My response time is 80ms on a thin cliënt with atom cpu and 2gig ram.

Re: Pass2PHP

Posted: Monday 09 November 2020 23:19
by ropske
@Egrerius: is your 'telegram' function still working?

the 'alert' function is not working for someway for me. i need to check why.
But i used the 'old' telegram function from your previous pass2php (what worked before for me) and now its not working anymore.

Code: Select all

function telegram2($msg,$silent=true,$to=1){
	
		
	for($x=1;$x<=100;$x++){
		$result=json_decode(file_get_contents('https://api.telegram.org/bot'.$telegrambot.'/sendMessage?chat_id='.$telegramchatid.'&text='.urlencode($msg).'&disable_notification='.$silent));
		if(isset($result->ok))
			if($result->ok===true){lg('telegram sent to 1: '.$msg);break;}
			else lg('telegram sent failed');sleep($x*3);
		global $actions;$actions=$actions+1;
	}
	if($to>=2)
		for($x=1;$x<=100;$x++){
			$result=json_decode(file_get_contents('https://api.telegram.org/bot'.$telegrambot.'/sendMessage?chat_id='.$telegramchatid2.'&text='.urlencode($msg).'&disable_notification='.$silent));
			if(isset($result->ok))
				if($result->ok===true){lg('telegram sent to 2: '.$msg);break;}
				else lg('telegram sent failed');sleep($x*3);
			global $actions;$actions=$actions+1;
		}
	elseif($to==3){ios($msg);global $actions;$actions=$actions+1;}
	
}


when i use this directly in a webbrowers: https://api.telegram.org/bot'.$telegram ... ='.$silent


with the needed data, i receive a telegram message.

u got any idea?
thank you

Re: Pass2PHP

Posted: Tuesday 10 November 2020 10:31
by Egregius
I pipe my telegram messages to a shell script so it doesn't hold up the rest of the script.

Code: Select all

function telegram($msg,$silent=true,$to=1)
{
	if ($silent==true) $silent='true';
	else $silent='false';
	shell_exec('/var/www/html/secure/telegram.sh "'.$msg.'" "'.$silent.'" "'.$to.'" > /dev/null 2>/dev/null &');
	lg('Telegram sent: '.$msg);
}
The alert function is to send a telegram, but only when a ttl is passed. So you can execute the alert function every minute, but the message will only be send once in the ttl. This uses a seperate sql table.

Code: Select all

CREATE TABLE `alerts` (
  `n` varchar(50) NOT NULL,
  `t` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


ALTER TABLE `alerts`
  ADD PRIMARY KEY (`n`);

Re: Pass2PHP

Posted: Wednesday 11 November 2020 10:43
by ropske
Hi Egrerius,

well if i use the "alert" function, it is writing data in the mysql data base, so that part works.

but the telegram itself is not working.
Even when i execute the telegram.sh itself with data, i don't receive a telegram message.

Code: Select all

./telegram.sh testmetalles false 1 > /dev/null 2>/dev/null &
give me this response:

Code: Select all

[1] 31353
so executed i think?

i think its something in my telegram.php
something with the curl

i found this on the internet to check if the curl is working:

Code: Select all

<?php
$ch = curl_init("http://www.google.com/");
$fp = fopen("google_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
if should work, it should make the file google_homepage.txt

but it does not make it.

also when i use this code:

Code: Select all

<?php
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
it says disabled

then i looked up in /etc/php/7.3/php.ini and there was a ; before: extension=curl so i removed that one and restarted apache2 server

when i check again with the code

Code: Select all

<?php
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
it still says Disabled

Re: Pass2PHP

Posted: Wednesday 11 November 2020 10:45
by ropske
if i want to install curl, i get this:

stijn@debian:~$ sudo apt-get install php-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
php7.3-curl
The following NEW packages will be installed:
php-curl php7.3-curl
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 36.7 kB of archives.
After this operation, 147 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 http://security.debian.org/debian-security buster/updates/main amd64 php7.3-curl amd64 7.3.14-1~deb10u1
404 Not Found [IP: 2a04:4e42:9::204 80]
Get:2 http://ftp.be.debian.org/debian buster/main amd64 php-curl all 2:7.3+69 [5,992 B]
Fetched 5,992 B in 0s (14.3 kB/s)
E: Failed to fetch http://security.debian.org/debian-secur ... _amd64.deb 404 Not Found [IP: 2a04:4e42:9::204 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
stijn@debian:~$

Re: Pass2PHP

Posted: Wednesday 11 November 2020 10:52
by ropske
ok, its working lol

i did like what i said: sudo apt-get update

and after that i did: sudo apt-get install php-curl

then restart apache2server: sudo service apache2 restart

and now the code:

Code: Select all

<?php
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
shows enabled

and telegram is sending messages, thanks anyway :lol: :D

Re: Pass2PHP

Posted: Wednesday 11 November 2020 11:29
by ropske
So the alert function only send a telegram message if message was more than 5minutes? (300seconds)

how can i change it so it sends a telegram message to user 1 and user 2?

Code: Select all

<?php
if ($status=='On') {
    $msg='Rook gedecteerd in badkamer!';
    alert($device, $msg, 300, false, 1, false);
    alert($device, $msg, 300, false, 2, false);
its normal due the alert function, it only sends a message to user1

if i should use this:

Code: Select all

if(is_array($to))
in the alert function and then a loop to send it to both users?

Re: Pass2PHP

Posted: Wednesday 11 November 2020 17:27
by Egregius
alert($device, $msg, 300, false, 2, false);
should do it normally. The 5th paramater is the send to one.

Re: Pass2PHP

Posted: Wednesday 11 November 2020 19:01
by ropske
hmm, i think i'm reading it wrong then :lol:

i thought this code:

Code: Select all

if ($last < TIME-$ttl) {
        if ($ios) {
			shell_exec('./ios.sh "'.$msg.'" >/dev/null 2>/dev/null &');
		}
		$time=TIME;
		$db->query("INSERT INTO alerts (n,t) VALUES ('$name','$time') ON DUPLICATE KEY UPDATE t='$time';");
        telegram($msg, $silent, $to);
        lg('alert='.$last);
    }
i thought it means:

when the last timestamp of the 'alert' update is less then $tt, it will not send again.
But if i send it to user1 then the alert timestamp is update and if i send it directly again to user2; then it wont send i think because last timestamp update is less then $ttl ?

Re: Pass2PHP

Posted: Thursday 12 November 2020 6:42
by Egregius
You don't have to send it twice. If you use alert('name', 'message', 3600, false, 2) the telegram will be send to both id's in one call.

Re: Pass2PHP

Posted: Friday 13 November 2020 8:53
by sincze
Hi @Egregius.

To speed up Pass2PHP (and I know you already did some extensive research in the past).
Was PHP preloading ever considered ??
https://www.php.net/manual/en/opcache.preloading.php

I've also done experiments with NGINX + Cache but enabling that gave me some mixed results.
_cron5.php did not appear anymore in my Domoticz log.. after disabling the cache it started working again.

Ofcourse by default Opcache is enabled.
But I was wondering if we could squeeze some more juice out of the system.
Opcache.PNG
Opcache.PNG (55.24 KiB) Viewed 1873 times
tnx
Sándor

Re: Pass2PHP

Posted: Friday 13 November 2020 14:27
by Egregius
Don't think preloading will make a big difference. Only your first 193 misses will benefit from it. It's not that you restart php-fpm every hour or so.
Don't know if I ever tried nginx for this. Because I'm used to use Apache2 on all other servers I manage I also went for that. I already know the virtual hosts files quite good. Doing it all in nginx would require to learn that all again.
And then for what? To squeze 1 msec out of it? Don't think the webserver will make a lot of difference in this usecase. Maybe if you have a gigantic household with thousands of users...

Re: Pass2PHP

Posted: Saturday 14 November 2020 9:05
by Egregius
Maybe I need to reconsider my last post...
Busy moving from Proxmox VM to LXC Containe, from Apache to nginx and from php7.4-fpm to php8.0-fpm
Will cost some work to finish it all...

First things I saw on my floorplan: the XHR requests take now 5msec and before 7-10msec.
From lua to php seems to be a little slower. I'm now at 26msec, but a lot is still at default values. Still room for improvement I guess.

Re: Pass2PHP

Posted: Saturday 14 November 2020 10:52
by Egregius
Starts to look good :-)

Code: Select all

2020-11-14 09:51:30.161 (ZWAVE) Light/Switch (pirkeuken)
2020-11-14 09:51:30.175 OpenZWave: Domoticz has send a Switch command! NodeID: 4 (0x04)
Used php7.4-fpm, 8.0 is still release candidate and there's no APCu support yet.

So, now running in LXC container with nginx, mariadb with sql file from tmpfs and domoticz on tmpfs.

Re: Pass2PHP

Posted: Tuesday 17 November 2020 17:37
by Egregius
Is there by any chance someone using PHP to connect to the Ring Doorbell API?
I have a Python script running but would rather have it in PHP ;)

Re: Pass2PHP

Posted: Thursday 19 November 2020 15:37
by Egregius
Made some more progress on the response times :lol:

Code: Select all

2020-11-19 15:33:19.983  (Xiaomi) Light/Switch (deurgarage)
2020-11-19 15:33:19.993  (STORE)                => deurgarage   => Open (Pass2PHP)
2020-11-19 15:33:19.993  (SWITCH)               =>garageled=>On (functions.php:994)
2020-11-19 15:33:19.993  Status: User: Admin initiated a switch command (2062/garageled/On)
2020-11-19 15:33:19.993  OpenZWave: Domoticz has send a Switch command! NodeID: 102 (0x66)
Now at 10 msec :mrgreen:

Changes:
Nginx instead of Apache2
php8.0-fpm instead of php7.4-fpm
wget instead of curl in the lua script (biggest change).
cron.sh now simply gets cron.php. Cron120, 180 etc is handled in the php file.

Re: Pass2PHP

Posted: Thursday 19 November 2020 20:19
by ropske
nice work guys :)

about the ring doorbell, i also have one, but still not managed to get it working in php

Something else, you dont had problems with Zwave before (i made a topic some months ago about it and you responded to it you did not had the same issues like me)

But i noticed a lot of other people have the same issue like me.
Domoticz telling a zwave device is switched off, but zwave control panel says its switched on and the real condition is also on, so something wrong with domoticz received the real value.

Just wondering what kind of Domoticz you have and what version of Openzwave you have 1.4 or 1.6?
I noticed a lot of the people who are having the same zwave problems have all version 1.6

thank you in adavance.

Re: Pass2PHP

Posted: Friday 20 November 2020 7:20
by Egregius
My Ring doorbell is working with IFTTT but that sucks, sometimes the alerts arrive hours later, even with a premium IFTTT account. I've put a Python script to poll the Ring alerts every 3 seconds. That's running on a server with another ip and another ring account because I got locked for some reason. It's running good now, but still like to handle it in PHP just because I know that better.

The only problem I have at the moment with Zwave is for the Qubino ZMNHBA2 Flush 2 Relays that don't report their correct status. Everything else works as it should. I'm running Domoticz 2020.2 Build 12485 with openzwave 1.6-1392-gb0afd4c6. The Qubino's also have the right status in the OZW control panel, but not in Domoticz. I'm using a kind of refresh script to have the right status but it's not ideal.
Oh, wait. I disabled that again because it did to much on the zwave network and caused delays.
It was something like this: if ($d['pirkeuken']['s']=='On') RefreshZwave(4);

Re: Pass2PHP

Posted: Friday 20 November 2020 7:24
by Egregius
sincze wrote: ↑Friday 13 November 2020 8:53 Was PHP preloading ever considered ??
https://www.php.net/manual/en/opcache.preloading.php
I played with that yesterday. Saw to much strange things that I stopped it. It was like it wanted to parse all included files at once resulting in a lot of errors for constants and functions already assigned.
It's only beneficial for the first execution of a file. Because functions.php is included everywhere and it's the biggest file that one is instantly cached. So I still believe it's not a big advantage.