|
|||||||
Linphone and Raspberry Pi
Время создания: 26.04.2019 14:35
Текстовые метки: raspberry pi, compiling. liblinphone, linphone, python
Раздел: Компьютер - Linux - Сеть в Linux - Телефония, SIP, Asterisk
Запись: xintrea/mytetra_syncro/master/base/1556278540d3wdmk44zh/text.html на raw.github.com
|
|||||||
|
|||||||
Using the raspberry pi for video monitoring The Raspberry PI is a good hardware for making a simple video monitoring device, such as watching at any time what's happening at home, if cats have enough to eat, chicken safe from fox attacks, or simply see at distance what's the weather like. The linphone console tools (linphonec and linphone-daemon) can be used to automatically accept a SIP call with video, so that it becomes possible from Linphone android or iOS app to call home at any time. From a hardware standpoint, a raspberry pi2 is a minimum for a decent image quality. Indeed, video software encoding is a cpu consuming task that a pi 1 can hardly achieve as it doesn't have the NEON (multimedia) instruction set. The PI's camera has excellent quality, however plugging a USB camera can be more interesting as it will provide sound recording thanks to its integrated microphone, which the raspberry doesn't have. An ethernet connection is preferred, though wifi would work decently for video transmission as long as the raspberry is not too far from the wifi router. Displaying the video received by the raspberry is out of this article's scope : we will just focus on the capture, sound and video, as well as the transmission via SIP to another SIP phone. The following section explains how to setup the video monitoring on the raspberry pi. Several options are possible:
We recommend to use Raspbian, as a base installation to run linphone. Since linphone heavily makes uses of dual-stack (ipv6 and ipv4) sockets, it is required to enable ipv6 on the raspberry by doing (as root): echo ipv6 >> /etc/modules And reboot. To be clear, there is absolutely no need to have an IPv6 connection, the concern is only to enable the IPv6 APIs of the kernel (which are compatible with IPv4 operation of course). Using the python wrapper to develop a simple script First of all, you need to install the python wrapper for liblinphone API on your raspberry. You can follow the Linux instructions (there are raspberry pi specifics) from this page . Here's a simple script (a bit more advanced than the sample from the Linphone Python Wrapper page). In addition to the linphone python wrapper, this script uses daemon, so you'll have to install it first: pip install python-daemon Here are the features:
#!/usr/bin/env python First of all, edit the script itself to set which account will be allowed to call your raspberry. For example, I'll allow myself: cam = SecurityCamera(whitelist=['sip:sylvain.berfini@sip.linphone.org']) The script simplifies the configuration of the Linphone SIP account you'll use to contact your raspberry-pi. To configure the account, use the following command: ./linphonecam.py configure_account <username> <password> If you don't have yet a Linphone SIP account, you can create one for free at https://www.linphone.org/free-sip-service.html You're good to go, just call the account used to on the previous configuration step using a Linphone application (or another SIP client) on which you have your whitelisted account configured on: If you want your daemon to be started automatically when your raspberry pi boots, you can use the following script: sudo cp linphonecam /etc/init.d/ Adjust the DIR accordingly (and possibly some other values depending on the name you gave the script): # Provides: linphonecam Finally, apply the changes: sudo update-rc.d linphonecam defaults Compiling linphone on the rasberry pi This procedure is for using the linphone console tools (linphonec, linphonecsh or linphone-daemon) on the raspberry pi. It assumes that the raspberry pi is installed with a Raspbian image.
sudo apt-get install cmake automake autoconf libtool intltool yasm libasound2-dev libpulse-dev libv4l-dev nasm git libglew-dev
git clone git://git.linphone.org/linphone-desktop.git --recursive
cd linphone-desktop
make -j4
Now the software is ready to be used ! First run linphonec once in order to configure your SIP account, so that you can place calls to your raspberry from another place (typically the linphone app on android or iOS!). We recommend to use our free sip.linphone.org service, on which accounts can be created using this online form . cd OUTPUT/no-ui/bin ./linphonec [.....] linphonec> proxy add […enter sip account configuration. You may also, within the linphonec command prompt, set the sound card to use for capturing sound. The raspberry-pi has no microphone, but if your plan is to plug a USB camera onto the raspberry pi, it probably has a built-in microphone. To tell linphonec to use the microphone from the usb camera, use the "soundcard list" and "soundcard use" commands to select the sound card index to use. Now open ~/.linphonerc file with an editor (vim, nano...) in order to tweak a few things:
echocancellation=0 Indeed, echo cancellation is not needed, our raspberry pi has no speaker. No need to spend cpu cycles on this.
size=vga
720p is also possible but the pi2 cpu is a bit too slow for this image format with VP8 codec. svga tends to work not so bad as well.
stun_server=stun.linphone.org You can then launch linphonec in background mode in with auto-answer mode. We assume the current directory is already in the OUTPUT/no-ui/bin directory. export PATH=$PATH:`pwd` Notice the "-d 6 -l /tmp/log.txt" which are there to tell linphonec to output all debug messages into /tmp/log.txt. Looking into this file might be useful should any trouble arrive. To stop it, do: linphonecsh exit In order to have linphonec automatically started when the raspberry boots: you can add this line to /etc/rc.local : export PATH=/home/pi/linphone-desktop/OUTPUT/no-ui/bin:$PATH The lines above assume that your linphone-desktop source tree is in /home/pi/linphone-desktop. Please adapt if it is not the case. Just a final reboot and now you can place calls from your favourite linphone app (mobile or desktop) to your raspberry, by calling its sip address ! If you are using the RaspberryPi Camera, you'll notice it won't show up as a /dev/video entry, thus it won't be available in linphone for use. To fix that, use the following:
sudo bash Sadly, the raspberry loosing the network connectivity is a frequent occurrence. Unfortunately, all that NetworkManager stuff included with Raspbian was designed for Linux workstation or servers, and is not robust to temporary network connectivity losses. They happen quite frequently because of various reasons:
I recommend to plug the DSL box onto a programable power timer so that it is restarted every day : indeed it is not so rare that a DSL box hangs forever and needs a manual reboot. In order to force the raspberry to check the network periodically and force a re-connection, I suggest these two scripts, that can be invoked periodically from cron daemon:
#!/bin/sh
Sadly, the wifi devices and drivers are generally so bad in terms of robustness, that this kind of trick is necessary. #!/bin/sh And here's the crontab file: 5 12 * * * /home/pi/reboot_if_necessary >> /home/pi/reboots.log 2>&1 Use sudo crontab -e to write these lines aboves. This will schedule restart_wlan0_if_necessary.sh every hour, and reboot_if_necessary every day at 12:05. |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|