Pass2PHP

Moderator: leecollings

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 »

@Egregius: I created a new php class (my first one indeed) to read Omink Inverters from friends via the Omnik Web Portal. (so no direct access to their Inverters). It log in to the portal, grabs a token, retrieves the data from the portal and returns the data.

Code: Select all

function OmnikInverterUpdate()
{
	include(rootdir.'pass2php_include/omnikwebinverter_class.php');
    
       $inverter = new \OmnikWebInverter\OmnikWebInverter(omnik_user_1,omnik_pwd_1,omnik_id_1);
	$result=$inverter->omnikdata();
	lg('Omnik: 1 Result: '.round($result[0]).' and: '.$result[1]); 

	$inverter = new \OmnikWebInverter\OmnikWebInverter(omnik_user_2,omnik_pwd_2,omnik_id_2);
	$result=$inverter->omnikdata();
	lg('Omnik: 2 Result: '.round($result[0]).' and: '.$result[1]);

	$inverter = new \OmnikWebInverter\OmnikWebInverter(omnik_user_3,omnik_pwd_3,omnik_id_3);
	$result=$inverter->omnikdata();
	lg('Omnik: 3 Result: '.round($result[0]).' and: '.$result[1]);
}
It just returns current W and Currenlt Daily KwH.

As this process takes around 6-8 seconds to complete, wouldn't it be best not to call this function from _Cronn300.php but move the action to a separate file like:

Code: Select all

shell_exec(domoticz_location.'scripts/pass2php/OmnikWebInverter.sh "'.$details.'" > /dev/null 2>/dev/null &');      // 
Like with telegram :lol: and grabbing screenshots from an ip camera ?

tnx for your thought.
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
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 »

I would indeed put it in cron120 or cron300 at the end of the file so it doesn't slow down the rest. Or put it in a separate script and call that at the end of cron.
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 »

Egregius wrote: Saturday 18 August 2018 13:05 I would indeed put it in cron120 or cron300 at the end of the file so it doesn't slow down the rest. Or put it in a separate script and call that at the end of cron.
Tnx for the tip at the end of Cron300.php
- Cron line calls function OmnikInverterUpdate() within pass2php library to update the omnik devices.

- The function calls 1 script 3 times (1 for each inverter)

Code: Select all

function OmnikInverterUpdate()
{
    shell_exec(domoticz_location.'scripts/pass2php/omnikwebinverter.sh "Omnik_1" > /dev/null 2>/dev/null &');
    shell_exec(domoticz_location.'scripts/pass2php/omnikwebinverter.sh "Omnik_2" > /dev/null 2>/dev/null &');
    shell_exec(domoticz_location.'scripts/pass2php/omnikwebinverter.sh "Omnik_3" > /dev/null 2>/dev/null &');
}
omnikwebinverter.sh calls a omnikwebinverter.php via the local webserver.

As the device name (Omnik_1) is passed as a parameter the omnikwebinverter.php can update the device using that name and you 'ud' function.

Maybe there is a better solution, but it is working ;-) :D

I could ofcourse move all inverter data to omnikwebinverter.php and have just 1 call
like so.

Code: Select all

function OmnikInverterUpdate()
{
    shell_exec(domoticz_location.'scripts/pass2php/omnikwebinverter.sh "all" > /dev/null 2>/dev/null &');
}

Code: Select all

function retrieve_omnik_data($command)
{
//    $device=$command;
 
    $to_inverters = array(     
                        array( 'device' => "Omnik 1",  'username' => 1_user, 'password' => 1_pwd, 'id' => 1_id ),
                        array( 'device' => "Omnik 2",  'username' => 2_user, 'password' => 2_pwd, 'id' => 2_id ),
                        array( 'device' => "Omnik 3",  'username' => 3_user, 'password' => 3_pwd, 'id' => 3_id )
                        );

    foreach ($to_inverters as $item) 
    {   
        $inverter = new \OmnikWebInverter\OmnikWebInverter($item['username'],$item['password'],$item['id']);
        $result=$inverter->omnikdata();
        $device=$item['device'];

        $str= ( round($result[0]).';'.($result[1]*1000) );
        lg('Omnik: '.$device.' result: '.round($result[0]).' and: '.$result[1].' for domoticz: '.$str);
        if ( isset($result[0]) && isset($result[1]) ) ud($device,0,$str,'Omnik: Inverter: Generation updated');
    }
}
Also working a well multiple roads to Rome...
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
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 »

