AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
3.94k stars 318 forks source link

Basic SIP server for doorbells #409

Open felipecrs opened 1 year ago

felipecrs commented 1 year ago

This project never stops surprising me. It is like the always missing glue for cameras and smart homes. And I have another suggestion.

An embedded and very basic SIP server that doorbells like Dahua VTO or Hikvision can connect to.

go2rtc has 2-way audio support for doorbells, which is awesome. But that's not enough for a fully functional doorbell setup. In other words, a SIP server is still required even though go2rtc can do 2-way audio.

That's because the doorbell still needs to signal and receive signals to react on certain events like:

In my understanding, if go2rtc could expose a basic SIP server in which the doorbell could connect to, no other project like the Asterisk add-on would be required (Asterisk is VERY hard to manage, and overkill for the purpose).

go2rtc as a SIP server would:

Luckily, there seems to be some good SIP servers written in golang out there:

So, what do you think?

Refs #49

AlexxIT commented 1 year ago

I knows nothing about SIP technologies and didn't have any hardware that using it.

felipecrs commented 1 year ago

That's sad, but thank you.

I know very little of Golang, but nevertheless I'll try to build something.

felipecrs commented 1 year ago

It does not look very difficult according to the examples of https://github.com/emiago/sipgo. However, my doorbell is in a very inaccessible place which makes it very hard for me to work with it.

But I will try to build something when I get a chance.

AlexxIT commented 1 year ago

Can your doorbell works with this integration? https://www.home-assistant.io/integrations/voip/

felipecrs commented 1 year ago

I don't think so. That does not even look like SIP also.

I think that integration only works with the Grandstream conversor for old analog phones.

I don't think that integration talks to the conversor over SIP either. Maybe I'm wrong.


Off topic, SIP itself could be used as a 2-way audio source provider. In fact, even as a video source.

But what I'm suggesting is way simpler than that, which is to make go2rtc to expose a SIP server on port like 5060.

Then I would configure my doorbell to use go2rtc as the SIP server.

On the go2rtc side, apart from exposing the SIP TCP server on port 5060, it would:

I currently use the Asterisk add-on https://github.com/TECH7Fox/asterisk-hass-addons with the SIP card to be able to call with my doorbell from Home Assistant https://github.com/TECH7Fox/sip-hass-card.

Cc @pergolafabio @nanosonde which are the most experienced people I know about SIP.

(Sorry to ping you both, if you don't care about this please unsubscribe)

Any opinion is appreciated. I don't know if the approach I suggest actually makes sense or is feasible. Maybe I'm just crazy.

felipecrs commented 1 year ago

Oh wait! The VoIP integration for Home Assistant seems to be SIP indeed. I'll do some testing with it.

pergolafabio commented 1 year ago

Yes, the voip is indeed a sip, but be careful, it only works with opus codec, and remember to change port to something else then 5060 if you have asterisk running...

But anyway, I don't see the point for calling to HA to speak to assist anyway :-)

AlexxIT commented 1 year ago

But I can easily read code of voip integration and reproduce it with go2rtc. I saw how they accept connection on 5060 port and answer to it.

You right. They using OPUS/48000/2. I can change it to PCM/16000/1

felipecrs commented 1 month ago

As realized in https://github.com/rroller/dahua/issues/359#issuecomment-2139719570, the Dahua VTO is useless when NOT CONNECTED to a SIP server. Even the most basic function of button press event will not work when it's not connected to a SIP server.

I detailed my VTO setup on Home Assistant (https://github.com/felipecrs/dahua-vto-on-home-assistant) and I use go2rtc for 2-way audio communication, but I still need to run the full Asterisk add-on just to have a SIP server for my VTO to connect to and therefore allow me to capture the button press event to run automations on.

After these realizations, just to reiterate, if go2rtc could expose a simple SIP server for the doorbell to connect to, I could get rid of Asterisk in my setup which would make things a lot easier.

felipecrs commented 1 month ago

Can your doorbell works with this integration? https://www.home-assistant.io/integrations/voip/

By the way, I tried making it work with that integration and I could not. No matter what, the doorbell would not connect to it. I don't have much details though.

felipecrs commented 1 month ago

I will try making some tests with:

https://github.com/emiago/sipgo/tree/main/example/register

felipecrs commented 1 month ago

OMG! I can't believe, it worked in the first attempt!

~\repos\sipgo\example\register main ❯ go run ./server -u "8001:somepass" -ip 0.0.0.0:5060
May 30 11:53:33.797517 INF Listening on addr=0.0.0.0:5060
May 30 11:53:42.670412 INF New client registered source=192.168.1.40:5060 username=8001
May 30 11:57:34.866194 WRN Server > SIP request handler not found
May 30 11:57:34.888231 WRN Server > SIP request handler not found
May 30 11:57:34.976455 WRN Server > SIP request handler not found

192.168.1.40 is my VTO. It registered in gosip immediatelly with no issue.

image

And everything worked as expected. The button press event is emitted and I don't need SIP for anything else.

@AlexxIT, it would be awesome if you could bundle this in go2rtc. What do you think?

AlexxIT commented 1 month ago

I'll try when have time for my two doorbells