[how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_dongle

sezione dedicata ai sistemi operativi alternativi Open Source

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 08/02/2015, 20:37

OpenWRT Wi-Fi analog PSTN Voip adapter ;)

Immagine

Immagine

Immagine
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 10/05/2015, 14:39

Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 23/05/2015, 18:14

It seems that to solve the one way audio problem on chan_dongle on OpenWRT B.B. you have to insert the following two lines in /etc/asterisk/modules.conf:

noload => res_timing_pthread.so
noload => res_timing_timerfd.so

but by doing this the Music On Hold becomes jerky on SIP channels (MOH seems OK on dongle channel) :shock: :(

If you use "load => res_timing_pthread.so", SIP channels are OK but Chan_dongle has one way audio with high noise on the other channel,
with "load => res_timing_timerfd.so" SIP channels are OK but Chan_dongle has one way audio with no audio on the other channel.
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 23/05/2015, 18:15

Since I was able to make chan_dongle working on OpenWRT B.B., I want to post some useful commands:

To send a SMS from shell:

/usr/sbin/asterisk -rx 'dongle sms dongle0 number message'

example:

/usr/sbin/asterisk -rx 'dongle sms dongle0 +393711734567 test message'


bash:
#!/bin/sh
asterisk -rx 'dongle sms dongle0 +393711734567 test message'

Perl:
#!/usr/bin/perl
system qq(asterisk -rx 'dongle sms dongle0 +393711734567 test message')


-----------------------------------------------------------------
Chan_dongle configuration example for Huawei E169
-----------------------------------------------------------------

/etc/asterisk/extensions.conf:

[from-internal]
; extension 100 - rings for 30 seconds
exten => 100,1,Dial(SIP/100,30)
exten => 100,2,Hangup()
; dial out
exten => _1NXXNXXXXXX,Dial(dongle/dongle0/${EXTEN})
[from-pstn]
; incoming
exten =>
+393711734567,1,Answer()
exten =>
+393711734567,2,Dial(SIP/100,30)
exten =>
+393711734567,3,Hangup()


/etc/asterisk/dongle.conf:

[general]
interval=15
[defaults]
context=from-pstn
group=1
rxgain=0
txgain=0
autodeletesms=yes
resetdongle=yes
u2diag=-1
usecallingpres=yes
callingpres=allowed_passed_screen
disablesms=no
language=it
smsaspdu=yes
mindtmfgap=45
mindtmfduration=80
mindtmfinterval=200
callwaiting=auto
disable=no
initstate=start
exten=
+393711734567
dtmf=relax
[dongle0]
audio=/dev/ttyUSB1
data=/dev/ttyUSB2
imei=123456789012345
imsi=123456789012345


/etc/asterisk/modules.conf:

[modules]
autoload=yes
noload => res_timing_pthread.so
noload => pbx_gtkconsole.so
noload => res_musiconhold.so
noload => chan_alsa.so
noload => chan_console.so
noload => pbx_ael.so
load => pbx_spool.so
noload => chan_motif.so
noload => res_timing_timerfd.so
load => chan_dongle.so
noload => chan_iax2.so


/etc/asterisk/sip.conf:

[general]
transport=udp
bindport=5060
bindaddr=0.0.0.0
nat=force_rport,comedia
language=en
allowguest=no
srvlookup=no
disallow=all
allow=ulaw
allow=alaw
allow=gsm
dateformat=%F %T
alwaysauthreject=yes
localnet=192.168.1.0/255.255.255.0
localnet=127.0.0.0/255.255.255.0
localnet=10.0.0.0/255.255.255.0
;tcpbindaddr=0.0.0.0
;tcpenable=yes


[100]
user=100
type=friend
secret=
Change_Me!
host=dynamic
qualify=yes
nat=force_rport,comedia
insecure=invite,port
context=from-internal
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 23/05/2015, 18:15

Forward any SMS received through "chan_dongle" to email:

edit "/etc/asterisk/extensions.conf" and add the following:

[from-pstn]
;
; SMS 2 email ; it needs mini_sendmail and asterisk11-func-base64 installed
;
exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})

