poljvd / hyperion-webapp

Colorpicker webapp for Hyperion
19 stars 5 forks source link

Run on Ubuntu? (updated version) #6

Open Fire69 opened 9 years ago

Fire69 commented 9 years ago

Hey there,

A year ago you guys did a great job helping me out with the webapp on Ubuntu (https://github.com/poljvd/hyperion-webapp/issues/2). I hadn't updated it anymore since then, yesterday I noticed the screenshot for the webapp in your wiki was completely different so I wanted to update. But apparently, the code has changed completely? :-)

Would it still be possible to get it working on Ubuntu now? I cloned the repo, and changed the ip's I found in /colourPicker/conf/Configuration.php

But I guess that would have been too easy :-)

bradcornford commented 9 years ago

Hi there,

Yeah the code was completely re-factored in general a while back.

Yes it is possible to get it working on Ubuntu.

Within: /colourPicker/conf/Configuration.php There are a few values you'll need to enter: serverAddress - which can be 127.0.0.1 if the web app is hosted on the same box as the hyperion service. serverController - which can be set for the environment you are using, in your case 'sudo /etc/init.d'

This should then work as expected.

Fire69 commented 9 years ago

Can't get it to work.

With the old version, I had to compile the hyperion-remote on the Ubuntu-machine. Do I still need that now?

In Configuration.php, I set: 'Remote server IP' => 127.0.0.1 'Hyperion IP' => 192.168.1.13 (IP for RasPi) 'System service' => sudo /etc/init.d

When I load the page I get the Hyperion logo and a green 'Turn on' button. That's it.

Any pointers?

bradcornford commented 9 years ago

I'm not sure about the hyperion-remote, but i assume you would still need to do that.

So is the web app deployed on a different server to your RasPi?

In that case, you'll need to set: 'Remote server IP' => '192.168.1.13' 'Hyperion IP' => '127.0.0.1:19444'

When you press the 'Turn On' button, does it work?

Fire69 commented 9 years ago

Not sure what you mean by 'deployed on another server to your pi'... :-)

The webapp is on my Ubuntu (192.168.1.20), which has the hyperion-remote in usr/sbin, and the page is being served by Apache in /var/www/hyperion Hyperion is on my Pi obviously :P (192.168.1.13)

What is the difference between remote server ip and hyperion ip?

bradcornford commented 9 years ago

Sorry, I think I may have been confusing things!

Okay, so in that case, you'll need to set: 'Remote server IP' => '127.0.0.1' 'Hyperion IP' => '192.168.1.13:19444'

So the the remote server is the IP address of the server that has the hyperion remote service on it, the hyperion ip is the server with the hyperion service on it.

Also you will need do the steps on the app page, under the heading 'Required if you are running Raspbian / Debian'

Fire69 commented 9 years ago

Changed the IP's, followed the other instructions, no luck.

Is there actually a functional advantage to using the newer version? If not, I'm staying with the one that's working! :-D

bradcornford commented 9 years ago

Yeah there is a few new functional updates that come with the new version. Such as durations, and effects. If you think they aren't needed feel free to roll back.

Out of interest, does this command work:

hyperion-remote -a 192.168.1.13:19444 -c FF0000

Fire69 commented 9 years ago

Yes, hyperion-remote works, I had to get that working for the old version too :)

I have the old and new in separate folders under /var/www so no need to roll back. If you want me to test more stuff, just let me know :)

bradcornford commented 9 years ago

Okay, so I believe the issue you are facing is because I only re-wrote the script to work correctly when the hyperion remote was running on the same box as the hyperion service. I will take a look into how it can be re-factored to do what you are wanting to do. I'll let you know the progress once done.

bradcornford commented 9 years ago

Okay, I've pushed an update to the develop branch, if you could check it out, and give it a go, it should work.

Fire69 commented 9 years ago

First of all, I'd like to say I really appreciate the time you are putting into this :+1:

So, I deleted my git-folder and recloned it, just to be sure. I then switched to develop, in configuration.php I set Hyperion IP to '192.168.1.13', the remote IP I left at 127.0.0.1, then I updated the sudoers-file.

Still no-go. The page displays, but I only get the 'Turn On' button, which doesn't appear to be doing anything. Is there some log I can check maybe?

bradcornford commented 9 years ago

You can check the php error log, it should be located at /var/log/php5/error.log. This should give you some information if any errors are occurring. You will also need to set the username and password for the connection to the Pi that has hyperion.

Fire69 commented 9 years ago

This gets logged when I load the page:

[Sun Feb 08 21:44:34.879143 2015] [:error] [pid 11121] [client 192.168.1.1:56164] Executing 'hyperion' command to '192.168.1.13': ps aux | grep [h]yperion | awk '{print $11}'
[Sun Feb 08 21:44:34.879379 2015] [:error] [pid 11121] [client 192.168.1.1:56164] Executing 'hyperion' command to '127.0.0.1': /usr/bin/hyperion-remote  --address 192.168.1.13:19444 --list | grep '"priority" : ' | cut -d ':' -f2 | tr '\\n' ','
[Sun Feb 08 21:44:34.929046 2015] [:error] [pid 11121] [client 192.168.1.1:56164] Executing 'hyperion' command to '127.0.0.1': /usr/bin/hyperion-remote  --address 192.168.1.13:19444 --list | grep '"name" : ' | cut -d '"' -f4 | tr '\\n' ','

This gets logged when I click 'Turn on':

[Sun Feb 08 21:44:56.315415 2015] [:error] [pid 22686] [client 192.168.1.1:56202] Executing 'hyperion' command to '192.168.1.13': sudo /etc/init.d/hyperion start , referer: http://domain/hyperion.new/
[Sun Feb 08 21:44:56.315654 2015] [:error] [pid 22686] [client 192.168.1.1:56202] Executing 'hyperion' command to '192.168.1.13': ps aux | grep [h]yperion | awk '{print $11}', referer: http://domain/hyperion.new/
[Sun Feb 08 21:44:56.315784 2015] [:error] [pid 22686] [client 192.168.1.1:56202] Executing 'hyperion' command to '127.0.0.1': /usr/bin/hyperion-remote  --address 192.168.1.13:19444 --list | grep '"priority" : ' | cut -d ':' -f2 | tr '\\n' ',', referer: http://domain/hyperion.new/
[Sun Feb 08 21:44:58.357409 2015] [:error] [pid 22686] [client 192.168.1.1:56202] Executing 'hyperion' command to '127.0.0.1': /usr/bin/hyperion-remote  --address 192.168.1.13:19444 --list | grep '"name" : ' | cut -d '"' -f4 | tr '\\n' ',', referer: http://domain/hyperion.new/

When I set the username for the connection to the pi :

[Sun Feb 08 21:59:44.599894 2015] [:error] [pid 22708] [client 192.168.1.1:57095] Executing 'hyperion' command to '192.168.1.13': ps aux | grep [h]yperion | awk '{print $11}'
[Sun Feb 08 21:59:44.600102 2015] [:error] [pid 22708] [client 192.168.1.1:57095] PHP Fatal error:  Call to undefined function ssh2_auth_password() in /var/www/hyperion.new/colourPicker/lib/RemoteCommand.class.php on line 546
[Sun Feb 08 21:59:46.351290 2015] [:error] [pid 11121] [client 192.168.1.1:57096] Executing 'hyperion' command to '192.168.1.13': ps aux | grep [h]yperion | awk '{print $11}'
[Sun Feb 08 21:59:46.351501 2015] [:error] [pid 11121] [client 192.168.1.1:57096] PHP Fatal error:  Call to undefined function ssh2_auth_password() in /var/www/hyperion.new/colourPicker/lib/RemoteCommand.class.php on line 546

I'm wondering, why would I need to set a username for the connection, since it wasn't necessary in the old version?

bradcornford commented 9 years ago

Okay, from the logs everything seems to be working okay.

Did you set the username and password for the hyperion server in hyperionUsername and hyperionPassword within the colourPicker/conf/Configuration.php?

bradcornford commented 9 years ago

Okay, I just released you updated your message. It looks like the ssh2 package is missing, and needs installing.

Try these steps on your Ubuntu box: sudo apt-get install libssh2-php sudo /etc/init.d/apache2 restart

Fire69 commented 9 years ago

Yeah, sorry, I've been updating the message a little. I first had another error, but realised that was because I didn't put username/password between quotes :)

I installed ssh2, different error now:

[Sun Feb 08 22:39:29.138154 2015] [:error] [pid 18949] [client 192.168.1.1:59466] PHP Fatal error:  Cannot redeclare ssh2_connect() in /var/www/hyperion.new/colourPicker/lib/RemoteCommand.class.php on line 12
bradcornford commented 9 years ago

Okay, that's my bad, I left some debug code in by mistake. You'll need to pull the develop branch again. You can use:

git stash
git fetch --all
git reset --hard origin/develop
git stash pop
Fire69 commented 9 years ago

Victory!!! :-D