Why bother searching for other solutions if it works without issues?
Leave it like that ;)
I only make changes for new stuff, like yesterday for a Bose Soundtouch 30 😁
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 »

Egregius wrote: Saturday 18 August 2018 16:05 I only make changes for new stuff, like yesterday for a Bose Soundtouch 30 😁
Am I missing a piece on your github :lol: :lol:
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
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 »

You also have a soundtouch?
I'm updating Github now ;)

There are some new functions for it:

Code: Select all

function bosekey($key,$sleep=100000){
	$xml = "<key state=\"press\" sender=\"Gabbo\">$key</key>";
	bosepost("key", $xml);
	usleep ($sleep);
	$xml = "<key state=\"release\" sender=\"Gabbo\">$key</key>";
	bosepost("key", $xml);
}
function bosevolume($vol){
	$vol=1*$vol;
	$xml = "<volume>$vol</volume>";
	bosepost("volume", $xml);
}
function bosepreset($pre){
	$pre = 1 * $pre;
	if($pre<1||$pre>6)return;
	bosekey("PRESET_$pre");
}
function bosepost($method,$xml){
	echo "$xml\n";
	$ch = curl_init("http://192.168.2.194:8090/$method");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
	curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
	$response = curl_exec($ch);
	curl_close($ch);
	echo $response;
}
And there are also some changes in pass2php files to automate some stuff for it. Like start playing a random preset when entering the living room and choose a volume depending on how early I'm awake :D
And a new floorplan to control it. It has basic functions like power on/off, volume, choose preset and view what's playing.
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 »

Egregius wrote: Sunday 19 August 2018 6:50 You also have a soundtouch?
I'm updating Github now ;)

There are some new functions for it:
.....

And there are also some changes in pass2php files to automate some stuff for it. Like start playing a random preset when entering the living room and choose a volume depending on how early I'm awake :D
And a new floorplan to control it. It has basic functions like power on/off, volume, choose preset and view what's playing.
Excellent.
I did not dare to touch your floorplans functionality yet. Not that much knowledge.

I do have everything in pass2php 'regular' style and that works great.
Sometimes I figure out a nice addition to add to it. :D
Currently out of ideas.. as pretty much everything I own that has a wire or antenna is taking part of it. :lol:

I have to admit you once told me about PHP possibilities with so many examples around.
viewtopic.php?f=64&t=12343&start=40#p107590
It's true. :P
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
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 »

You can run the floorplan completely besides the domoticz ui. Once you get the hang of it you’ll never use the domoticz ui again. Except for adding devices...
Sometimes I need to use the domoticz ui when I just added a switch, but what a pain it is to find a switch when you have +100 of them :shock:
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 »

Egregius wrote: Sunday 19 August 2018 22:19 You can run the floorplan completely besides the domoticz ui. Once you get the hang of it you’ll never use the domoticz ui again. Except for adding devices...
Sometimes I need to use the domoticz ui when I just added a switch, but what a pain it is to find a switch when you have +100 of them :shock:
Ok, let me have a closer look. :D don't need to think about cookies and login :D I hope..

Something different...
As my stupid bash file did not want create a nice google notification warning anymore... for a reason I don't know..Spending my whole sunday figuring out what went wrong.
I decided to go the Pass2PHP way..
Job finished within 35 minutes.... :lol: and.. response is a lot quicker.. as I now reuse my created samples.

Code: Select all


<?PHP
//error_reporting(E_ALL);ini_set("display_errors", "on");
define('rootdir','/var/www/html/secure/');
require(rootdir.'pass2php/settings.php');


if(isset($_REQUEST['text'])){ googlenotification($_REQUEST['text']); }             // The Command to parse is ; separated