exten => sms,2,System(echo 'From: ${CALLERID(num)} <sender@domain.com>\nTo: <myself@domain.com>\nSubject:Received SMS\nfrom: ${CALLERID(num)}\n${BASE64_DECODE(${SMS_BASE64})}' >> /var/log/asterisk/sms.txt)
exten => sms,3,System(/usr/sbin/mini_sendmail -fsender@domain.com -ssmtp.server.com -p25 myself@domain.com < /var/log/asterisk/sms.txt)
exten => sms,4,System(rm -f /var/log/asterisk/sms.txt)
exten => sms,5,Hangup()

Notes:
the line in red is a single line!
-ssmtp.server.com is the SMTP server and need to be adapted to your parameters, -p25 is the SMTP port, example:
if your server is relay.post.com, then use: -srelay.post.com -p25

usage:
mini_sendmail -f(sender) -s(SMTP) -p(port) (recipient)
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 23/05/2015, 18:15

Web page to send SMS from OpenWRT (B.B.) using Asterisk11+Chan_dongle:


1) Install PHP:
opkg update
opkg install php5 php5-cgi


2) create /www/sms directory
mkdir /www/sms

3) create index.php file
nano /www/sms/index.php
(or vi /www/sms/index.php if you don't have nano installed)

insert the following lines:

<?php
/************************************************** *******************
* Chan_Dongle SMS Script v.0.01
* for The Raspberry Asterisk
*
* Author: Troy Nahrwold
* Email: Troy(at)eternalworks(dot)com
* Company: Eternal Works
* Website: www.eternalworks.com
*
* Disclaimer:
* This product is solely a private production of the above named
* author, and is neither endorsed nor supported by Eternal Works.
* Although this product has been thuroughly tested, it is
* distributed AS IS, and the author assumes no liability for any
* damages this script may cause to your system. The author
* has provided full source code and encourages you to review the
* source code to determine any effects it may have on your system.
*
* (c) Copyright 2011, Troy A Nahrwold, Eternal Works, LLC.
* All Rights Reserved.
*
* ITALIAN/OPENWRT VERSION BY: pilovis
* EVENTUALLY EDIT THIS FILE TO CHANGE DESCRIPTIONS FROM ITALIAN TO YOUR LANGUAGE
************************************************** *******************/
$dongle = "dongle sms dongle0 ";
$ini = "'";
if(isset($_REQUEST['phonenumbers']) && !empty($_REQUEST['phonenumbers']) && !empty($_REQUEST['message']))
{
$message = substr($_REQUEST['message'],0,160);
$phonenumberarray1 = explode(' ',$_REQUEST['phonenumbers']);
foreach ($phonenumberarray1 as $phonenumber)
{
}
$output = "Testo: $message<br><br>\n";
{
$runcommand = '/usr/sbin/asterisk -rx' . $ini . $dongle . $phonenumber . " " . $message . $ini;
$output .= "Invio messaggio a: $phonenumber<br>\n";
exec($runcommand);
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMS Messaging for Asterisk</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<script type="text/javascript">
/**
**/
function countChar() {
//
var count_char_textarea = document.getElementById("message");
// count_char_textarea.value = count_char_textarea.value.length;
var char_length = document.getElementById("char_length");
//
if ( count_char_textarea.value.length > 160 ) {
count_char_textarea.value = count_char_textarea.value.substr(0, 160);
}
char_length.innerHTML = count_char_textarea.value.length;
}
</script>
<hr>
<body bgcolor="#84b0fd" text="#030303" link="#9abcde">
<a href="./index.php"><h2 align="center"></h2></a>
<table border="0" cellspacing="0" cellpadding="1" width="600" bgcolor="#ffffff" align="center">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="3" width="100%" bgcolor="#ffffff" align="center">
<tr bgcolor="#abcdef">
<td><b><?php echo $output; ?></b></td>
</tr>
<tr><form action="index.php" method="post">
<p><b>Numero di cellulare:</b> <br><font size="-2">(Formato: +39XXXXXXXX)</font></p>
<textarea id="phonenumbers" name="phonenumbers"></textarea>
<p><b>Testo del messaggio:</b> <br> <font size="-2">(Massimo 160 caratteri, se superiore il messaggio verra' troncato) </font></p>
<textarea id="message" name="message" size="160" rows="6" cols="30" onchange="countChar()" onkeyup="countChar()"></textarea><br /><br/>
<font size="2">conteggio caratteri del messaggio: <span id="char_length"> 0 </span></font>
<p>
<button type="submit">Invia Messaggio</button><br /><br />
</form></tr>
</table>
</dd>
<p></td>
</tr>
<tr>
<td bgcolor="#ffffff"><a href="javascript:history.back()">Invia lo stesso messaggio ad altro numero</a></td>
</tr>
</table>
</td>
</tr>
</table>
<p>
</td>
</tr>
</table>
<hr>
</body>



4) test the page at http://your_IP_address/sms/


5) protect the page with a password

Basic Authentication on uhttpd, to add a password to uhttpd (global web page access) use the following commands:

uci set uhttpd.main.config=/etc/httpd.conf
uci commit uhttpd
echo "/:root:password" > $(uci get uhttpd.main.config)
/etc/init.d/uhttpd restart


change password as you desire, user is root (note that this is not the "root user" of OpenWRT)
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 10/06/2015, 14:54

To improve a little bit the efficency of Asterisk11 + Chan_dongle on Openwrt there are some configuration modifications to do:

In "asterisk.conf" add the following line under [options]:

internal_timing = yes

the "modules.conf" file should be modified as per the following:

[modules]

; notes:
; noload => disable a module
; load => enable a module


autoload=yes

noload => res_timing_pthread.so ; never enable it when using chan_dongle
noload => pbx_gtkconsole.so
noload => res_musiconhold.so ; you shouldn't use music on hod with chan_dongle because of choppy audio
noload => chan_alsa.so
noload => chan_console.so
noload => pbx_ael.so
load => pbx_spool.so
noload => chan_motif.so ; enable it only if you have an active Google voice account
noload => res_timing_timerfd.so ; never enable it when using chan_dongle
load => chan_dongle.so ; if you don't use chan_dongle, disable this and enable res_timing_timerfd.so
noload => chan_iax2.so
noload => codec_ilbc.so
noload => codec_lpc10.so
noload => skipping codec_lpc10.so
noload => codec_speex.so
noload => app_adsiprog.so
noload => app_db.so
noload => chan_skinny.so
noload => cdr_csv.so
noload => res_adsi.so
noload => res_agi.so
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 10/06/2015, 14:55

Say current date and time to the caller

install zoneinfo-core:

opkg update
opkg install zoneinfo-core


Insert the following lines in "extensions.conf":

[from-internal]

; say current Date & Time
exten => 161,1,SayUnixTime(,CET,AdbYkM)
exten => 161,2,Wait(2)
exten => 161,3,Hangup()


note: change CET with your timezone (ex.: GMT, EST, UTC, etc.).

Restart asterisk:

/etc/init.d/asterisk restart

To test it dial 161.
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Send email & restart Asterisk when a SIP trunk gets disconne

Messaggio da leggereda root » 07/09/2016, 0:28

[HOW-TO] Send an email and restart Asterisk when a SIP trunk gets disconnected.

0) prerequisites: asterisk and mini-sendmail (no_auth SMTP server required)


1) create and edit the script:

touch /root/check-sip.sh

vi /root/check-sip.sh

#!/bin/bash
# check SIP trunk for Asterisk/OpenWRT, send an email and restart Asterisk when a SIP trunk gets disconnected
# don't forget to create a crontab to lauch this script every xx minutes
# by pilovis - parknat12@yahoo.com
#
## check for sip trunk status
checkifok=`/usr/sbin/asterisk -rx "sip show peer
xxxxxxxx" | grep Status | grep -wc OK`
## if trunk is not connected
if [[ $checkifok == 0 ]]; then
## send an email
/bin/echo "SIP Trunk
xxxxxx not registered" | /usr/sbin/mini_sendmail -fsender@mail.com -smailer-smtp.com -p25 receiver@mail.com
## then wait for 3 seconds
/bin/sleep 3
## and restarts Asterisk
/usr/sbin/asterisk -rx "sip reload"
## if trunk is OK do nothing
else
/bin/echo "Trunk OK" > /dev/null 2>&1
fi
#eof


Notes:
"/bin/echo "SIP Trunk xxxxxx not registered" | /usr/sbin/mini_sendmail -fsender@mail.com -smailer-smtp.com -p25 receiver@mail.com" is a single line!
change peer name 'xxxxxxxx' with your outbound trunk peer name as specified in /etc/asterisk/sip.conf