bradcornford commented 9 years ago

Great news! Hope your happy with the upgrade!

Fire69 commented 9 years ago

Sure am! :)

I'll do some more thorough testing tomorrow, but seems to be running just fine :+1:

Fire69 commented 9 years ago

Everything is OK, except for 1 thing. Don't know if it's only for my situation though.

Whether or not hyperion is running on the pi, I always get the 'full' page. So when it's not running (which normally wouldn't happen because it's always on) I don't get the 'Turn on' button.

When it IS running, and I press the 'Turn off' button, it does turn off, but I have no way of turning it on again :-P

bradcornford commented 9 years ago

Can you provide a printscteen or something to help me understand the error.

Fire69 commented 9 years ago

Not much to show actually. Whether or not the service on the pi is running, I always get the page you see at https://github.com/tvdzwan/hyperion/wiki/web-app

If the service is running, I can turn it off. But when it's not running, I can't turn it on since the page doesn't show the 'Turn on'-button.

bradcornford commented 9 years ago

Okay, this may have been me being stupid, can you change the serverController to:

'serverController' => '/sbin/initctl',
Fire69 commented 9 years ago

Right, because i have to use the command that's used on the pi to start/stop the service, not on my Ubuntu! :-)

I'm running Osmc, so the command should be 'sudo systemctl' That seems to be working for stopping the service, but after I stop it, I'm left at the same page, so no 'Turn on' button available to start it again.

bradcornford commented 9 years ago

What's the exact start and stop commands you use? I'll get them integrated.

Fire69 commented 9 years ago

Both these seem to work:

When I put "sudo /etc/init.d" or "sudo systemctl" as the servercontroller, both work to stop the service.

So I don't think you need to integrate anything new actually. It's just very strange that I don't get the page with the green 'Turn on' button when the service isn't running.

Fire69 commented 9 years ago

Tested some more. When I set the user/password for the hyperion server to false, I do get the page with the single 'Turn on' button. But it doesn't work obviously, since the connection fails without user/pass. When I set the user/pass back to osmc/osmc and reload the page, I immediately get the full page, even though the service isn't running.

