schwar3kat Posted September 20, 2019 Posted September 20, 2019 If you use a SIP Voip client on your phone or computer, you can use the sip protocol and scripting to monitor your Armbian board. I'm using Ubuntu Xenial, but other versions should work as well. I have the Linphone client on my phone and I use the free Linphone SIP service. Linphone.org hosts a free SIP service that allows users to make audio or video calls using SIP addresses via the domain sip.linphone.org. You can also send text messages. SIP requires an internet data connection, and my phone is connected via WIFI most of the time except when I'm commuting, so I set up my monitoring chron jobs on the Armbian device to run at times when I'm connected. Set up a SIP account for yourself if you don't yet have one, and set up an account for your device. You can set up free accounts at https://www.linphone.org/freesip/home The example accounts used in this tutorial are: sip:armdevice@linphone.org and sip:youraccount@linphone.org Replace these with your own accounts. I suggest that you get your Voip service running and tested on your phone and another device or PC before you try and set up SIP scripting on your Armbian device. Install the Linphone console client on your Armbian device (Orange Pi Zero Plus in my case). sudo apt-get install linphone-nogtk When it has installed start the client linphonec You may get a bunch of warnings about unconfigured sound cards and etc. Unless you want to use voice or video, you can ignore these. ........ eventually you will get a linphonec prompt Warning: video is disabled in linphonec, use -V or -C or -D to enable. linphonec> If you type help, you will get a list of commands: linphonec> help Commands are: --------------------------- help Print commands help. call Call a SIP uri or number calls Show all the current calls with their id and status. chat Chat with a SIP uri terminate Terminate a call answer Answer a call pause pause a call resume resume a call transfer Transfer a call to a specified destination. conference Create and manage an audio conference. mute Mute microphone and suspend voice transmission. camera Send camera output for current call. unmute Unmute microphone and resume voice transmission. playbackga Adjust playback gain. duration Print duration in seconds of the last call. autoanswer Show/set auto-answer mode proxy Manage proxies soundcard Manage soundcards webcam Manage webcams ipv6 Use IPV6 nat Set nat address stun Set stun server address firewall Set firewall policy call-logs Calls history friend Manage friends play play a wav file record record to a wav file quit Exit linphonec --------------------------- Now you need to configure your SIP proxy. "help proxy" gives you the relevant commands linphonec> help proxy 'proxy list' : list all proxy setups. 'proxy add' : add a new proxy setup. 'proxy remove <index>' : remove proxy setup with number index. 'proxy use <index>' : use proxy with number index as default proxy. 'proxy unuse' : don't use a default proxy. 'proxy show <index>' : show configuration and status of the proxy numbered by index. 'proxy show default' : show configuration and status of the default proxy. We must use "proxy add". It will start an interactive session. Note the format of the proxy sip address enclosed with < and > linphonec> proxy add Adding new proxy setup. Hit ^D to abort. Enter proxy sip address: <sip:sip.linphone.org;transport=tls> Your identity for this proxy: sip:armdevice@sip.linphone.org Do you want to register on this proxy (yes/no): yes Specify register expiration time in seconds (default is 600): Expiration: 0 seconds Specify route if needed: No route specified. -------------------------------------------- sip address: <sip:sip.linphone.org;transport=tls> route: identity: sip:armdevice@sip.linphone.org register: yes expires: 0 registered: no -------------------------------------------- Accept the above proxy configuration (yes/no) ?: yes Proxy added. linphonec> Password for armdevice on "sip.linphone.org": Y0uR-pa$$word linphonec> Unregistration on <sip:sip.linphone.org;transport=tls> done. That's it you are now configured. (not sure what "unregistration" means, perhaps it's a typo and should say registration) Send yourself a test text and quit out of linphonec. Once again "help" is useful: linphonec> linphonec> help chat chat <sip-url> "message"' : send a chat message "message" to the specified destination. linphonec> chat <sip:youraccount@sip.linphone.org> "Testing sip messaging" linphonec> terminate No active calls linphonec> quit Terminating... How can you easily send messages from a script? Create a wrapper script using expect (uses tls not bash) If you don't have expect installed then sudo apt-get install expect Create a wrapper expect script called "send-sip.sh" #!/usr/bin/expect -f # send-sip.sh "this is a message" set message [lindex $argv 0]; spawn linphonec expect "<sip:sip.linphone.org;transport=tls> done." send "chat <sip:youraccount@sip.linphone.org> \"$message\"\r" expect "linphonec>" sleep 10 send "terminate\r" expect "linphonec>" send "quit\r" expect "Terminating..." exit Set execute permission on the file. I placed mine in /usr/local/bin chmod +x /path/to/file # e.g. chmod +x /usr/local/bin/send-sip.sh Now you can execute your wrapper from a script like this and it will send the message to your sip address. Change the path to the location of your wrapper script. /usr/local/bin/send-sip.sh "this is a sip message"
Recommended Posts