2) give the right permissions to the script:

chmod 755 check-sip.sh


3) create a contab to run the script every 5 minutes:

vi /etc/crontabs/root

*/5 * * * * /bin/sh /root/check-sip.sh


4) reboot to apply.

----------------------------------------------------

If you want to use "msmtp" to be able to use your Google account and SMTP Google server,
this is the line to be used to send an email:

/bin/echo "SIP Trunk xxxxxx not registered" | /usr/bin/msmtp receiver@mail.com


you also need to edit "/etc/msmtprc" with your gmail credentials,
delete everything inside the file and put the following;

account default
host smtp.gmail.com
port 587
auth on
user youraccount@gmail.com
password yourpassword
auto_from off
from youraccount@gmail.com
tls on
tls_starttls on
tls_certcheck off
logfile
syslog LOG_MAIL


Note: change "youraccount@gmail.com" and "yourpassword" with your Gmail credentials.


To install msmtp:

opkg update
opkg install msmtp
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

OpenWRT Home Automation BOX

Messaggio da leggereda root » 11/09/2016, 21:44

this is my last (mad) creation:

OpenWRT Home Automation BOX

Features:

- 2 digital input channels (to get feedback from remote devices)
- 7 power output channels 1500 W max each (to switch ON and OFF remote devices)
- PBX Voip/GSM server (Asterisk 11 + GSM_dongle)
- remote control by phone by using DTMF tones (I created an IVR that says: "press 1 to switch on relay 1, etc")
- HD video streaming to monitor remote location (MJPG-streamer)
- 2 ways (listen/talk) remote audio streaming by phone (Baresip)
- 2 ways SMS server (receive commands and/or send back alerts/notifications) (Gnokii)
- remote/local control by web page (PHP + uhttpd)
- local control by USB keypad (Triggerhappy)
- restore the channels status after a power failure/reboot (restore the last status ON/OFF just before the power loss)

Maximum power consumption = 15W, one single power supply 12v/2.5A (I keept the original netgear PS)
This BOX can be powered by solar cells and/or by a 12V rechargeable lead battery
To save some electrical power and heating, I removed the (useless) WiFi PCI internal card because it is not supported by Barrier Breaker :( , maybe Chaos Calmer supports it, but C.C. sucks, it is almost useless since there are to many packages missing, included many packages I used in this BOX :mad:

Notes: by having a GSM dongle (GSM calls and SMS), this box can work anywere, even in a place without any internet connection.


I used (cost):

my brain (free) :)
many sleepless nights (almost free)
Openwrt Barrier Breaker (free)
Netgear DGND3700V1 router (Ebay @ 50 Euro)
USB HD webcam (local store @ 30 Euro)
8 channels Relay Board (Ebay @ 10 Euro)
USB GSM dongle Huawei E169 (Ebay @ 15 Euro)
USB audio card (local store @ 5 Euro)
Small speaker (recovered for free from my electronic trash)
USB Keypad (local store @ 5 Euro)
USB Hub (local store @ 5 Euro)