(sorry, I hope it's clear the way I explain it, English is not my native language...)

Fire69 commented 9 years ago

One more question. I just noticed now that there is an inconsistency in the config-file concerning the single and double quotes (' / ") In the comments, you use " but for the actual values, you use ' What should I be using? Maybe this is causing some weird errors?

bradcornford commented 9 years ago

Okay, can you replace the controllerType method in colourPicker/lib/RemoteCommand.class.php with:

protected function controllerType($argument)
    {
        switch ($this->controller) {
            case '/etc/init.d':
            case 'sudo /etc/init.d':
                return sprintf($argument, $this->controller . '/' . self::APPLICATION, '');
                break;
            case 'systemctl';
            case 'sudo systemctl';
                return sprintf($argument, $this->controller, self::APPLICATION);
                break;
            case '/sbin/initctl':
            default:
                return sprintf($argument, $this->controller, self::APPLICATION);
        }
    }

Can you also ssh into you Pi and run the command below, and send me the output when hyperion is both on and off.

ps aux | grep [h]yperion | awk '{print $11}'

Either double or single quotes can be used.

Fire69 commented 9 years ago

Replaced the method, no change in behaviour.

Output when hyperion is running: hyperiond

When it's not running, it returns nothing

bradcornford commented 9 years ago

Okay, I'm a little stumped now if I'm honest! I'll put a box together with OSMC and see if i can get that to work and report back.

Fire69 commented 9 years ago

Don't worry too much about it, this isn't anything urgent/important. It's great you're willing to have a look, but don't make it a priority :-P

PS: Just so you don't lose any more time over this, I couldn't get hyperion working with osmc alpha 4 (alpha 3 works flawlessly).

bradcornford commented 9 years ago

Okay, so i bragged my spare SD card out, and found its broken. So I've ordered another one, as soon as that comes I'll get this tested!

Fire69 commented 9 years ago

I really appreciate all the trouble you're going through to get this working! :+1:

bradcornford commented 9 years ago

I have now setup OSMC with Hyperion and all seems to be working as expected. The only difference is that I have a Windows environment with PHP installed for the Web App. I'm wondering if Ubuntu returns a different response to PHP than windows.

Lets try this, replace this method, in colourPicker/lib/RemoteCommand.class.php:

public function getStatus()
{
$this->executeCommand('ps aux | grep [h]yperion | awk \'{print $11}\'', true);
if ($this->output === null) {
return false;
}
return true;
}

with:

public function getStatus()
{
$this->executeCommand('ps aux | grep [h]yperion | awk \'{print $11}\'', true);
var_dump($this->output);
if ($this->output === null) {
return false;
}
return true;
}

This should print onto the application page. Run the application, pressing the Turn Off/Turn On buttons, and reply with the output that's given.

Fire69 commented 9 years ago

Well, don't know what's going on with my server all of a sudden... Last week everything was still working OK, now I just get the page with the 'Turn on' green button. In the log-file, it's complaining about ssh2

[Wed Feb 25 22:28:47.825873 2015] [:error] [pid 536] [client 192.168.1.1:65290] Executing 'hyperion' command to '192.168.1.13': ps aux | grep [h]yperion | awk '{print $11}'
[Wed Feb 25 22:28:47.892897 2015] [:error] [pid 536] [client 192.168.1.1:65290] PHP Warning:  ssh2_connect(): Error starting up SSH connection(-1): Unable to exchange encryption keys in /var/www/hyperion/colourPicker/lib/RemoteCommand.class.php on line 530
[Wed Feb 25 22:28:47.893084 2015] [:error] [pid 536] [client 192.168.1.1:65290] PHP Warning:  ssh2_connect(): Unable to connect to 192.168.1.13 in /var/www/hyperion/colourPicker/lib/RemoteCommand.class.php on line 530
[Wed Feb 25 22:28:47.893144 2015] [:error] [pid 536] [client 192.168.1.1:65290] PHP Warning:  ssh2_auth_password() expects parameter 1 to be resource, boolean given in /var/www/hyperion/colourPicker/lib/RemoteCommand.class.php on line 537
[Wed Feb 25 22:28:47.893168 2015] [:error] [pid 536] [client 192.168.1.1:65290] PHP Warning:  ssh2_exec() expects parameter 1 to be resource, boolean given in /var/www/hyperion/colourPicker/lib/RemoteCommand.class.php on line 542
[Wed Feb 25 22:28:47.893258 2015] [:error] [pid 536] [client 192.168.1.1:65290] Executing 'hyperion' command to '127.0.0.1': /usr/bin/hyperion-remote  --address 192.168.1.13:19444 --list | grep '"priority" : ' | cut -d ':' -f2 | tr '\\n' ','
[Wed Feb 25 22:28:47.939625 2015] [:error] [pid 536] [client 192.168.1.1:65290] Executing 'hyperion' command to '127.0.0.1': /usr/bin/hyperion-remote  --address 192.168.1.13:19444 --list | grep '"name" : ' | cut -d '"' -f4 | tr '\\n' ','
bradcornford commented 9 years ago

Has the RaspberryPi with Hyperion on changed IP address?

Fire69 commented 9 years ago

No. I tried hyperion-remote -a 192.168.1.13:19444 -c FF0000 and that still works...

bradcornford commented 9 years ago

Have you tried an Apache/nginx restart? Also try an SSH connection from your Ubuntu box to the RaspberryPi manually

Fire69 commented 9 years ago

Apparently something crashed in osmc, although the hyperion-remote worked, I couldn't ssh into the pi... After a reset, the webapp is working again :)

I replaced the method and tested. I stopped the hyperion-service on the pi and opened the webapp. I get the full interface instead of the 'Turn on' button. Output: resource(2) of type (stream) I started the hyperion-service on the pi and opened the webapp. I get the full interface. Output: resource(2) of type (stream) I pressed the 'Turn off' button, Output: resource(4) of type (stream). The hyperion-service stopped on the pi, but I still saw the full page instead of the green 'Turn on' button.

So it seems it can't detect whether the service is running or not.

bradcornford commented 9 years ago

Okay, a bit more debugging is needed...

Replace the same method with this:

public function getStatus()
{
$this->executeCommand('ps aux | grep [h]yperion | awk \'{print $11}\'', true);

stream_set_blocking($this->output, true);
$this->output = stream_get_contents(ssh2_fetch_stream($this->output, SSH2_STREAM_STDIO));
var_dump($this->output);
if ($this->output === null) {
return false;
}
return true;
}
Fire69 commented 9 years ago

Same testing done. I stopped the hyperion-service on the pi and opened the webapp. I get the full interface instead of the 'Turn on' button. Output: string(0) "" I started the hyperion-service on the pi and opened the webapp. I get the full interface. Output: string(10) "hyperiond " I pressed the 'Turn off' button, Output: string(0) "". The hyperion-service stopped on the pi, but I still saw the full page instead of the green 'Turn on' button.