Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Presence and Net::XMPP

by morgon (Priest)
on Apr 19, 2016 at 23:37 UTC ( [id://1160952]=perlquestion: print w/replies, xml ) Need Help??

morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I can't figure out how to set a presence with Net::XMPP...

I have rapsody running on a Raspberry Pi and would like to implement a bot that I can send messages from my phone.

I can indeed send messages but I cannot make my bot become visible in my android app...

This is what I try:

use strict; use Net::XMPP; use Data::Dumper; my $con = new Net::XMPP::Client(); my $status = $con->Connect( hostname => 'mh.com', connectiontype => 'tcpip', ); my @result = $con->AuthSend( hostname => 'mh.com', username => 'pi', password => 'pi' ); $con->PresenceSend(); $con->SetCallBacks( presence=>\&do_presence, message=>\&do_message, ); sub do_presence { my ($id, $presence) = @_; print "Presence\n"; print "From: ", $presence->GetFrom(), "\n"; print "Type: ", $presence->GetType(), "\n"; print "Status: ", $presence->GetStatus(), "\n"; } sub do_message { my($id, $msg)=@_; print "message: ", $msg->GetBody; } while(defined($con->Process())) { }
The output (when no other client is connected) is:
Presence From: pi@mh.com/9b568386-f5e3-46de-bb1d-22f2d861a94a Type: Status:
Actually this is enough to send messages to the bot but the Pi is shown as offline in my Android app.

I assume the problem is the presence...

So when I change the SetPresence-call to this:

$con->PresenceSend( status => "doing nothing at all" );
I get this:
Presence From: pi@mh.com/c577d4e2-c4b3-44b5-b044-d2e7e67b0172 Type: Status: doing nothing at all
So yeah, I can set the status, but what I want to do is set the type, so I try:
$con->PresenceSend( type => "available" );
But now I get:
Presence From: Type: error Status:
So does anybody know how to set a presence of "available" with Net::XMPP?

Many thanks!

Replies are listed 'Best First'.
Re: Presence and Net::XMPP
by NetWallah (Canon) on Apr 20, 2016 at 03:35 UTC
    Just a guess, based on this example posted in the CPAN doc:
    $Pres->SetPresence(TYPE=>"away", StatuS=>"Out for lunch");
    It looks like "TYPE" needs to be in caps.

            This is not an optical illusion, it just looks like one.

      I should have said that I have tried the uppercase variant - that does not matter.

      I guess the weird spelling of "StatuS" is the author's way of telling you that it's case-insensitive.

      I finally figured out what I need, even though I don't totally understand it (that I know hardly anything about the jabber protocol probably does not help).

      This seems to work:

      $con->PresenceSend(type => "unavailable");
      However this does not:
      $con->PresenceSend(type => "available");
      But this does:
      $con->PresenceSend(to => 'mh@mh.com');
      Now my pi-client is green and available on my phone. I can only assume that in the jabber protocol you advertise your availability to certain jids, so leaving "to" out was the problem....

      Strangely enough this does not work either:

      $con->PresenceSend(type => "available", to => 'mh@mh.com');
      But now I can't be bothered anymore.

      I wonder if AnyEvent::XMPP would be a better libary....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1160952]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found