http://www.lovisolo.com/asterisk/software/openwrt/netgear-DGND2700-home-automation/20160911_183045.jpg
http://www.lovisolo.com/asterisk/software/openwrt/netgear-DGND2700-home-automation/20160911_183100.jpg
http://www.lovisolo.com/asterisk/software/openwrt/netgear-DGND2700-home-automation/20160911_183320.jpg
http://www.lovisolo.com/asterisk/software/openwrt/netgear-DGND2700-home-automation/20160911_180049.jpg

Netgear DGND3700V1 has 11 LEDs of wich 9 of them can be used to control 9 relays, fortunately these 9 LEDs do not turn on or do not start blinking during startup process :)

The downside of this router is that the internal PCI WiFi module is bad supported on OpenWRT, as a workaround you can use a different WiFI PCI board or connect an external USB WiFi dongle to the router (or use an ethernet cable).

This router is very powerful: it has 2x400 Mhz CPUs, 2xUSB2 ports, 2 integrated Switch buttons (plus reset) both usable directly by triggerhappy, 1 WAN and 4 LAN Gigabit ethernet connectors, 128 Mbytes of RAM and 32 Mbytes of Flash.

Here are the commands to switch ON the 9 LEDs (to switch them off use "echo 0 > ..."):

/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:blue:wifi5g/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:dsl/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:inet/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:usb-back/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:usb-front/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:wifi2g/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:wps/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:red:inet/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:lan/brightness


LED name, Color, GPIO, #note
power, red, 22, # it turns on at bootup
power, green, 24, # it turns on and starts blinking at bootup
lan, green, 23, # usable
usb-back, green, 14, # usable
wifi2g, green, 26, # usable
wifi5g, blue, 27, # usable
dsl, green, 2, # usable
inet, red, 4, # usable
inet, green, 5, # usable
usb-front, green, 13, # usable
wps, green, 11, # usable


Board switches as seen by triggerhappy:

root@OpenWrt:~# thd --dump /dev/input/event*
EV_KEY KEY_WPS_BUTTON 1 /dev/input/event0
# KEY_WPS_BUTTON 1 command
EV_KEY KEY_WPS_BUTTON 0 /dev/input/event0
# KEY_WPS_BUTTON 0 command
EV_KEY KEY_WLAN 1 /dev/input/event0
# KEY_WLAN 1 command
EV_KEY KEY_WLAN 0 /dev/input/event0
# KEY_WLAN 0 command


KEY_WLAN = gpio-10
KEY_WPS_BUTTON = gpio-35


Usable GPIOs:

root@OpenWrt:~# cat /sys/kernel/debug/gpio
GPIOs 0-37, bcm63xx-gpio:
gpio-2 (DGND3700v1_3800B:gre) out hi
gpio-4 (DGND3700v1_3800B:red) out hi
gpio-5 (DGND3700v1_3800B:gre) out hi
gpio-10 (wlan ) in hi
gpio-11 (DGND3700v1_3800B:gre) out hi
gpio-12 (reset ) in hi
gpio-13 (DGND3700v1_3800B:gre) out hi
gpio-14 (DGND3700v1_3800B:gre) out hi
gpio-22 (DGND3700v1_3800B:red) out hi
gpio-23 (DGND3700v1_3800B:gre) out hi
gpio-24 (DGND3700v1_3800B:gre) out lo
gpio-26 (DGND3700v1_3800B:gre) out lo
gpio-27 (DGND3700v1_3800B:blu) out lo
gpio-35 (wps ) in hi
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

PrecedenteProssimo

Torna a OpenWRT e sistemi operativi vari

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron