RaspberryPi Door Opener

Hello everyone :slight_smile:

Im totaly new to FreePBX and since im trying to solve my problem i have allready read a few post about that but non of them really helped me out and that is why I decided to write a new post. Please if this has been answered somewhere else already, feel free to delete the post an please link me to the solution.

So my goal is to open my doors with two RaspberryPiā€™s, where one acts as a internal unit where the FreePBX is installed (acts as Host and Client at the same time) and the other one as outdoor unit where Linphone client is installed and registered to the internal Host. The whole Process of registration and calling is finished, meaning Im able to press the button on the outside unit and make a call to the indoor unit.

My problem begins here.
What would be the best solution to open the door. I have a Python Script on the outdoor unit that opens the door so I was thinking to use the System() application function with ssh command on the indoor unit during the call with the DTMF option. But I have no idea where to start how to configure that. There are also Feature Codes and Dynamic Features but I have no clue how does all these work.

Can anyone help please? Your help would be appreciated.

Thanks in Advance.

The best way would be to open the door after entering a sequence of numbers. I guess the most complex part would be done on the door phone side. From the point of view of the Asterisk side, you are just sending digits during the call. On the door phone you would need to be waiting for digits and when the right sequence is entered, the opener should be triggered.

In fact there is an example on the FreePBX wiki. Have you taken a look there?

https://wiki.freepbx.org/plugins/servlet/mobile?contentId=33293415#content/view/33293415

1 Like

I personally would use mqtt to signal the open door event.

1 Like

There are very tried and true solutions designed for this purpose. Why are you trying to build your own solution? What are you going to do to let people in when something isnā€™t working?

1 Like

IoTā€¦very interesting. I newer tough about itā€¦but certainly Ill give it a try, perhaps a hint on how do I make Asterisk publish to topic? And then again wouldnā€™t it be easier and faster if I could just make custom dial plan and use the system() function to send a ssh command to the other RPi? I just donā€™t know how to accomplish thatā€¦

and

depending on your abilities, easiest would be to install mosquitto (for your broker) and mosquitto-clients on the Piā€™s, use

TrySystem(. . .) from the dial plan

using ā€˜mosquitto_pubā€™ on the inside device and have ā€˜mosquitto_subā€™ hitting the relay on the outside. pi, you an.

An older technology that still works, if it all fails,

Listen for a knock on the door (it is interrupt driven and it can be password protected), go answer it if you want to :wink:

1 Like

How do I accomplish the TrySystem(ā€¦) thing? I mean how does it work? can I start it with DTMF or do i need an extension for it or macro or anything, do I use some custom feature code and when how do I do all that? the point is I want to make it happen during the call, so if I talk to someone and afterwards want to open the door I want to press a number on a keypad and start an action of door opener, I mean I could eventually forward a phone call to an extension thatā€™s has that TrySystem(ssh command) option build in but then again no clue where to start in this directionā€¦

I would add an in-call feature and mapping

TrySystem

http://www.asteriskdocs.org/en/2nd_Edition/asterisk-book-html-chunk/asterisk-APP-B-228.html

command to try thhe system with

`TrySystem(/usr/bin/mosquitto_pub -h 192.168.1.3 -t "doorlock "-m ā€œopensesameā€)

mapping gpio to mqtt with

and add a

You could of course use ssh instead but that is a very round-about way of going from a human pressing a dtmf button to powering a door latch somewhere else on the internet (use ssl if you go that route, mqtt is really quite secure if done properly) , . Use an open access mqtt broker and you can let the cleaning lady in while your at the pub. And it cost you 2x$5 for the pi zeros and another 5 for the relay, add in a few hours of R&D and you ā€œlearned to fish a bitā€.

Then learn how to do it with thge AGI library straight to mqtt and there is no messing with the dialplan
or ssh or bash or routing or . . . needed as you can intercept the DTMF in there as needed.

1 Like

I have tryed the mqtt part without a problem, it works fine. But Im stuck at the Dynamic_Features, I have done the following:

in globals_custom.conf added following:
DYNAMIC_FEATURES = open

in features_applicationmap_custom.conf added following:
open=>*3,caller,Macro,open

in features_featuremap_custom.conf added following:
open=*3

and in the extensions_custom.conf
[macro-open]
exten => s,1,TrySystem(/usr/bin/mosquitto_pub -h test.mosquitto.org -t doorlock -m opensesame)

so the /usr/bin/mosquitto_pub -h test.mosquitto.org -t doorlock -m opensesame works when I run it from cli, but during the conversation if I press *3 I just see on the following output:

Receiving tone * from sip:[email protected]
Receiving tone 3 from sip:[email protected]

Somehow I cant get it to work, I dont know what am I doing wrongā€¦

Confirm your edits are good with:

[root@freepbx asterisk]# asterisk -x "dialplan show globals" | grep DYNAMIC_FEATURES
   DYNAMIC_FEATURES=open

and

[root@freepbx asterisk]# asterisk -x "features show"

Dynamic Feature           Default Current
---------------           ------- -------
apprecord                 no def  *1
open                      no def  *3
1 Like

Check your usage in current asterisk of the difference between caller,peer,callee. You probably dont want the ā€˜callerā€™ to unilaterally let herself in :wink:

Also make sure that the asteriskuser has permission to run that command (it should) , you are testing it as root.

Interestingā€¦this is my output:

root@raspbx:~# asterisk -x ā€œdialplan show globalsā€ | grep DYNAMIC_FEATURES
DYNAMIC_FEATURES=open

root@raspbx:~# asterisk -x ā€œfeatures showā€
Builtin Feature Default Current


Pickup *8 *8
Blind Transfer # #
Attended Transfer
One Touch Monitor
Disconnect Call * *
Park Call
One Touch MixMonitor

Dynamic Feature Default Current


(none)

Feature Groups:

(none)

So I donā€™t have the Dynamic Featureā€¦

Asterisk User has the rights to publish:

Publish:
root@raspbx:~# su asterisk
$ /usr/bin/mosquitto_pub -h test.mosquitto.org -t opendoor -m opensesame
$

Subscribe:
root@raspbx:/# mosquitto_sub -h test.mosquitto.org -v -t opendoor
opendoor opensesame

Does that mean when I change it to the callee then only the callee can run that feature?

Hereā€™s one FM to R :wink:

https://wiki.asterisk.org/wiki/display/AST/Custom+Dynamic+Features

/etc/asterisk/globals_custom.conf

Is where you add globals in asterisk but outside FreePBX, (maybe that is now changed.)

I have successfully achieved my Goal :slight_smile:

So a BIG thank you goes to Dicko and the lgaetz

that link helped me: https://wiki.asterisk.org/wiki/display/AST/Custom+Dynamic+Features but frankly I have already saw that one before but was to scared to alter the feature.conf and extension.conf and extension.conf files because of early media in the past, and a lot, lot, lot of other stuffā€¦and because of the warning on the top ā€œDO NOT ALTERā€ā€¦and so onā€¦

The fun Part:

config as above with these two new things that came along:

in the features.con file under applicationmap:
[applicationmap]
include features_applicationmap_additional.conf
include features_applicationmap_custom.conf
open => *3,callee,TrySystem(/usr/bin/mosquitto_pub -h ā€œtest.mosquitto.orgā€ -t ā€œopendoorā€ -m ā€œopensesameā€)

the callee option is not working, meaning both can open door with *3, but Ill check that laterā€¦

in the extension.conf file added at the end of the file:
Set(__DYNAMIC_FEATURES=open)

So next Goal is to create mqtt-python-gpio connectionfor door to open , and after that forward my calls from Asterisk to the internet, so meaning I can answer to the door even from outsideā€¦and the rest of the would be the same, only the mqtt broker would be in that case on the insideā€¦so I cut down some security issues.

So my next question is how I do it? What is the best practice when it comes to that? I know i can get a free sip account make a trunk and then Im publicly available but if I want to make it free off charge for me I would need a second sip account and register that one on my phone and then these two speak free of chargeā€¦but if I want the third oneā€¦and so onā€¦so what would be alternatives to that?

1 Like

Any edits you make to files that have a warning in the header will be lost on reload.

Even on server restart?

I have restarted the Server and run dialplan reload and core reload and it is still thereā€¦nothing has been deleted.

The two files you edited are symlinked to their counterparts in the FreePBX module webroot:

[root@freepbx etc]# ll /etc/asterisk/ | grep "features.conf\|extensions.conf"
lrwxrwxrwx. 1 asterisk asterisk     52 Dec 19  2017 extensions.conf -> /var/www/html/admin/modules/core/etc/extensions.conf
lrwxrwxrwx. 1 asterisk asterisk     50 Dec 19  2017 features.conf -> /var/www/html/admin/modules/core/etc/features.conf

youā€™ve altered FreePBX module files, which will probably trigger dashboard warnings of altered files, but more importantly will be overwritten when you update the core module. The only supported way to adding features is what you were doing first, as described in this post:

2 Likes