Hide last authors
Simon Morlat 1.1 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
Simon Morlat 15.2 2 {{toc/}}
Simon Morlat 1.1 3 {{/box}}
4
Simon Morlat 20.1 5 = =
Peio Rigaux 14.3 6
Simon Morlat 2.1 7 = Using the raspberry pi for video monitoring =
Simon Morlat 1.1 8
SandrineAvakian 3.1 9 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.
Simon Morlat 1.1 10
SandrineAvakian 3.1 11 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.
Simon Morlat 1.1 12
Simon Morlat 2.1 13 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.
Simon Morlat 1.1 14
SandrineAvakian 3.1 15 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.
Simon Morlat 1.1 16
Sylvain Berfini 3.2 17 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.
Simon Morlat 1.1 18
jehan monnier 13.1 19 The following section explains how to setup the video monitoring on the raspberry pi by compilation on the raspberry to use linphone console tools directly
Simon Morlat 1.1 20
Simon Morlat 6.1 21 == Prequisites ==
22
23 We recommend to use Raspbian, as a base installation to run linphone.
24
Simon Morlat 15.2 25 The procedure was lastly tested on Raspbian 10.4 (August 2020).
Simon Morlat 6.1 26
Sylvain Berfini 3.2 27 == Compiling linphone on the rasberry pi ==
Simon Morlat 1.1 28
Simon Morlat 8.2 29 This procedure is for using the linphone console tools (linphonec, linphonecsh or linphone-daemon) on the raspberry pi.
Simon Morlat 1.1 30
Simon Morlat 8.2 31 **It assumes that the raspberry pi is installed with a Raspbian image**.
Simon Morlat 1.1 32
Simon Morlat 8.2 33 * Install build dependencies from raspbian repositories
Simon Morlat 1.1 34
Simon Morlat 1.5 35 {{code language="sh"}}
Simon Morlat 18.1 36 sudo apt install cmake automake autoconf libtool intltool yasm libasound2-dev libpulse-dev libv4l-dev nasm git libglew-dev
Simon Morlat 1.5 37 {{/code}}
Simon Morlat 1.1 38
Simon Morlat 22.1 39 * Clone the linphone-sdk git repository on its latest stable branch (as of 2021/04/02 it is //release/4.5//). This repository comprises the liblinphone source code plus all required dependencies, with an overall build script that builds everything in order. The console tools (linphonec, linphone-daemon) are included with liblinphone.
Simon Morlat 1.1 40
Simon Morlat 1.6 41 {{code language="shell"}}
Simon Morlat 22.1 42 git clone --branch release/4.5 https://gitlab.linphone.org/BC/public/linphone-sdk.git --recursive
Simon Morlat 1.6 43 {{/code}}
44
Simon Morlat 17.1 45 * Setup compilation options. The line below sets options for a minimal liblinphone build with video features.
Simon Morlat 1.6 46
47 {{code language="sh"}}
Simon Morlat 15.2 48 cd linphone-sdk
49 mkdir build-raspberry
50 cd build-raspberry
Simon Morlat 20.1 51 cmake .. -DLINPHONESDK_PLATFORM=Desktop -DCMAKE_C_FLAGS="-mfpu=neon" -DENABLE_OPENH264=ON -DENABLE_LIME_X3DH=OFF -DENABLE_ADVANCED_IM=OFF -DENABLE_WEBRTC_AEC=OFF -DENABLE_UNIT_TESTS=OFF -DENABLE_MKV=OFF -DENABLE_FFMPEG=ON -DENABLE_CXX_WRAPPER=OFF -DENABLE_NON_FREE_CODECS=ON -DENABLE_VCARD=OFF -DENABLE_BV16=OFF -DENABLE_V4L=ON
Simon Morlat 1.6 52 {{/code}}
53
Simon Morlat 8.2 54 * Now proceed with the compilation. This step may take around half an hour and will warm the raspberry !
Simon Morlat 1.6 55
Simon Morlat 8.2 56 {{code}}
Simon Morlat 20.1 57 make -j2
SandrineAvakian 3.1 58 {{/code}}
Simon Morlat 1.1 59
Simon Morlat 21.1 60 * Once completed, the output executables are in linphone-sdk/desktop/bin. The intermediate compilation products are all located in the WORK directory, that you can safely remove. Should any compilation problem happen, in order to restart the compilation from the beginning, removing the WORK directory is sufficient.
Simon Morlat 1.1 61
Simon Morlat 20.1 62 (% class="box warningmessage" %)
63 (((
Simon Morlat 22.1 64 **BUG:** liblinphone won't initialize correctly if the data directory (for persistent storage) is not created. To workaround do:
Simon Morlat 20.1 65 mkdir -p ~~/.local/share/linphone
66 )))
67
Simon Morlat 8.2 68 **Now the software is ready to be used !**
Sylvain Berfini 7.1 69
Simon Morlat 8.2 70 === Configuration ===
Sylvain Berfini 7.1 71
NicolasMichon 13.2 72 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>>https://www.linphone.org/freesip/home]].
Sylvain Berfini 7.1 73
Simon Morlat 8.2 74 (% style="background:#eeeeee;border:1px solid #cccccc;padding:5px 10px;" %)
75 (((
Simon Morlat 21.1 76 cd linphone-sdk/desktop/bin
Sylvain Berfini 7.1 77
Simon Morlat 8.2 78 ./linphonec
Sylvain Berfini 7.1 79
Simon Morlat 8.2 80 [.....]
Simon Morlat 1.6 81
Simon Morlat 8.2 82 linphonec> proxy add
Simon Morlat 1.6 83
Simon Morlat 1.1 84
Simon Morlat 8.2 85 […enter sip account configuration.
86 We recommend to set proxy address to <sip:sip.linphone.org;transport=tls>
87 Once done, you should be prompted for your sip account password, and then it should indicate that it is successfully registered. ]
Simon Morlat 1.1 88 quit
Simon Morlat 1.7 89 )))
Simon Morlat 1.1 90
Simon Morlat 1.7 91
Simon Morlat 8.2 92 //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.//
Simon Morlat 1.7 93
Simon Morlat 8.2 94 Now open //~~/.linphonerc// file with an editor (vim, nano...) in order to tweak a few things:
95
Simon Morlat 1.9 96 * In section [sound], set
97
Simon Morlat 1.7 98 (% style="background:#eeeeee;border:1px solid #cccccc;padding:5px 10px;" %)
99 (((
Simon Morlat 1.1 100 echocancellation=0
Simon Morlat 1.7 101 )))
Simon Morlat 1.1 102
SandrineAvakian 3.1 103 Indeed, echo cancellation is not needed, our raspberry pi has no speaker. No need to spend cpu cycles on this.
Simon Morlat 1.7 104
Simon Morlat 1.9 105
Simon Morlat 1.8 106 (((
Simon Morlat 1.9 107 * In section [video], set vga video size to achieve decent quality, compatible with the pi's processing capabilities:
Simon Morlat 1.8 108 )))
109
110 (((
111
112 )))
113
114 (% style="background:#eeeeee;border:1px solid #cccccc;padding:5px 10px;" %)
115 (((
Simon Morlat 1.1 116 size=vga
Simon Morlat 1.8 117 )))
Simon Morlat 1.1 118
Simon Morlat 1.8 119 (((
120
121 )))
122
123 (((
Simon Morlat 2.1 124 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.
Simon Morlat 1.8 125 )))
126
Simon Morlat 1.9 127 * Turn on ICE, in section [net] section:
Simon Morlat 1.8 128
129 (% style="background:#eeeeee;border:1px solid #cccccc;padding:5px 10px;" %)
130 (((
Simon Morlat 1.1 131 stun_server=stun.linphone.org
132 firewall_policy=3
Simon Morlat 1.8 133 )))
Simon Morlat 1.1 134
Simon Morlat 1.9 135
Sylvain Berfini 3.2 136 === Starting linphonec ===
Simon Morlat 1.9 137
Simon Morlat 8.2 138 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.
Simon Morlat 1.1 139
Simon Morlat 1.8 140 {{code language="sh"}}
Simon Morlat 8.2 141 export PATH=$PATH:`pwd`
142 linphonecsh init -a -C -c ~/.linphonerc -d 6 -l /tmp/log.txt
Simon Morlat 1.8 143 {{/code}}
Simon Morlat 1.1 144
Simon Morlat 8.2 145 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.
146
Simon Morlat 1.9 147 To stop it, do:
148
149 {{code}}
150 linphonecsh exit
151 {{/code}}
152
SandrineAvakian 3.1 153 === Automatic start at boot ===
Simon Morlat 1.9 154
Simon Morlat 1.1 155 In order to have linphonec automatically started when the raspberry boots: you can add this line to /etc/rc.local :
156
Simon Morlat 1.8 157 {{code language="shell"}}
Simon Morlat 21.1 158 export PATH=/home/pi/linphone-sdk/build-raspberry/linphone-sdk/desktop/bin:$PATH
Simon Morlat 8.2 159 sudo -u pi linphonecsh init -a -C -c /home/pi/.linphonerc -d 6 -l /tmp/log.txt
Simon Morlat 1.8 160 {{/code}}
Simon Morlat 1.1 161
Simon Morlat 8.2 162 The lines above assume that your linphone-desktop source tree is in /home/pi/linphone-desktop. Please adapt if it is not the case.
Simon Morlat 1.1 163
Simon Morlat 8.2 164 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 !
165
Sylvain Berfini 3.3 166 === Common hardware problems ===
Simon Morlat 1.9 167
Sylvain Berfini 8.1 168 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:
169
Simon Morlat 8.2 170 * first enable the camera thanks to the raspi-config utility included in your raspberry.
171 * tell the raspberry to load the driver specific to the raspberry camera and do it automatically and next reboot:
172
Sylvain Berfini 8.1 173 {{code}}
Simon Morlat 12.1 174 sudo bash
175 modprobe bcm2835-v4l2
176 echo "bcm2835-v4l2" >> /etc/modules
177 exit
Sylvain Berfini 8.1 178 {{/code}}
179
180
Sylvain Berfini 3.2 181 (% id="HSadly2Ctheraspberryloosingthenetworkconnectivityisafrequentoccurrence.Unfortunately2CallthatNetworkManagerstuffincludedwithRaspbianwasdesignedforLinuxworkstationorservers2Candisnotrobusttotemporarynetworkconnectivitylosses.Theyhappenquitefrequentlybecauseofvariousreasons:" %)
Simon Morlat 21.1 182 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:
Simon Morlat 1.9 183
184 * The internet box looses DSL connection and reboots
185 * The wifi signal is lost temporarily due to interferences
Simon Morlat 1.10 186 * The wifi driver has bugs and looses connection after some hours
SandrineAvakian 3.1 187 * The house general power shuts down and comes back due to a thunderstorm, but the raspberry starts faster than the DSL box and will have no internet at boot time.
Simon Morlat 1.10 188
SandrineAvakian 3.1 189 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.
Simon Morlat 1.10 190
191 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:
192
SandrineAvakian 3.1 193 * The first one called "restart_wlan0_if_necessary.sh". It just tries a ping to linphone.org, and in absence of response, trigers a shutdown/restart of the wlan0 network interface.
Simon Morlat 1.10 194
195 {{code language="shell"}}
196 #!/bin/sh
197 date
198 if test -z "`ping -w 5 linphone.org |grep time`" ; then
199 echo "broken connection, restarting wlan0 now"
200 /sbin/ifdown wlan0
201 sleep 1
202 /sbin/ifup wlan0
203 echo "wlan0 restarted."
204 else
205 echo "Everything ok with network."
206 fi
207
208 {{/code}}
209
210
SandrineAvakian 3.1 211 * The second one, called "reboot_if_necessary.sh". Its goal is to reboot the raspberry if network is still not working, which is the case when the wifi driver or hardware has entered an irrecoverabilly corrupted state.
Simon Morlat 1.10 212
Simon Morlat 1.12 213 Sadly, the wifi devices and drivers are generally so bad in terms of robustness, that this kind of trick is necessary.
214
Simon Morlat 1.11 215 {{code language="sh"}}
216 #!/bin/sh
217 date
218 if test -z "`ping -w 5 linphone.org |grep time`" ; then
219 echo "broken connection, rebooting now"
220 /sbin/reboot
221 else
222 echo "Everything ok with network."
223 fi
224 {{/code}}
Simon Morlat 1.10 225
Simon Morlat 1.11 226 And here's the crontab file:
227
228 {{code}}
229 5 12 * * * /home/pi/reboot_if_necessary >> /home/pi/reboots.log 2>&1
230 0 * * * * /home/pi/restart_wlan0_if_necessary.sh >> /home/pi/restarts.log 2>&1
231
232 {{/code}}
233
234 Use //sudo crontab -e// to write these lines aboves.
235
236 This will schedule restart_wlan0_if_necessary.sh every hour, and reboot_if_necessary every day at 12:05.