function googlenotification($command) 
{
    $location="/tmp/google/";
    $lang = "nl-NL";

    $commandline = explode(";",$command);
    if(isset($commandline[0])) $devicename=$commandline[0];        // Google device
    if(isset($commandline[1])) $text=$commandline[1];                   // Text

    if (isset($devicename))     
    {
        switch ($devicename)          // Determine the IP Address of GOOGLE Machine.
        {
            case 'googlehome':
                $devicename='192.168.1.114';
            break;
            case 'googleaudio':
                $devicename='192.168.1.131';
            break;                
            default:
                $devicename='192.168.1.114';
        }
    }

    if ( time>=strtotime('08:00') && time<strtotime('21:00') ) $volume='0.4';
    else $volume='0.2';

    $text=str_replace('_', ' ', $text); 
    // MP3 filename generated using MD5 hash
    // Added things to prevent bug if you want same sentence in two different languages
    $file = md5($lang."?".urlencode($text));
    $file = $location . $file . ".mp3";
    
    // Check folder exists, if not create it, else verify CHMOD
    if (!is_dir($location)) mkdir($location);
    else
        if (substr(sprintf('%o', fileperms($location)), -4) != "0777") chmod($location, 0777);

    if (!file_exists($file))
    {
        $mp3 = file_get_contents('http://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&client=tw-ob&&tl='.$lang.'&q='.urlencode($text));        
        file_put_contents($file, $mp3);
    }

    if (file_exists($file))
    {
        $command=('python /home/pi/domoticz/scripts/system/stream2chromecast/stream2chromecast.py -devicename '.$devicename.' -setvol '.$volume);
        $output = passthru($command);

        $command=('python /home/pi/domoticz/scripts/system/stream2chromecast/stream2chromecast.py -devicename '.$devicename.' '.$file);
        $output = passthru($command);
    }

}
Only need to add something to check if the google device is online.. Could be as easy as

Code: Select all

status($devicename);
:lol: :lol: :lol:
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
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 »

Is the device pingable?
If so, there must be some code somewhere, perhaps the code I use to check if my nas is online.

Code: Select all

$nas=apcu_fetch('nas');
if(pingport('192.168.2.210',1598)==1){
	$prevcheck=apcu_fetch('check_diskstation_1598');
	if($prevcheck>0)apcu_store('check_diskstation_1598',0);
	if($nas!='On'){apcu_store('nas','On');apcu_store('Tnas',time());}
}else{
	$check=apcu_fetch('check_diskstation_1598')+1;
	if($check>0)apcu_store('check_diskstation_1598',$check);
	if($check>=3&&$nas!='Off'){apcu_store('nas','Off');apcu_store('Tnas',time());}
	$nas='Off';
}
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 »

@Egregius, cleaned up your code? :D no more usage for setstatus and status on github ?
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
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 »

Could be, but then it's already a long time like that I think.
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 found this nice https://github.com/Art-of-WiFi/UniFi-API-client class.
With the class you can retrieve info from the UniFi Controller. I created a script so I can do presence detection with PHP, just to phase out another cron job. :lol:

In addition I also used it to retrieve the public IP address and store that in a user variable. I used to have a separate function for that, however the online website I retrieved the information from was not always available. (not included in the example below)

Do's:
  • In the Unifi controller find your mobile phones and in the 'note' section add 'GSM' in the beginning.
  • The device name in the controller must be the same as the domoticz device name.
As the script takes several seconds to run I moved it to a separate file as suggested by @Egregius some posts ago, like the separate telegram script.
Spoiler: show

Code: Select all

<?PHP
define('rootdir','/var/www/****/*******/');
require(rootdir.'pass2php_include/settings.php');

checkunify();

