Home of the Squeezebox™ & Transporter® network music players.
Page 2 of 9 FirstFirst 1234 ... LastLast
Results 11 to 20 of 90
  1. #11
    Senior Member
    Join Date
    Mar 2014
    Posts
    234
    Yes sorry, this is my code :

    Code:
    package Plugins::Jeedom::Plugin;
    
    use strict;
    
    use base qw(Slim::Plugin::Base);
    
    use Plugins::Jeedom::Settings;
    use Slim::Music::Info;
    use Slim::Utils::Misc;
    use Slim::Utils::Network;
    use Slim::Player::Player;
    use Slim::Player::Client;
    use Slim::Player::Sync;
    
    use Scalar::Util qw(blessed);
    
    use Slim::Control::Request;
    
    use Slim::Utils::Log;
    
    use Slim::Utils::Prefs;
    
    use Slim::Utils::Strings qw(string);
    
    my $jeedomipaddress;
    my $jeedomapi;
    
    my $prefs = preferences('plugin.jeedom');
    
    our @browseMenuChoices;
    
    my $log = Slim::Utils::Log->addLogCategory({
    	'category'     => 'plugin.jeedom',
    	'defaultLevel' => 'INFO',
    #	'defaultLevel' => 'DEBUG',
    	'description'  => getDisplayName(),
    });
    
    sub getDisplayName {
    	return 'PLUGIN_JEEDOM';
    }
    
    sub myDebug {
    	my $msg = shift;
    	my $lvl = shift;
    	
    	if ($lvl eq "")
    	{
    		$lvl = "debug";
    	}
    
    	
    	$log->$lvl("*** Jeedom *** $msg");
    }
    
    sub initPlugin {
    
    	$jeedomipaddress =	$prefs->get('address');
    	$jeedomapi  =	$prefs->get('user');
        
    	my $class = shift;
    	
    	myDebug("Initializing");
    		
    	$class->SUPER::initPlugin();
    
    	Plugins::Jeedom::Settings->new;
    	
    	Slim::Control::Request::subscribe( \&commandCallbackVolume, [['mixer']]);
        
    }
    
    sub shutdownPlugin {
    
    	Slim::Control::Request::unsubscribe(\&commandCallbackVolume);
        
    
    }
    
    sub commandCallbackVolume {
    	my $request = shift;
    
    	my $client = $request->client();
    	if( !defined( $client)) {
    		return;
    	}
    		
    	my $iPower = $client->power();
    
    	if( $request->isCommand([['mixer'], ['volume']])  ) {
    		if($iPower ==  1) {
    			
    			my $iVolume = $client->volume();			
    my $mac = ref($client) ? $client->macaddress() : $client;
    
    $log->error("Couldn't find requested entry: $jeedomapi $jeedomipaddress $mac $iVolume");
    
    
    my $http = Slim::Networking::SimpleAsyncHTTP->new(\&exampleCallback,
    	\&exampleErrorCallback, 
    	{
                            client => $client, 
                            
                    });
    
            $http->post("$jeedomipaddress/core/api/jeeApi.php?api=$jeedomapi&type=squeezebox&adress=$mac&logicalId=volume2&value=$iVolume");
    		
    		 	
    		}
    	}	
    }
    
    
    sub exampleCallback {
    
    }
    
    sub exampleErrorCallback {
    
    
    
    }
    1;
    I try to send some data to my home automation system. So i subscribe to volume change and send volume level.

    Thank for your help.

  2. #12
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,323

    SimpleAsyncHTTP Problem

    > $http->post("$jeedomipaddress/core/api/jeeApi.php?api=$jeedomapi&type=squeezebox&adress=$ mac&logicalId=volume2&value=$iVolume");

    Most likely POSTing a request with the parameters in the query string is
    not accepted by your automation system. You either have to POST the
    data, or use $http->get(...) instead.

    > sub exampleCallback {
    >
    > }
    >
    > sub exampleErrorCallback {
    >
    > }


    Add a "print Data:ump::dump($_[0|);" to these two handlers. It will
    print the response of the http request to the server.log file.

    --

    Michael

  3. #13
    Senior Member
    Join Date
    Mar 2014
    Posts
    234
    If i add : print Data::dump::dump($_[0|); the plugin won't start

    My home automation system only allow posting data with the url : ip_adress/core/api/jeeApi.php?api=api_key&type=squeezebox&adress=mac_ adress&logicalId=volume2&value=volume_value

    Is there a simple way to call that url ?

  4. #14
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,323

    SimpleAsyncHTTP Problem

    > If i add : print Data::dump::dump($_[0|); the plugin won't start

    Stupid forums software: it replaced the uppercase D for the first Dump
    with a smiley... just change that to uppercase (only the first Dump!),
    and it should work.

    > My home automation system only allow posting data with the url :
    > ip_adress/core/api/jeeApi.php?api=api_key&type=squeezebox&adress=mac_ adress&logicalId=volume2&value=volume_value


    But that's not a POST request, but rather a GET request. See my previous
    response.

    http://en.wikipedia.org/wiki/POST_(HTTP) (and links for GET on the right
    hand side)

    --

    Michael

  5. #15
    Senior Member
    Join Date
    Mar 2014
    Posts
    234
    New error with Dump :

    Code:
    15-03-30 09:37:58.0944] Slim::Utils::Misc::msg (1220) Warning: [09:37:58.0939] Number found where operator expected at C:/PROGRA~2/SQUEEZ~1/server/Plugins/Jeedom/Plugin.pm line 174, near "1"
    [15-03-30 09:37:58.0949] Slim::Utils::Misc::msg (1220) Warning: [09:37:58.0946] 	(Missing semicolon on previous line?)
    [15-03-30 09:37:58.0956] Slim::bootstrap::tryModuleLoad (286) Warning: Module [Plugins::Jeedom::Plugin] failed to load:
    syntax error at C:/PROGRA~2/SQUEEZ~1/server/Plugins/Jeedom/Plugin.pm line 164, near "|)"
    syntax error at C:/PROGRA~2/SQUEEZ~1/server/Plugins/Jeedom/Plugin.pm line 170, near "|)"
    Missing right curly or square bracket at C:/PROGRA~2/SQUEEZ~1/server/Plugins/Jeedom/Plugin.pm line 174, at end of line
    Compilation failed in require at (eval 1469) line 2.
    BEGIN failed--compilation aborted at (eval 1469) line 2.
    This is my code :

    Code:
    sub commandCallbackVolume {
    	my $request = shift;
    
    	my $client = $request->client();
    	if( !defined( $client)) {
    		return;
    	}
    		
    	my $iPower = $client->power();
    
    	if( $request->isCommand([['mixer'], ['volume']])  ) {
    		if($iPower ==  1) {
    			
    			my $iVolume = $client->volume();			
    my $mac = ref($client) ? $client->macaddress() : $client;
    
    $log->error("Couldn't find requested entry: $mac");
    
    my $http = Slim::Networking::SimpleAsyncHTTP->new(\&getProxyResponse, \&gotErrorViaHTTP, {
                            client => $client, 
                            
                    });
    
            $http->get("$jeedomipaddress/core/api/jeeApi.php?api=$jeedomapi&type=squeezebox&adress=$mac&logicalId=volume2&value=$iVolume");
    		
    		 	
    		}
    	}	
    }
    
    
    sub getProxyResponse {
    
    print Data::Dump::dump($_[0|);
    
    }
    
    sub gotErrorViaHTTP {
    
    print Data::Dump::dump($_[0|);
    
    }
    
    1;
    So GET is the method to pass data on the url, like on php ? I try $http->get but still no data on my home automation (when i use url directly on chrome, it's work on my home automation side).

    Thank for your help.

  6. #16
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,323

    SimpleAsyncHTTP Problem

    > 15-03-30 09:37:58.0944] Slim::Utils::Misc::msg (1220) Warning: [09:37:58.0939] Number found where operator expected at C:/PROGRA~2/SQUEEZ~1/server/Plugins/Jeedom/Plugin.pm line 174, near "1"
    > [15-03-30 09:37:58.0949] Slim::Utils::Misc::msg (1220) Warning: [09:37:58.0946] (Missing semicolon on previous line?)


    Oops... sorry. Another typo. Make sure you close the square brackets in
    the dump($_[0]) call.

    > So GET is the method to pass data on the url, like on php ? I try


    This has nothing to do with PHP or Perl. GET and POST are only two of
    the http methods (did you check that wikipedia link I posted?). GET is
    the way to pass parameters right there in the address. POST would send
    them after the headers as the request body. What you need to use, I
    don't know. This would probably be documented in your automation system
    documentation. If you need to use GET in PHP, then you'll need to use
    GET in Perl, too.

    --

    Michael

  7. #17
    Senior Member
    Join Date
    Mar 2014
    Posts
    234
    >Oops... sorry. Another typo. Make sure you close the square brackets in
    >the dump($_[0]) call.

    Ok everything start normally but no message inside log when i change volume.

    >This has nothing to do with PHP or Perl. GET and POST are only two of
    >the http methods (did you check that wikipedia link I posted?). GET is
    >the way to pass parameters right there in the address. POST would send
    >them after the headers as the request body. What you need to use, I
    >don't know. This would probably be documented in your automation system
    >documentation. If you need to use GET in PHP, then you'll need to use
    >GET in Perl, too.

    Ok i understand. So i must use GET because the parameters must be in the url adress. Maybe my code isn't good for using GET ? When i use $http->get no error messages and no data send to my HA system.

  8. #18
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,323

    SimpleAsyncHTTP Problem

    > Ok everything start normally but no message inside log when i change
    > volume.


    How do you expect anyone to help you with your coding problems without
    actually seeing your code?

    --

    Michael

  9. #19
    Senior Member
    Join Date
    Mar 2014
    Posts
    234
    Yes right

    So this is my basic.html :

    Code:
    [% PROCESS settings/header.html %]
    
    	[% WRAPPER settingSection %]
    		[% WRAPPER settingGroup title="SETUP_GROUP_JEEDOM" desc="" %]
    					<table border="0" cellspacing="3" cellpaddding="3">
    
    			<tr>
    				<td><label for="pref_address">[% "SETUP_JEEDOMIPADDRESS" | string %]</label>
    					<input type="text" class="stdedit" name="pref_address" id="jeedomipaddress" value="[% prefs.pref_address %]" size="20">
    				</td>
                    
                    <td><label for="pref_user">[% "SETUP_JEEDOMAPI" | string %]</label>
    					<input type="text" class="stdedit" name="pref_user" id="jeedomapi" value="[% prefs.pref_user %]" size="20">				 				            </td>
                    
    			</tr>
    
    		</table>
    		[% END %]
    
    	[% END %]
    
    [% PROCESS settings/footer.html %]
    My Settings.pm :

    Code:
    package Plugins::Jeedom::Settings;
    
    use strict;
    use base qw(Slim::Web::Settings);
    use Slim::Utils::Prefs;
    use Slim::Utils::Log;
    
    # Used for logging.
    my $log = Slim::Utils::Log->addLogCategory({
    	'category'     => 'plugin.jeedom',
    	'defaultLevel' => 'INFO',
    #	'defaultLevel' => 'DEBUG',
    	'description'  => 'Jeedom Settings',
    });
    
    
    
    # my own debug outputer
    sub myDebug {
    	my $msg = shift;
    	
    	$log->info("*** Jeedom - Settings *** $msg");
    }
    
    my $prefs = preferences('plugin.jeedom');
    
    sub name {
    	return Slim::Web::HTTP::CSRF->protectName('PLUGIN_JEEDOM_DESC2');
    }
    
    
    sub page {
    	return Slim::Web::HTTP::CSRF->protectURI('plugins/Jeedom/settings/basic.html');
    }
    
    
    
    
    sub prefs {
    	return ($prefs, qw(address user) );
    }
    
    1;
    And finally my Plugin.pm :

    Code:
    package Plugins::Jeedom::Plugin;
    
    # HelloWorld tutorial plugin by Mitch Gerdisch
    # Meant to be a way of figuring out and understanding how plugins need to be written for SC7.
    # There are 4 basic components that need to be written for SC7 plugins:
    #	Plugin.pm - This is the main processing bit of the plugin and not much different than pre-SC7 plugin code.
    #				But, there are differences.
    #	Settings.pm - This file contains perl code for processing the web page used to set the settings for the plugin.
    #	strings.txt - Where all the strings are stored - including their various lanuage equivalents.
    #	basic.html - This is a file under HTML/<language abbrev.>/plugins/<plugin name>/settings/. It contains 
    #				 HTML-like stuff for displaying the plugin's web user interface.
    
    # This code is derived from code with the following copyright message:
    #
    # SqueezeCenter Copyright 2001-2007 Logitech.
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License,
    # version 2.
    
    # required bit
    use strict;
    
    # required bit
    use base qw(Slim::Plugin::Base);
    
    # Plugin specific bit - put name of plugin where HelloWorld is.
    # This points to the Settings.pm file that you also need to create/update for the plugin.
    use Plugins::Jeedom::Settings;
    use Slim::Music::Info;
    
    use Slim::Utils::Misc;
    use Slim::Utils::Network;
    
    
    
    use Slim::Player::Player;
    use Slim::Player::Client;
    use Slim::Player::Sync;
    # Might be required. At least it's not bad to include it.
    use Scalar::Util qw(blessed);
    
    # Might be required. Not sure, but again it doesn't hurt.
    use Slim::Control::Request;
    
    # MUST HAVE: This log bit is new and allows one to use nicer logging facilities than were available pre-SC7
    use Slim::Utils::Log;
    
    # MUST HAVE: magical preferences getting stuff
    use Slim::Utils::Prefs;
    
    # MUST HAVE: provides the strings functionality that uses the strings.txt file to present the correct language
    use Slim::Utils::Strings qw(string);
    
    my $jeedomipaddress;
    my $jeedomapi;
    # So, get the data related to this plugin.
    # The call to preferences() will be "plugin.<plugin name in lowercase>
    # Something that might be interesting, there's actually a prefs file for each plugin.
    # On Windows its stored in documents and settings/all users/application data/squeezecenter/prefs.
    # You can look at it (it's a text file) and see what is being currently stored.
    # However, there seems to be a lag between doing a set and it actually showing up in the file, fyi.
    my $prefs = preferences('plugin.jeedom');
    
    # Any global variables? Go ahead and declare and/or set them here
    our @browseMenuChoices;
    
    # used for logging
    # To debug, run squeezecenter.exe from the command prompt as follows:
    # squeezecenter.exe --debug plugin.<plugin name>=<logging level in caps>
    # Log levels are DEBUG, INFO, WARN, ERROR, FATAL where a level will include messages for all levels to the right.
    # So, squeezecenter.exe --debug plugin.helloworld=INFO,persist will show all messages fro INFO, WARN, ERROR, and FATAL.
    # The "persist" bit of text allows the system to remember that logging level between invocations of squeezecenter.
    my $log = Slim::Utils::Log->addLogCategory({
    	'category'     => 'plugin.jeedom',
    	'defaultLevel' => 'INFO',
    #	'defaultLevel' => 'DEBUG',
    	'description'  => getDisplayName(),
    });
    
    # This is an old friend from pre-SC7 days
    # It returns the name to display on the squeezebox
    sub getDisplayName {
    	return 'PLUGIN_JEEDOM';
    }
    
    # I have my own debug routine so that I can add the *** stuff easily.
    sub myDebug {
    	my $msg = shift;
    	my $lvl = shift;
    	
    	if ($lvl eq "")
    	{
    		$lvl = "debug";
    	}
    
    	
    	$log->$lvl("*** Jeedom *** $msg");
    }
    
    # Another old friend from pre-SC7 days.
    # This is called when SC loads the plugin.
    # So use it to initialize variables and the like.
    sub initPlugin {
    
    	$jeedomipaddress =	$prefs->get('address');
    	$jeedomapi  =	$prefs->get('user');
        
    	my $class = shift;
    	
    	myDebug("Initializing");
    		
    	$class->SUPER::initPlugin();
    
    	Plugins::Jeedom::Settings->new;
    	
    	Slim::Control::Request::subscribe( \&commandCallbackVolume, [['mixer']]);
        
    
    
    }
    
    sub shutdownPlugin {
    
    	Slim::Control::Request::unsubscribe(\&commandCallbackVolume);
        
    
    }
    
    
    
    sub commandCallbackVolume {
    	my $request = shift;
    
    	my $client = $request->client();
    	if( !defined( $client)) {
    		return;
    	}
    		
    	my $iPower = $client->power();
    
    	if( $request->isCommand([['mixer'], ['volume']])  ) {
    		if($iPower ==  1) {
    			
    			my $iVolume = $client->volume();			
    my $mac = ref($client) ? $client->macaddress() : $client;
    
    $log->error("Couldn't find requested entry: $jeedomapi $jeedomipaddress $mac $iVolume");
    
    
    my $http = Slim::Networking::SimpleAsyncHTTP->new(\&exampleCallback,
    	\&exampleErrorCallback, 
    	{
                            client => $client, 
                            
                    });
    
            $http->post("$jeedomipaddress/core/api/jeeApi.php?api=$jeedomapi&type=squeezebox&adress=$mac&logicalId=volume2&value=$iVolume");
    		
    		 	
    		}
    	}	
    }
    
    
    sub exampleCallback {
    
    }
    
    sub exampleErrorCallback {
    
    
    
    }
    1;
    I don't find where there are bugs

  10. #20
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,323

    SimpleAsyncHTTP Problem

    Your code works perfectly fine for me. Except that you're still doing a
    POST instead of a GET. And still don't have any debug output added to
    the callbacks. And still don't give us any insight into your server.log
    file.

    --

    Michael

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •