SIP (VoIP) Monitoring for incoming calls using MQTT

this is the log from DSS notifier pjsip

Starting SIP Client and calling 'sip:[email protected]'...
15:45:48.574         os_core_unix.c !pjlib 2.8 for POSIX initialized
15:45:48.574         sip_endpoint.c  .Creating endpoint instance...
15:45:48.574                  pjlib  .select() I/O Queue created (0x563b6c394a70)
15:45:48.574         sip_endpoint.c  .Module "mod-msg-print" registered
15:45:48.574        sip_transport.c  .Transport manager created.
15:45:48.574           pjsua_core.c  .PJSUA state changed: NULL --> CREATED
15:45:48.583           pjsua_core.c  .pjsua version 2.8 for Linux-4.15.0.58/x86_64 initialized
15:45:48.583            pjsua_app.c  .Turning sound device -99 -99 ON
15:45:48.583                 main.c  Ready: Success
15:45:48.697            pjsua_app.c  .......Call 0 state changed to CALLING
>>>>
Account list:
  [ 0] <sip:172.30.33.18:5060>: does not register
       Online status: Online
  [ 1] <sip:172.30.33.18:5060;transport=TCP>: does not register
       Online status: Online
 *[ 2] sip:[email protected]: does not register
       Online status: Online
Buddy list:
 [ 1] <?>  sip:[email protected]

Maybe @MartyTremblay can say something about this problem?

Looks to me that 3cx needs a ring group of 2 extensions. The first for your phone, the second configured to be connected with sip2mqtt. When someone calls, both extensions should “ring” which would make 3cx not go straight to busy.

Hello,

I’ve been trying out the great @MartyTremblay docker using @raphii’s add-on structure.

I’ve been able to solve an issue with one of the voip providers I use, it constantly failed registration with error 407 (Proxy Authentication Required). After a lot of trial and error (lots of) I’ve found out that changing a parameter in the sip2mqtt.py script solved all my registration problems:

in Marty’s script at line 183 there is this

acc_cfg.auth_cred = [ pj.AuthCred(args.sip_domain, args.sip_username, args.sip_password) ]

the first parameter in the auth_cred list is the realm, which I found in a lot of cases is set as “*” instead of as the value of the domain

so I changed it like this

acc_cfg.auth_cred = [ pj.AuthCred(“*”, args.sip_username, args.sip_password) ]

From this moment on, all my voip providers work, I was also able to connect to my pbx (Yeastar S20), which initially failed miserably with error 401; unfortunately it doesn’t seem to work perfectly, because it doesn’t trigger any action in the script when an incoming call happens, but this is for another day.

Hope this helps someone down the road.

Ciao

Claudio

Hey, this is a great effort, huge thanks to @MartyTremblay, @CiBi69, @raphii, @ntuseracc for your valueable contributions.

I’m using it successfully with voip.ms.

For anyone still paying attention:

  • does not seem to work with Grandstream PBX which is Asterix-based. Always get 401 unauthorized. I have not tried the edits suggested most recently by @CiBi69, but I will and will report back.

  • Basically what I am looking for is advanced callerID, similarly to other users, I use IVRs to answer the phone. With voip.ms, you can pair this script with a subaccount, add it into a ring group with your main account, and then both will register the call at the same time. The issue I’m having is the pbx answers the call pretty much instantly, so the caller ID is only displayed in hass for a brief moment. Anyone know how to retain and display the last caller?

  • This gives us the caller ID, but it does not give us the number that was dialed. If I point a bunch of DIDs at it, I would be interesting in comparing how many calls are made to each DID. I would prefer not to have to run a bunch of copies of the container! An example output would be comparing how many calls came in locally compared to 1-800.

  • Has anyone done anything creative with the data in HomeAssistant?

Nice, will try to use it simply with an existing fritzbox which is used for my doorbell (Doorline Slim). The doorbell works like an analog a/b phone and utilize sip2mqtt will enable home assistant to easily send push notifications including a still image from the surveillance cam!

1 Like

Hi @raphii - I get:

20-05-12 22:41:14 INFO (SyncWorker_5) [supervisor.docker.addon] Start build bccff8de/armv7-addon-sip2mqtt:beta
20-05-12 22:41:22 ERROR (SyncWorker_5) [supervisor.docker.addon] Can’t build bccff8de/armv7-addon-sip2mqtt:beta: The command ‘/bin/ash -o pipefail -c apk add --no-cache python2 py2-paho-mqtt bash curl wget tar && curl -L https://raw.githubusercontent.com/MartyTremblay/sip2mqtt/master/sip2mqtt.py -o sip2mqtt.py && apk add --no-cache --virtual .build4pjsip alpine-sdk && apk add --no-cache libsrtp-dev python2-dev openssl-dev opus-dev && cd && wget -qnv “http://www.pjsip.org/release/2.7.2/pjproject-2.7.2.tar.bz2” -O - | tar xjf - && cd pjproject-2.7.2 && ./configure --with-external-srtp --enable-shared --disable-sound --disable-oss --disable-sdl --disable-speex-aec --disable-video --prefix=/usr/local > /dev/null && make dep && make && make install && cd pjsip-apps/src/python && make && make install && cd && rm -rf pjproject-2.7.2 && apk del .build4pjsip’ returned a non-zero code: 1

I tried to install the addon and it failed. The log shows:

‘20-05-17 09:22:44 ERROR (SyncWorker_14) [supervisor.docker.addon] Can’t build 7d3aa1ca/amd64-addon-sip2mqtt:beta: The command ‘/bin/ash -o pipefail -c apk add --no-cache python2 py2-paho-mqtt bash curl wget tar && curl -L https://raw.githubusercontent.com/MartyTremblay/sip2mqtt/master/sip2mqtt.py -o sip2mqtt.py && apk add --no-cache --virtual .build4pjsip alpine-sdk && apk add --no-cache libsrtp-dev python2-dev openssl-dev opus-dev && cd && wget -qnv “http://www.pjsip.org/release/2.7.2/pjproject-2.7.2.tar.bz2” -O - | tar xjf - && cd pjproject-2.7.2 && ./configure --with-external-srtp --enable-shared --disable-sound --disable-oss --disable-sdl --disable-speex-aec --disable-video --prefix=/usr/local > /dev/null && make dep && make && make install && cd pjsip-apps/src/python && make && make install && cd && rm -rf pjproject-2.7.2 && apk del .build4pjsip’ returned a non-zero code: 1’

I am running ha on a synology system. Using a docker image.

Greetz!

I’d love to hear how this went. This seems ideal for a video doorbell integration to one that supports SIP.

Hi Raphael,

I tried to install the add-on and it just says “Failed to install addon, Unknown Error, see logs”.

In the logs:

20-09-01 20:17:43 INFO (MainThread) [supervisor.addons] Create Home Assistant add-on data folder /data/addons/data/7d3aa1ca_sip2mqtt
20-09-01 20:17:43 INFO (SyncWorker_0) [supervisor.docker.addon] Start build 7d3aa1ca/armv7-addon-sip2mqtt:beta
20-09-01 20:18:07 ERROR (SyncWorker_0) [supervisor.docker.addon] Can't build 7d3aa1ca/armv7-addon-sip2mqtt:beta: The command '/bin/ash -o pipefail -c apk add --no-cache python2 py2-paho-mqtt bash curl wget tar     && curl -L https://raw.githubusercontent.com/MartyTremblay/sip2mqtt/master/sip2mqtt.py -o sip2mqtt.py     && apk add --no-cache --virtual .build4pjsip alpine-sdk     && apk add --no-cache libsrtp-dev python2-dev openssl-dev opus-dev     && cd     && wget -qnv "http://www.pjsip.org/release/2.7.2/pjproject-2.7.2.tar.bz2" -O - | tar xjf -     && cd pjproject-2.7.2     && ./configure --with-external-srtp --enable-shared --disable-sound --disable-oss --disable-sdl --disable-speex-aec --disable-video --prefix=/usr/local > /dev/null     && make dep     && make     && make install     && cd pjsip-apps/src/python     && make     && make install     && cd     && rm -rf pjproject-2.7.2     && apk del .build4pjsip' returned a non-zero code: 1

Edit:
Some more info:
System: HassOS 4.12
Supervisor: 235
Home Assistant Core Version: 0.114.0
Raspberry Pi 4 with 4 GB RAM

I get my pi 4 this weekend, i will test it :slight_smile:

Pretty sure this happens because the docker script is trying to build an x86 version of pjsip. Being a Raspberry Pi, we’d would have to change the configure command to build an ARM version of the binary. Any volunteers?

More specifically, https://trac.pjsip.org/repos/wiki/Getting-Started/Autoconf#CrossCompilation

Hello can you please take a look of this issue
Unable to install this sddon on hassio · Issue #10 · raph2i/hassio-addons (github.com)

Thank you and best regards

Looks like pjsip has removed version 2.7.2 and the URL is now a 404. Version 2.10 seems to be the latest…

I’m working on a fix along with other enhancements. You can track the progress on the https://github.com/raph2i/hassio-addons/issues/10 ticket

Hi all,

Forgot to mention that I have provided a few fixes to @raphii 's add-on and these have been merged since. https://github.com/raph2i/hassio-addons/pull/11/commits

Let us know whether this resolves your issues.

Never would have thought of that, but that’s pretty dang neat! Nice job

@derdude41065, did you ever get this to work with fritzbox? In my case sip2mqtt seems to register the sip extension just fine, but I do not see incoming calls in the protocol of sip2mqtt, nor the MQTT sensor is showing any change. sip2mqtt protocol:

04/27/2021 08:18:03 AM - INFO - -- Registration Complete --
04/27/2021 08:18:03 AM - INFO - SIP: Status = 100 (In Progress)
04/27/2021 08:18:03 AM - INFO - SIP: Registration complete, status=200 (OK)
04/27/2021 08:18:04 AM - INFO - MQTT: Connected with the broker...

If I place a call to the extension where sip2mqtt says it is registered to, I get the following log entry in fritzbox:
27.04.21 08:21:00 Internettelefonie mit tuerklingel über 172.30.xxx.xxx:5060 war nicht erfolgreich. Ursache: (408)
In Englisch: Internet call with device tuerklingel via IP was not successfull.

Does anybody have an idea what I am doing wrong?

@enjoysimpson
Yes, just played around this weekend and get this up and running. In my case it was a NAT issue and could be easily fixed. Just allow contact rewrite, referng line 184 from sip2mqtt/sip2mqtt.py at d4aa6eea3435c459856eacf69347de8d2203bbbd · MartyTremblay/sip2mqtt · GitHub

Change:
acc_cfg.allow_contact_rewrite = False

to

acc_cfg.allow_contact_rewrite = True