GSM dongle trunk customization - start and stop the dongle

Hi to all,
I have successfully installed FreePBX and was able to set it to my purpose (which is a SIP-GSM Gateway).
To accomplish that goal I use two trunks (one is my SIP provider and the second is my mobile provider through GSM dongle using chan_dongle (you can find more here: http://wiki.e1550.mobi/doku.php?id=usage
However, I need to solve a specific customization issue and I am unable to do it using the web interface.
The GSM part of the gateway will serve for outgoing calls only.
I have put one of my double SIM card into the GSM dongle (I use two SIM cards with the same phone number). To be able to use the second SIM card in my mobile phone for receiving calls I need that the GSM dongle starts and connects to the GSM network only when there is an outgoing call through the GSM trunk and after the call has finished the dongle unregisters from the GSM network.
I am able to start and stop the dongle using CLI commands like this:
dongle start dongle0
dongle stop now dongle0
or
dongle stop when convenient dongle0

but I don’t know where to put these commands to start it before a call is made to the gsm trunk and to stop it after the call is finished.

Could you help me?

Petr

In /etc/asterisk/extensions_custom.conf I think something like this might work…

[font=Courier]
[macro-dialout-trunk-predial-hook]
exten => s,1,GotoIf($["${DIAL_TRUNK}" != “1”]?skip)
exten => s,n,System(dongle start dongle0)
exten => s,n(skip),MacroExit

[macro-hangupcall-custom]
exten => s,1,System(dongle stop now dongle0)
[/font]

Thank you.
I created the file /etc/extensions_custom.conf (It was missing in my system), copied the suggested text and restarted Asterisk.
I don’t know if I have to change something in it (I am absolute newbie to FreePBX), but just copying it didn’t work.
Do I have to substitute “DIAL_TRUNK” with the name of trunk or something else?
Sorry for my beginner question.

As I said, this assumes your trunk is number 1. You can check this in the FreePBX trunks page by looking at the link for each trunk. So for example http://pbx/admin/config.php?display=trunks&extdisplay=OUT_3 is trunk 3. So you’d want to change the If parameter to check for the correct trunk number.

I’ve never used the [font=Courier]System()[/font] application before, or had the need to do anything post-hangup. So you may need to figure some things out on your own. I strongly recommend reading the Asterisk book if you’re going to be doing much of anything with Asterisk, even if it is through FreePBX.

That said, we do use [font=Courier][macro-dialout-trunk-predial-hook][/font] to run A2Billing and it works great for us.

Yes!
The problem was that the trunk was number 2, not 1.
After editing it to 2, it seems to behave in a different way.
Unfortunately, when I try to place a call through that trunk a warning appears:
WARNING[27158][C-00000000]: app_system.c:138 system_exec_helper: Unable to execute 'dongle start dongle0’
and the dongle doesn’t start.
But the same command in CLI console prints:
[dongle0] Start scheduled
and it is OK.

What is wrong?

Try the full path?

I changed this line in macro:

exten => s,n,System(dongle start dongle0)

to:

exten => s,n,System(asterisk -rx “dongle start dongle0”)

and it started working!

Unfortunately, the second part (after hangup) even after changing into:

[macro-hangupcall-custom]
exten => s,1,System(asterisk -rx “dongle stop now dongle0”)

doesn’t do anything. So, when a call is terminated, the dongle remains started.

Any ideas what to do?

I misunderstood your original post, I though the “dongle” command was something in Linux, not an Asterisk command. Anyway, I’d check the call logs and see if [macro-hangupcall-custom] is even getting called at all.

Here is the full log from Asterisk when I make a call from a local SIP extension through the “dongle” trunk:

[2013-05-18 14:40:34] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:3] Wait(“SIP/1002-00000002”, “5”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:4] MacroExit(“SIP/1002-00000002”, “”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:18] GotoIf(“SIP/1002-00000002”, “0?bypass,1”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:19] ExecIf(“SIP/1002-00000002”, “1?Set(CONNECTEDLINE(num,i)=222745120)”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:20] ExecIf(“SIP/1002-00000002”, “1?Set(CONNECTEDLINE(name,i)=CID:)”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:21] GotoIf(“SIP/1002-00000002”, “1?customtrunk”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Goto (macro-dialout-trunk,s,25)
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:25] Set(“SIP/1002-00000002”, “pre_num=AMP:dongle/dongle0/”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:26] Set(“SIP/1002-00000002”, “the_num=OUTNUM”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:27] Set(“SIP/1002-00000002”, “post_num=”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:28] GotoIf(“SIP/1002-00000002”, “1?outnum:skipoutnum”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Goto (macro-dialout-trunk,s,29)
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:29] Set(“SIP/1002-00000002”, “the_num=+420222745120”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:30] Dial(“SIP/1002-00000002”, “dongle/dongle0/+420222745120,300,Tt”) in new stack
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] app_dial.c: – Called dongle/dongle0/+420222745120
[2013-05-18 14:40:39] VERBOSE[21700][C-0000005e] app_dial.c: – Dongle/dongle0-0100000001 is making progress passing it to SIP/1002-00000002
[2013-05-18 14:40:41] VERBOSE[21700][C-0000005e] app_dial.c: – Dongle/dongle0-0100000001 answered SIP/1002-00000002
[2013-05-18 14:40:41] ERROR[18272][C-0000005e] chan_sip.c: No SRTP module loaded, can’t setup SRTP session.
[2013-05-18 14:40:41] ERROR[18272][C-0000005e] chan_sip.c: No SRTP module loaded, can’t setup SRTP session.
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:1] Macro(“SIP/1002-00000002”, “hangupcall,”) in new stack
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:1] GotoIf(“SIP/1002-00000002”, “1?theend”) in new stack
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] pbx.c: – Goto (macro-hangupcall,s,3)
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:3] ExecIf(“SIP/1002-00000002”, “0?Set(CDR(recordingfile)=)”) in new stack
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] pbx.c: – Executing [[email protected]:4] Hangup(“SIP/1002-00000002”, “”) in new stack
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] app_macro.c: == Spawn extension (macro-hangupcall, s, 4) exited non-zero on ‘SIP/1002-00000002’ in macro ‘hangupcall’
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] pbx.c: == Spawn extension (macro-dialout-trunk, h, 1) exited non-zero on ‘SIP/1002-00000002’
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] app_macro.c: == Spawn extension (macro-dialout-trunk, s, 30) exited non-zero on ‘SIP/1002-00000002’ in macro ‘dialout-trunk’
[2013-05-18 14:41:24] VERBOSE[21700][C-0000005e] pbx.c: == Spawn extension (from-internal, 222745120, 6) exited non-zero on ‘SIP/1002-00000002’

My last suggestion is to try something like this:

[macro-dialout-trunk-custom]
exten => h,1,System(asterisk -rx "dongle stop now dongle0")

Hello everyone I’m doing some tests to make asterisk as Gateway to UMTS / GSM directly using a USB internet key

I followed this guide and installed everything on the distro http://wiki.e1550.mobi/ FreePBX 3.0
and as for incoming calls and outgoing using a sim umts H3G works perfectly.
Now I want to implement the function Sms in practice that when I get a text message forwards it to me via e-mail
has anyone had any experience on this and could give me some advice to do this?
TKS GRPSE

What the stuff below does is the following. It will log all incoming SMS and USSD into /var/log/asterisk/sms.txt and /var/log/asterisk/ussd.txt
On incoming SMS it will also create a short email with text message and send it using ssmtp to [email protected]. Substitute whatever email application you are using. Make sure user asterisk has right to send an email. Also make sure in /etc/asterisk/dongle.conf you have context=from-trunk
Finally, add to /etc/asterisk/extensions_custom.conf
something like

[from-pstn-custom]
include => dongle-incoming-sms
include => dongle-incoming-ussd

[dongle-incoming-sms]
exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,2,System(echo “Subject: SMS received from ${CALLERID(num)}” > /var/log/asterisk/smsmail)
exten => sms,3,System(echo " " >> /var/log/asterisk/smsmail)
exten => sms,4,System(echo “${BASE64_DECODE(${SMS_BASE64})}” >> /var/log/asterisk/smsmail)
exten => sms,5,System(/usr/sbin/ssmtp [email protected] < /var/log/asterisk/smsmail)
exten => sms,n,System(echo ‘${STRFTIME(${EPOCH},%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)}: ${BASE64_DECODE(${SMS_BASE64})}’

/var/log/asterisk/sms.txt)
exten => sms,n,Hangup()

[dongle-incoming-ussd]
exten => ussd,1,Noop(Incoming USSD: ${BASE64_DECODE(${USSD_BASE64})})
exten => ussd,n,System(echo ‘${STRFTIME(${EPOCH},%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}: ${BASE64_DECODE(${USSD_BASE64})}’ >> /var/log/asterisk/ussd.txt)
exten => ussd,n,Hangup()

thanks a lot dziny
I almost solved
there is’ an error
exten => sms,5,System(/usr/sbin/ssmtp [email protected] </var/log/asterisk/smsmail)

[email protected]il.com

On Freepbx 3 use postfix and there ssmtp can you give me some ideas?

TKS GRPSE

thanks a lot dziny I almost solved
there is’ an error
exten => sms,5,System(/usr/sbin/ssmtp [email protected] [email protected]
On Freepbx 3 use postfix and there ssmtp can you give me some ideas?

TKS GRPSE

 

my  extensions_custom.conf

 

[from-pstn-custom]
include => dongle-incoming-sms
include => dongle-incoming-ussd

[dongle-incoming-sms]
exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,2,System(echo "Subject: SMS received from ${CALLERID(num)}" > /var/log/asterisk/smsmail)
exten => sms,3,System(echo " " >> /var/log/asterisk/smsmail)
exten => sms,4,System(echo "${BASE64_DECODE(${SMS_BASE64})}" >> /var/log/asterisk/smsmail)
exten => sms,5,System(sendmail -f  [email protected] -t [email protected] < /var/log/asterisk/smsmail)

exten => sms,n,System(echo '${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)}: ${BASE64_DECODE(${SMS_BASE64})}'
>> /var/log/asterisk/sms.txt)
exten => sms,n,Hangup()

[dongle-incoming-ussd]
exten => ussd,1,Noop(Incoming USSD: ${BASE64_DECODE(${USSD_BASE64})})
exten => ussd,n,System(echo '${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}: ${BASE64_DECODE(${USSD_BASE64})}' >> /var/log/asterisk/ussd.txt)
exten => ussd,n,Hangup()

Hello Petr,
I’m trying to do same setup. I have raspbx with USB 4G overseas and would like to be able to dial into the raspbx and go out thru GSM trunk and make a local call.
How did you acheive it.
Thanks in advance ([email protected])

Just put your trunk from the remote machine in the raspbc in from-internal and it can access all dial plan resources.

Thanks Skyking,
I just need little more details please. I need to be able to call into the raspbx via US number and automatically forward all the calls out the GSM trunk which will have non US SIM so I can call any mobile or land line overseas. Do I need to get a sip account with DID? Would it be possible to have pin code before dialing the final destination number?

I thought you wanted to connect two boxes together and use GSM trunk on remote machine.

All you need to do is use DISA module, does what you want.

Certainly you need a number to dial in on so one of our SIP Station trunks would work great (they are unlimited).

Skyking,

Thank you for the fast reply, I’m not sure why I can’t locate the module?