Just to give someone searching for this another idea this is how i did this on ubuntu.
I’m using Linphone to do all the calling stuff.
- Login using SSH to your ubuntu machine and install linphone-nogtk package using apt-get
sudo apt-get install linphone-nogtk
- test linphone using linphonecsh
linphonecsh is a console program to control linphonec (this is a console app for linphone also installed with linphone-nogtk).
Best use openhab user for this.
sudo -u openhab /bin/bash
Test calls:
// creates a new instance of linphone. Only one instance allowed
linphonecsh init
//Register your linphoneclient at your SIP Server
linphonecsh register --host [SIPHostAdddress] --username [SIP Username] -- password [SIP Password]
//Check Status of registration
linphonecsh status register
-> should return something like: registered to identitiy
//call a number
linphonecsh dial 123456789
//exit linphonecsh
linphonecsh exit
I had an issue where status register always returned “-1”. This was caused by an issue where linphonec couldn’t create it’s databasefile. Took me some hours to find the root cause. You will get an warning when starting linphonec.
To fix this I had to create the folder where the databasefile is safed. I don’t know the location any more.
Now time for my JS Rule Script using ECMAScript262 (JS Scripting rule)
var Duration = Java.type("java.time.Duration");
var callingtimeouttimer;
//cechk if timer exists
if (cache.private.exists("callingtimeouttimer"))
{
callingtimeouttimer = cache.private.get("callingtimeouttimer");
}
//cancel timer and stop linphonecsh
if (callingtimeouttimer!= null)
{
callingtimeouttimer.cancel();
callingtimeouttimer = null;
}
//stop linphone for now to get shure it is sopped
actions.Exec.executeCommandLine("linphonecsh", "exit");
java.lang.Thread.sleep(500);
//start a new instance
actions.Exec.executeCommandLine("linphonecsh", "init");
java.lang.Thread.sleep(500);
//register at Phoneline
var re = actions.Exec.executeCommandLine(Duration.ofSeconds(1),"linphonecsh", "register", "--host", "192.168.1.xx", "--username", "SIPUSER", "--password", "SIPPASSWORD");
java.lang.Thread.sleep(1000);
//get registerstatus
var resp = actions.Exec.executeCommandLine(Duration.ofSeconds(1), "linphonecsh", "status", "register");
//setup linphone to play soundfiles
actions.Exec.executeCommandLine(Duration.ofSeconds(1),"linphonecsh", "generic", "soundcard use files");
java.lang.Thread.sleep(100);
//startplayback
actions.Exec.executeCommandLine(Duration.ofSeconds(1),"linphonecsh", "generic", "play /etc/openhab/sounds/AlarmSound.wav");
//check if registering was possible. Log error if not and cancel
if (!resp.includes("identity"))
{
console.error("Error registering at SIP Client:" + resp);
actions.Exec.executeCommandLine("linphonecsh", "exit");
}
else
{
//call a number
actions.Exec.executeCommandLine("linphonecsh", "dial", "123456789");
//setup timeout to and calling after x time
callingtimeouttimer = actions.ScriptExecution.createTimer("callingtimeout", time.ZonedDateTime.now().plusSeconds(30),endCall);
cache.private.put("callingtimeouttimer", callingtimeouttimer);
}
//end call timer callback
function endCall(){
actions.Exec.executeCommandLine("linphonecsh", "exit");
if (cache.private.exists("callingtimeouttimer"))
{
var callingtimeouttimer = cache.private.get("callingtimeouttimer");
callingtimeouttimer.cancel();
cache.private.remove("callingtimeouttimer");
}
}
What this script does is calling a number for max of 30 seconds an playing an wave file located in “Sounds” folder under OHConfig files location.
linphonecsh generic “xyz” runs command “xyz” on linphonec.
For more information on this run linphonec and enter help. you could also enter help advanced for some more help informations.
Hope this helps someone in the future as it took me some days to get this up running. Linphone has pretty much functions and i think you could do nearly everything using this.