Hello! I hope everyone is doing good
I have 2 servers
Server-1:asterisk 18.12.1
Server-2: PJSUA2 with python binding
both servers are on the cloud
asterisk server has 2 extensions created
“3000” a sip endpoint
and 1003 (PJSIP)
1- I have written a code (using ChatGPT) to register the 3000 and that is successfully authenticated and registered.
2- trying to add a buddy and then subscribe to the presence state of that buddy
but when I do that asterisk returns 404 not found to the subscribe request.
pythoncode####################################
import pjsua2 as pj
Define a class inheriting from Buddy to handle presence events
class MyBuddy(pj.Buddy):
def init(self, buddy_config, account):
super(MyBuddy, self).init()
self.create(account, buddy_config)
def onBuddyState(self):
buddy_info = self.getInfo()
print(f"Buddy {buddy_info.uri} is now {buddy_info.presStatus.statusText}")
def onRegState(self):
print(f"Registration state changed: {self.getInfo().regStatus.statusText}")
Initialize PJSUA2
def main():
# Create and initialize the Endpoint
ep = pj.Endpoint()
ep.libCreate()
ep_config = pj.EpConfig()
ep.libInit(ep_config)
# Create and configure the transport
transport_config = pj.TransportConfig()
transport_config.port = 5060
ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, transport_config)
# Start the library
ep.libStart()
# Create account without registration
account_config = pj.AccountConfig()
account_config.idUri = "sip:testpresence@199.231.184.220" # Server IP address
account_config.regConfig.registerOnAdd = False
acc = pj.Account()
acc.create(account_config)
# account_config = pj.AccountConfig()
# account_config.idUri = "sip:3000@137.184.234.234" # Your SIP username and server IP
# account_config.regConfig.registrarUri = "sip:137.184.234.234" # Registrar URI
# account_config.sipConfig.authCreds.append(pj.AuthCredInfo("digest", "*", "3000", 0, "Gigaset"))
# acc = MyAccount(account_config)
# Verify and log the buddy URI
buddy_uri = "sip:5004@137.184.234.234" # Buddy URI with server IP
print(f"Adding buddy with URI: {buddy_uri}")
# Add buddy
buddy_config = pj.BuddyConfig()
buddy_config.uri = buddy_uri
buddy = MyBuddy(buddy_config, acc)
# Subscribe to presence
buddy.subscribePresence(True)
print("Press Enter to quit...")
input()
# Clean up
del buddy
del acc
ep.libDestroy()
if name == “main”:
main()
#####################################
here are the logs of python script
root@debian11:~# python3 sip.py
05:25:57.556 os_core_unix.c !pjlib 2.14.1 for POSIX initialized
05:25:57.558 sip_endpoint.c .Creating endpoint instance…
05:25:57.558 pjlib .select() I/O Queue created (0xeceb38)
05:25:57.558 sip_endpoint.c .Module “mod-msg-print” registered
05:25:57.558 sip_transport.c .Transport manager created.
05:25:57.558 pjsua_core.c .PJSUA state changed: NULL → CREATED
05:25:57.558 sip_endpoint.c .Module “mod-pjsua-log” registered
05:25:57.558 sip_endpoint.c .Module “mod-tsx-layer” registered
05:25:57.558 sip_endpoint.c .Module “mod-stateful-util” registered
05:25:57.558 sip_endpoint.c .Module “mod-ua” registered
05:25:57.558 sip_endpoint.c .Module “mod-100rel” registered
05:25:57.558 sip_endpoint.c .Module “mod-pjsua” registered
05:25:57.559 sip_endpoint.c .Module “mod-invite” registered
05:25:57.591 alsa_dev.c …ALSA driver found 19 devices
05:25:57.592 alsa_dev.c …ALSA initialized
05:25:57.592 pjlib …select() I/O Queue created (0xf1e288)
05:25:57.594 sip_endpoint.c .Module “mod-evsub” registered
05:25:57.594 sip_endpoint.c .Module “mod-presence” registered
05:25:57.594 sip_endpoint.c .Module “mod-mwi” registered
05:25:57.594 sip_endpoint.c .Module “mod-refer” registered
05:25:57.594 sip_endpoint.c .Module “mod-pjsua-pres” registered
05:25:57.594 sip_endpoint.c .Module “mod-pjsua-im” registered
05:25:57.594 sip_endpoint.c .Module “mod-pjsua-options” registered
05:25:57.594 pjsua_core.c .1 SIP worker threads created
05:25:57.595 pjsua_core.c .pjsua version 2.14.1 for Linux-5.10.0.16/x86_64/glibc-2.31 initialized
05:25:57.595 pjsua_core.c .PJSUA state changed: CREATED → INIT
05:25:57.596 pjsua_core.c SIP UDP socket reachable at 199.231.184.220:5060
05:25:57.596 udp0xf1b860 SIP UDP transport started, published address is 199.231.184.220:5060
05:25:57.596 pjsua_core.c PJSUA state changed: INIT → STARTING
05:25:57.596 sip_endpoint.c .Module “mod-unsolicited-mwi” registered
05:25:57.596 pjsua_core.c .PJSUA state changed: STARTING → RUNNING
05:25:57.596 pjsua_acc.c Adding account: id=sip:testpresence@199.231.184.220
05:25:57.596 pjsua_acc.c .Account sip:testpresence@199.231.184.220 added with id 0
Adding buddy with URI: sip:5004@137.184.234.234
05:25:57.596 pjsua_pres.c Adding buddy: sip:5004@137.184.234.234
05:25:57.596 pjsua_pres.c .Buddy 0 added.
05:25:57.596 pjsua_pres.c …Buddy 0: updating presence…
05:25:57.597 pjsua_pres.c .Buddy 0: updating presence…
05:25:57.597 pjsua_pres.c …Buddy 0: subscribing presence,using account 0…
05:25:57.597 pjsua_core.c …TX 597 bytes Request msg SUBSCRIBE/cseq=15027 (tdta0xf530e8) to UDP 137.184.234.234:5060:
SUBSCRIBE sip:5004@137.184.234.234 SIP/2.0
Via: SIP/2.0/UDP 199.231.184.220:5060;rport;branch=z9hG4bKPjpgoCkRKxxVC6utfZqHqy2Nz9kRpxe69l
Max-Forwards: 70
From: sip:testpresence@199.231.184.220;tag=hpkt2-BA5BDobSnPAY-i69Mwmhr-WTti
To: sip:5004@137.184.234.234
Contact: sip:testpresence@199.231.184.220:5060;ob
Call-ID: 8.GCPZlPE5BgfRKiDQcPz4pNYhq0fbhR
CSeq: 15027 SUBSCRIBE
Event: presence
Expires: 600
Supported: replaces, 100rel, timer, norefersub, trickle-ice
Accept: application/pidf+xml, application/xpidf+xml
Allow-Events: presence, message-summary, refer
Content-Length: 0
–end msg–
05:25:57.597 evsub0xf36558 …Subscription state changed NULL → SENT
05:25:57.597 pjsua_pres.c …Presence subscription to sip:5004@137.184.234.234 is SENT
Buddy sip:5004@137.184.234.234 is now ?
Press Enter to quit…
05:25:57.670 pjsua_core.c .RX 494 bytes Response msg 404/SUBSCRIBE/cseq=15027 (rdata0xf32a28) from UDP 137.184.234.234:5060:
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 199.231.184.220:5060;branch=z9hG4bKPjpgoCkRKxxVC6utfZqHqy2Nz9kRpxe69l;received=199.231.184.220;rport=5060
From: sip:testpresence@199.231.184.220;tag=hpkt2-BA5BDobSnPAY-i69Mwmhr-WTti
To: sip:5004@137.184.234.234;tag=as37cdb42f
Call-ID: 8.GCPZlPE5BgfRKiDQcPz4pNYhq0fbhR
CSeq: 15027 SUBSCRIBE
Server: VitalPBX
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0
–end msg–
05:25:57.670 evsub0xf36558 …Subscription state changed SENT → TERMINATED
05:25:57.670 pjsua_pres.c …Presence subscription to sip:5004@137.184.234.234 is TERMINATED
05:25:57.670 pjsua_pres.c …Resubscribing buddy id 0 in 301312 ms (reason: Not Found)