function checkunify()
{
    require_once(rootdir.'pass2php_include/class/unificlient_class.php');
    
    $controlleruser     = unifi_controlleruser;         // the user name for access to the UniFi Controller
    $controllerpassword = unifi_controllerpassword;     // the password for access to the UniFi Controller
    $controllerurl      = unifi_controllerurl;          // full url to the UniFi Controller, eg. 'https://22.22.11.11:8443'
    $site_id            = unifi_site_id;
    
    /**
    * initialize the UniFi API connection class and log in to the controller and pull the requested data
    */

    $unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id);
    $loginresults     = $unifi_connection->login();

    $clients_array    = $unifi_connection->list_clients();
    $health_array     = $unifi_connection->list_health();

    $mobile_phones = array( "GSM Jan", "GSM Miep");                            // Check these phones (names)!
    $online_phones = array();

    foreach ($clients_array as $client) {
        if (isset($client->note) && (strpos($client->note, "GSM") === 0)) {         // Note field of USG contains the word GSM
            $online_phones[] = $client->name;                                       // Store found phone names in array
            }                                                                           
    }

    foreach ($mobile_phones as $mobile_phone ) {                                    // Retrieve a phone to check from the array        
        if ( in_array($mobile_phone, $online_phones) ) {
            if (status($mobile_phone) != 'On') sw($mobile_phone,'On'); 
        }
        else { 
            if (status($mobile_phone) != 'Off') sw($mobile_phone,'Off');
        }
        house_mode();
    }
}

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.
DarkAllMan
Posts: 52
Joined: Friday 23 December 2016 9:41
Target OS: Linux
Domoticz version:
Contact:

Re: Pass2PHP

Post by DarkAllMan »

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 »

There are other options available and still 87 days to explore them.
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 »

Hi All,

I wondering what the positive reason is to use this? Is it faster, easier, etc? Can someone tell me :)
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 »

:D
First advantage it is php so lots of examples on the internet.
And o boy it fast. My visitors are amazed about the responsiveness.

I started with pass2php before we had dVents.
But in the first few posts of this thread you can find speed comparisons. Pass2php Vs lua.
@Egregius has been a great help for me. As I had to rewrite all my lua scripts to PHP. A complete new language for me.
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 »

Thanks. I go check this as well... I can do everything what we now also can do on dzvents 2.4?

From 500-1000ms to less than 100 is a big difference and worth it to try


Verzonden vanaf mijn iPhone met Tapatalk Pro
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Pass2PHP

Post by waaren »

poudenes wrote: Saturday 06 October 2018 19:37 Thanks. I go check this as well... I can do everything what we now also can do on dzvents 2.4?
From 500-1000ms to less than 100 is a big difference and worth it to try Image
Please correct if I am wrong but what I read in the post with the speed comparison is that the difference from >1000 ms to < 100 ms is the result of loading the PHP with a Lua script (which is described there as being much faster) compared to loading PHP from domoticz. I don't read anything about comparing pure PHP speed with pure Lua speed.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
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 »

waaren wrote: Sunday 07 October 2018 9:51
poudenes wrote: Saturday 06 October 2018 19:37 Thanks. I go check this as well... I can do everything what we now also can do on dzvents 2.4?
From 500-1000ms to less than 100 is a big difference and worth it to try Image
Please correct if I am wrong but what I read in the post with the speed comparison is that the difference from >1000 ms to < 100 ms is the result of loading the PHP with a Lua script (which is described there as being much faster) compared to loading PHP from domoticz. I don't read anything about comparing pure PHP speed with pure Lua speed.
Mmm that could be true indeed. I do remember @Gizmocus giving the hint in a thread that PHP could be executed as well from within domoticz under scrips.

A well. I've been running Pass2PHP for several years now and it fits my needs, One step on the stairway and the lights switch on instantly. Keep in mind it does require some learning.. like for me PHP and tweaking the webserver (keep an eye on the logs)
WIthin Pass2PHP there is only 1 LUA file that triggers a PHP file.
From that moment on PHP takes over.
All variables are stored in cache and are accessible from any function. So it works separate from domoticz. But uses the domoticz API to switch or update devices.

I used to have ' script takes longer than 10 seconds to complete ' kind of messages in my Domoticz log. These are now history. As PHP seems to be single threaded as well for more complex functions (taking snapshots from IP cameras and sending them via telegram while kicking in a Kodi Addon with the live video feed) Pass2PHP does have some tricks to handle that.

Basically it is:
  • Install Domoticz,
    Install webserver Nginx (e.g.),
    Install PHP,
    Install Cache,
    Place Pass2PHP.lua in the lua directory of domoticz,
    Place FIles in webserver directory.
I can share my cheat sheet if you want. I've setup a system for my parents and these were the notes I did write down while building from scratch. (after completion I stop Domoticz, copy the database from their old release, restart domoticz and I can start building Pass2PHP)

Keep in mind these are steps for MY parents system so It could be you can skip a few steps :lol: At least by following these steps you won't break anything.
Spoiler: show
-1 What version am I running?
-> lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.3 (stretch)
Release: 9.3
Codename: stretch

0. Update Firmware (24-08-2018)
sudo rpi-update

1. Change Time-Zone -> Europe -> Amsterdam (24-08-2018)
sudo raspi-config

1. Update system (24-08-2018)

sudo apt-get update
sudo apt-get upgrade

3. Install Domoticz from SCRATCH (24-08-2018)

curl -L install.domoticz.com | sudo bash

6. Install PHP (24-08-2018)

sudo apt install php7.0 php7.0-cli php7.0-fpm php7.0-snmp php-curl

7. Install Webserver (NGINX) for Pass2php (24-08-2018)

sudo apt-get purge apache2
sudo apt-get remove apache2
sudo apt-get install nginx

sudo chown -R www-data:pi /var/www/html/
sudo chmod -R 770 /var/www/html/
sudo service nginx configtest

8 Logrotate (24-08-2018)
/etc/logrotate.conf

sudo logrotate -d /etc/logrotate.conf

9. Install lsof (24-08-2018)

sudo apt-get install lsof

10 Python: Failed dynamic library load, install the latest libpython3.x library that is available for your platform. (24-08-2018)

sudo apt-get install python3-dev

11. SAMBA Server (24-08-2018)
http://raspberrywebserver.com/serveradm ... twork.html

sudo apt-get install samba samba-common-bin

sudo nano /etc/samba/smb.conf

add: ## 18-11-2017 Due to SMB1 hacks added by Sincze
; bind interfaces only = yes
client min protocol = SMB2
client max protocol = SMB3

[homes]
comment = Home Directories
browseable = yes

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = no

[domoticz-www]
comment = Domoticz WWW directory
read only = no
locking = no
path = /home/pi/domoticz/www
guest ok = no

[domoticz-php]
comment = Domoticz PHP directory
read only = no
locking = no
path = /var/www
guest ok = no

[domoticz]
comment = Domoticz directory
read only = no
locking = no
path = /home/pi/domoticz/
guest ok = no

12. Set a password for Samba

sudo smbpasswd -a pi

13. Enable php (24-08-2018)

-> sudo nano /etc/nginx/sites-enabled/default

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

-> sudo nano /etc/php/7.0/fpm/php.ini

and set cgi.fix_pathinfo=0:

14 Install Caching (24-08-2018)

sudo apt install php-apcu
Also check if the module is active by “php -m”. You should see the entry “apcu” there at/near the top.

15 To avoid: server reached pm.max_children setting in /var/log/php7.0-fpm.log (23-08-2018)
https://serverfault.com/questions/81349 ... x-children

sudo nano /etc/php/7.0/fpm/pool.d/www.conf
;pm.max_children = 5 TO
pm.max_children = 10

sudo systemctl restart php7.0-fpm


30 Simple XML is maybe missing check with phpinfo! (Loaded Configuration File /etc/php/7.0/fpm/php.ini) (24-08-2018)

sudo apt-get install php7.0-xml

Change php.ini from:
; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect.
;opcache.validate_timestamps=1
opcache.validate_timestamps=0

sudo service php7.0-fpm restart

31 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) (24-08-2018)

sudo nano /etc/nginx/sites-available/default

fastcgi_pass unix:/run/php/php7.0-fpm.sock; # sincze added these lines
include fastcgi_params; # sincze added these lines
fastcgi_read_timeout 120; # sincze added these lines

32 NGINX open files problem (23-08-2018)
cat /proc/{nginx-master-process-id}/limits

sudo nano /lib/systemd/system/nginx.service

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
LimitNOFILE=30000 # <= This line was added

Add: LimitNOFILE=30000 # <= This line was added

sudo systemctl daemon-reload
sudo systemctl restart php7.0-fpm.service
sudo systemctl restart nginx


33 $ sudo nano /etc/nginx/nginx.conf (24-08-2018)

access_log off; # Access log disabled by sincze
#access_log /var/log/nginx/access.log;
#error_log /var/log/nginx/error.log debug; # Debug added by sincze
error_log /var/log/nginx/error.log;
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 1 guest