We have a manager/secretary style busy light on the outside of the manager’s door here, I’d love to be able to tie this into whether he’s on a call, (whether internal or external), I can handle the electronics side of things - but how would I get FreePBX to run a script if he’s on a call?
Thanks Lorne this looks like it could do what I want - is it something I’d call roughly every 30 seconds or so to try to be as up to date as possible? There’s nothing out there that would ‘push’ the BLF hint is there? Thanks again!
It uses a relay attached to an ESP32 connected to Node-Red
Cool. What are you doing to trigger it? You said you wanted to run a script, so does that work now if you execute the script from the PBX CLI? I mean at this point this is all curiosity on how you’re getting the signal from A to B.
Hmm, got it working locally (on the same box as FreePBX) but no matter whether I’m on a call or not the extension still just shows as ‘idle’. I also had to amend the IP in Asterisk Manager Users because it didn’t like 127.0.0.1 I had to enter the LAN IP of the server.
Yet when I login and do core show hints when NOT on a call I get
Looks like you didn’t edit script with legit AMI credentials. This bare bones is working as expected for me:
<?php
// Remote server host/IP, AMI credentials and
$remote_server = "127.0.0.1";
$remote_name = "admin";
$remote_secret = "password";
$remote_context = "from-internal";
// define range or remote extension numbers to poll, the fewer the better
// the range needs to match the dynamic hint noted above
$remote_extension_start='5002';
$remote_extension_end='5002';
// Connect to local machine with FreePBX bootstrap, requires FreePBX 2.9 or higher
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
include_once('/etc/asterisk/freepbx.conf');
}
// connect to remote Asterisk machine using AMI credentials and get status of Extension 103
$remote = new AGI_AsteriskManager();
if ($remote->connect($remote_server, $remote_name, $remote_secret)) {
for ($remote_extension=$remote_extension_start; $remote_extension<=$remote_extension_end; $remote_extension++) {
$foo[$remote_extension] = $remote->ExtensionState($remote_extension, $remote_context);
}
$remote->disconnect();
}
else {
output("Can not connect to remote AGI");
}
print_r($foo);
Thanks Lorne - I’d been updating/editing my post throughout - seems to have been a permissions thing - got it working - just wondering now how often to call the script to get accurate info - ideally it would be pushed from Asterisk as that seems less aggressive than calling the script every few seconds?
No it wasn’t that, because a) I did, and b) it wasn’t throwing errors at me about (“Can not connect to remote AGI”), it was the Asterisk User Manager write settings it needed enabling. Not just read settings.
I am not a programmer, just a hacker. I am sure there is a way to leverage the AMI (the connection to which you now have) to subscribe to an event and receive updates automatically.
As is so often the case with me, I’m making things harder than they need to be. This works as well, using the FreePBX AMI connection already established:
<?php
// Connect to local machine with FreePBX bootstrap, requires FreePBX 2.9 or higher
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
include_once('/etc/asterisk/freepbx.conf');
}
if($astman->connected()) {
$cmd = $astman->ExtensionState("5002", "from-internal");
}
print_r($cmd);
Thanks Lorne, this (your second, simpler script) does work, but I’m confused as to how it works because I didn’t need to input any username or password for this script unlike the first script. I know you mentioned it’s already established but in what sense is the AMI connection already established? Sorry to be a ninny.
FreePBX interacts directly with asterisk using AMI for some actions. For example, when you click the red apply config button, one of the actions is to tell Asterisk to do a core reload. In advanced settings are AMI credentials and you will find corresponding creds in the manager.conf file. It is this AMI user that FreePBX uses.
Gotcha! I’m with you. So this wouldn’t work if it was on another machine on my LAN it works because it’s on the same server as my FreePBX instance. Makes total sense now. Thanks.
Correct. The more complex version wouldn’t work on another (non freepbx) machine either, as it’s using the bootstrap for the remote connection as well.
So I’ve been playing around on and off for last few hours and have made a few discoveries. A windows program called CallMonitor which is a bit buggy but which does successfully authenticate and show AMI info, it just never seems to respond to the specific task it’s supposed to do like show a caller ID window or open a URL.
I’ve also come across and installed Pami, I’ve found but not managed to get working a daemon listener called ami-push (as there’s seemingly zero documentation).
So far Pami seems like overkill but it’s the only thing I’ve got working. I also don’t know how to filter events with it or to act on them yet. But I’m making progress!