Page 38 of 76
Re: Pass2PHP
Posted: Saturday 13 April 2019 13:26
by gimic
Upgrade finished, had some trouble with getting statusses from other devices as i needed to re-write them as you told.
only thing that does not work is my screens
i get azimuth of the sun by running a script (dzvents) grabbing from darkcloud and updating a general custom sensortype every 5 minutes. it seems like pass2php does not see the update every 5 min so it does not do anything with the sensor.
maybe i'l do the execution in cron instead of in the custom sensortype php file.
Re: Pass2PHP
Posted: Saturday 13 April 2019 13:28
by gimic
Installation on debian stretch:
New version 04/2019
With my sql:
wget
http://repo.mysql.com/mysql-apt-config_0.8.9-1_all.deb
dpkg -i mysql-apt-config_0.8.9-1_all.deb
apt update
apt install mysql-server
mysql_secure_installation
Root password: domoticz
mysql -u root -p
Create user:
GRANT ALL PRIVILEGES ON *.* TO 'domotica'@'localhost' IDENTIFIED BY 'domotica';
Create db
CREATE DATABASE domotica;
Restore database
mysql -u domotica -p domotica < Create-Update SQL Database.txt
Install phpmyadmin
apt-get install phpmyadmin
Domoticz
Copy config.php to \var\www\
Copy all scripts to the correct location \var\www\html\
Adjust the _fetchdomoticz.php script:
require '/var/www/config.php';
require 'functions.php';
$domoticzurl='
http://127.0.0.1:8080';
Set the correct rights in the log files
Chown www-data:www-data /var/log/domoticz.txt for example
Browse to the _fecthcomoticz.php script and look in the db if the idx is added
Re: Pass2PHP
Posted: Saturday 13 April 2019 15:57
by sincze
gimic wrote: ↑Saturday 13 April 2019 13:28
Installation on debian stretch:
New version 04/2019
Tnx @gimic
It is installing however i received some key
warnings.
Code: Select all
pi@domoticz-pi:~ $ sudo apt update
Get:1 http://repo.mysql.com/apt/debian stretch InRelease [19.2 kB]
Hit:3 http://raspbian.raspberrypi.org/raspbian stretch InRelease
Hit:4 http://archive.raspberrypi.org/debian stretch InRelease
Err:1 http://repo.mysql.com/apt/debian stretch InRelease
The following signatures were invalid: EXPKEYSIG 8C718D3B5072E1F5 MySQL Release Engineering <[email protected]>
Get:2 https://dl.ubnt.com/unifi/debian stable InRelease [3,024 B]
Reading package lists... Done
W: GPG error: http://repo.mysql.com/apt/debian stretch InRelease: The following signatures were invalid: EXPKEYSIG 8C718D3B5072E1F5 MySQL Release Engineering <[email protected]>
E: The repository 'http://repo.mysql.com/apt/debian stretch InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
Re: Pass2PHP
Posted: Saturday 13 April 2019 16:05
by gimic
I am not working on pi, i am on thin cliënt with debian stretch on it. I'l look at it tonight if i missed any commands between, but dont think so.
Re: Pass2PHP
Posted: Saturday 13 April 2019 19:55
by gimic
i did not do any other commands, did not get errors either
google mysql raspberry pi and you will find a howto, its bascially only apt-get install mysql
the commands for the db should be the same.
Re: Pass2PHP
Posted: Saturday 13 April 2019 21:29
by sincze
gimic wrote: ↑Saturday 13 April 2019 19:55
i did not do any other commands, did not get errors either
google mysql raspberry pi and you will find a howto, its bascially only apt-get install mysql
the commands for the db should be the same.
I guess it has something to do with:
https://dbahire.com/how-to-install-mysq ... n-stretch/
MariaDB is also installed on the Pi.... for my Unifi stuff.
Seems a bit tricky to have them both installed according to the article.
Re: Pass2PHP
Posted: Saturday 13 April 2019 22:10
by Egregius
Mariadb is the same as mysql, isn't it?
I even think mariadb is the default mysql server in debian 9.
Anyway, I'm running mariadb so it shouldn't be a problem.
Edit: It is:
https://mariadb.com/resources/blog/mari ... -debian-9/
Re: Pass2PHP
Posted: Saturday 13 April 2019 23:37
by sincze
Let me just try to use mariadb and create an extra dB for pass2php
Re: Pass2PHP
Posted: Sunday 14 April 2019 8:00
by gimic
Indeed my DB is also Mariadb
Re: Pass2PHP
Posted: Sunday 14 April 2019 9:05
by sincze
I'm back in the game.. reverted.... and started over using:
https://r00t4bl3.com/post/how-to-instal ... spberry-pi
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mysql-server
sudo mysql_secure_installation
Code: Select all
pi@domoticz-pi:~ $ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.37-MariaDB-0+deb9u1 Raspbian 9.0
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
That post contained the answer to my issue:
Code: Select all
pi@domoticz-pi:~ $ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Let's continue.
Re: Pass2PHP
Posted: Sunday 14 April 2019 10:50
by sincze
As I am working on the WAF approved a.k.a. live system
I have to be careful.
For the installation wiki on RASPBERRY with MARIA DB.. in addition to the installation manual.
Importing the Database, first exit MYSQL
Code: Select all
mysql -u domotica -p domotica < 'Create-Update SQL Database.txt'
Check if Database was created
Code: Select all
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| domotica |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
I addded the
store($device,$status) function to my existing Pass2PHP and it is filling the database
Re: Pass2PHP
Posted: Sunday 14 April 2019 11:40
by sincze
Is it correct that I am missing the IDX value ??
- mising idx.JPG (26.28 KiB) Viewed 8174 times
Haha Can be solved with
_fetchdomoticz.php
Re: Pass2PHP
Posted: Tuesday 16 April 2019 11:01
by sincze
Code: Select all
function rgb($name,$hue,$level,$check=false)
{
global $user,$d,$domoticzurl;
lg(' (RGB) | '.$user.' => '.$name.' '.$level);
if ($d[$name]['i']>0) {
if ($check==false) {
file_get_contents($domoticzurl.'/json.htm?type=command¶m=setcolbrightnessvalue&idx='.$d[$name]['i'].'&hue='.$hue.'&brightness='.$level.'&iswhite=false');
} else {
if ($d[$name]['s']!=$$level) {
file_get_contents($domoticzurl.'/json.htm?type=command¶m=setcolbrightnessvalue&idx='.$d[$name]['i'].'&hue='.$hue.'&brightness='.$level.'&iswhite=false');
}
}
} else {
store($name, $level);
}
}
@Egregius: Is the
$$level) Correct double $$ ??
Re: Pass2PHP
Posted: Tuesday 16 April 2019 11:13
by sincze
For some reason, sometimes my lights don't receive a status.. messing the whole system up.
- No Status.JPG (15.65 KiB) Viewed 8155 times
I modified the status function a bit so that I can still use the existing rules without having to rewrite everything.
Code: Select all
function status($name)
{
global $d;
// lg('Status requested for: '.$name.' with status: '.$d[$name]['s']);
$status = $d[$name]['s'];
if ($status === '100') return 'On';
elseif ($status === '0') return 'Off';
elseif (empty($status)) return 'Empty'; // Sometimes no status.... strange..
else return $d[$name]['s'];
}
Re: Pass2PHP
Posted: Tuesday 16 April 2019 11:55
by Egregius
You could add some logging in pass2php when the status is empty to figure out why this is happening.
Re: Pass2PHP
Posted: Tuesday 16 April 2019 13:46
by sincze
Egregius wrote: ↑Tuesday 16 April 2019 11:55
You could add some logging in pass2php when the status is empty to figure out why this is happening.
It has something to do with:
Code: Select all
function yeelight($name,$command,$info='')
{ //Available commands: nightlight, fulllight, warmer, cooler, brightnessup, brightnessdown
$idx=idx($name);
if($idx>0)
{
$comment='(Pass2PHP Yeelight | '.$name.' => '.$command.' => '.$info;
lg($comment);
sl($name,100); // Switch light on first. Ater that apply the mood command.
curl(domoticz.'json.htm?type=command¶m='.$command.'&idx='.$idx);
}
}
mmm Parsing one of the available scenes results in empty value in DB.
Code: Select all
yeelight('Lamp LED Study Left',100,'Nightlight');
Does work. And value in DB
Code: Select all
yeelight('Lamp LED Study Left','nightlight','Nightlight');
Does not work. And NO value in DB.
Drilling down further.. adding a log in pass2php.php
Code: Select all
2019-04-16 14:26:09.537 Status: --->> Starting with: Lamp LED Study Left Received status is: Set Level !
I looked at a different light and domoticz reports the state as follows:
- No Status2.JPG (11.69 KiB) Viewed 8147 times
Re: Pass2PHP
Posted: Tuesday 16 April 2019 17:12
by sincze
For easy migration still tons and tons of code to review.. I modified the Pass2php legacy
cset and
cget functions so that I can store the values I want in 'cache' in the DB as well. I think this is correct.
cache=='mysql
Code: Select all
function cset($key,$value){
global $d;
if(cache=='apcu'){
apcu_store($key,$value);
}elseif(cache=='apc'){
apc_store($key,$value);
}elseif(cache=='memcached'){
if(!$m=xsMemcached::Connect('127.0.0.1',11211)){return;}$m->Set($key,$value);
}elseif(cache=='mysql'){
storemode($key, $value,true);
}
}
function cget($key){
global $d;
if(cache=='apcu'){
return apcu_fetch($key);
}elseif(cache=='apc'){
return apc_fetch($key);
}elseif(cache=='memcached'){
if(!$m=xsMemcached::Connect('127.0.0.1',11211)){return 0;}return $m->Get($key);
}elseif(cache=='mysql'){
return $d[$key]['m'];
}
}
Re: Pass2PHP
Posted: Tuesday 16 April 2019 18:58
by Egregius
I don’t have rgb stuff...
But I’m sure you’ll figure it out
Re: Pass2PHP
Posted: Tuesday 16 April 2019 22:23
by sincze
Egregius wrote: ↑Tuesday 16 April 2019 18:58
I don’t have rgb stuff...
But I’m sure you’ll figure it out
Got it. Will show fix tomorrow
Re: Pass2PHP
Posted: Wednesday 17 April 2019 9:58
by sincze
Issue was previously seen here:
https://www.domoticz.com/forum/viewtopi ... hp#p135033
As not all devices will provide a
"Set Level: 35%" but just
"Set Level". I think it is a Domoticz device bug.
"Set Level: 35%" will work with default Pass2PHP,
"Set Level" definitely not. To Solve it Pass2PHP.php needs a little modification.
Code: Select all
if(in_array($device,array('Lamp (Kastenkamer) (RF)','Lamp (CV Ruimte) (RF)','Lamp (Keukentafel)','Lamp (Keukentafel) (RF)','Lamp (Bank)','Lamp (Bank) (RF)',
'Lamp LED TV','Lamp LED Vensterbank','Lamp LED Tafel (Woonkamer)','Lamp LED Trap','Lamp LED Hal','Lamp LED Keukenkast',
'Xiaomi RGB Gateway','Xiaomi RGB Gateway (Keuken)','Lamp LED Study Left','Lamp LED Study Right','Lamp (Kastenkamer) (RF)' ))) {
if($status=='Off'){
store($device, 0); // 14-04-2019 Pass2PHP 3.0 If one of the above items (dimmers is updated store different values)
}elseif($status=='On'){
store($device, 100); // 14-04-2019 Pass2PHP 3.0 If one of the above items (dimmers is updated store different values)
}elseif( $status==='Set Level' || $status==='Set Color' || empty($status) ) {
store($device, nvalue($device,'Level')); // 14-04-2019 Pass2PHP 3.0 If one of the above items (dimmers is updated store different values)
}else{
$status=filter_var($status,FILTER_SANITIZE_NUMBER_INT);
store($device,$status); // 14-04-2019 Pass2PHP 3.0 If one of the above items (dimmers is updated store different values, dimmer value)
}
}
else {
store($device,$status); // 14-04-2019 Pass2PHP 3.0 If not one of the above items (dimmers is updated store different values)
}
//lgsql('Domoticz',$device,$status);
@include rootdir.'pass2php/'.$device.'.php';
//lg('Pass2php: Called '.$device.' = Received "'.$status.'" status');
}
Within functions I created an additional function
nvalue() to retrieve the missing info from the DB.
Code: Select all
function nvalue($name,$nvalue) // Added: 06-11-2018
{
$idx=idx($name);
$json_string=curl(domoticz.'json.htm?type=devices&rid='.$idx); // retrieve current level
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['result'][0];
if(array_key_exists($nvalue, $parsed_json)) {
$value=$parsed_json[$nvalue];
}
else $value='NA';
return $value;
}
The patient... a.k.a. the House is running fine for over 12 hours now and no WAF complaints.