ITCooky Recipes

Lets cooky it yammy things!

How to beat SPAM calls on a landline with Asterisk, IVR, Grandstream ht813 on Raspberry Pi 4!

дата December 11, 2022

As long as you live you must reinstall Asterisk – every time like the first time, solving problems for half a day, I don’t know why that happens! While the video card is training the neural network… Yes, and Orange PC Plus, by the way, from the first article Let’s beat spam calls via PSTN line with Asterisk with IVR by Grandstream ht813 on OrangePi PC Plus! – eMMC died, and the whole system… It’s been a long time since I’ve done anything with Raspberry Pi, the cheapest PC, ooh! So what is happening, why in China the 4Gb version now costs $ 170, and in our country about 250 (ah andOrangePi PC Plus is already worth $40!!!)!!! Well, at least the cases for the RPi haven’t gone up in price, I took the Argon One, the version they no longer produce, I still have many accessories for the raspberry here, that’s the current version with two big HDMI Argon ONE V2 Case for Raspberry Pi 4 for just $25, that much you used to pay for RPi in old times!

That case has an on/off button, a reset button, via an installed script, a cover that allows access to pins and fans, while the CPU and memory are passively cooled through protrusions, transferring heat to the house.

It is clear why the first version (like mine) of this case disappeared, and the second appeared. It is necessary to saw a little so that the raspberry fits into it, the RJ45 connector does not fit.

The case is osom

Install Raspberry Pi OS Lite
The process is eerily simple, download here www.raspberrypi.com/software/ Raspberry Pi Imager and it does all by itself: downloads from the internet ISO and writes it to the SD card. I chose Raspberry Pi OS Lite 32-bit from 2022.09.22

Before recording, you need to set a password and check the SSH box, before now that was done differently. Here you can also configure Wi-Fi, how convenient!

After the end of the recording, the card can be inserted into the raspberry and you have to finde hers received IP, I looked at my router.

Installing the Argon One case script
curl http://download.argon40.com/argon1.sh | bash
Reboot

And to customize
argonone-config

Scheme
We receive a call, Asterisk picks up the phone and plays a message saying: “if you are a human, press 7, otherwise 5 while listening to music. If you press 7, then the phone in the apartment will start ringing!”

Raspberry PI will take care of the voice menu (IVR), while the single SIP phone will connect to the HT813 and call the city directly through it. Binding HT813 FXO port to Asterisk to work together with IVR didn’t work, here Forcing Grandstream ht813 to call via PSTN Asterisk!< /a>… i blame 100500 ticks on HT813!

Instalation of Asterisk
sudo apt-get install asterisk
I start it and watch the status
sudo systemctl start asterisk
systemctl status asterisk

● asterisk.service - Asterisk PBX
     Loaded: loaded (/lib/systemd/system/asterisk.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-11-04 06:38:03 MSK; 1min 5s ago
       Docs: man:asterisk(8)
   Main PID: 7985 (asterisk)
      Tasks: 68 (limit: 4915)
        CPU: 2.568s
     CGroup: /system.slice/asterisk.service
             ├─7985 /usr/sbin/asterisk -g -f -p -U asterisk
             └─7997 astcanary /var/run/asterisk/alt.asterisk.canary.tweet.tweet.tweet 7985

ноя 04 06:38:03 rpiserver asterisk[7985]: [Nov  4 06:38:03] ERROR[7985]: loader.c:2396 load_modules: cel_radius declined to loa>
ноя 04 06:38:03 rpiserver asterisk[7985]: [Nov  4 06:38:03] ERROR[7985]: loader.c:2396 load_modules: cdr_pgsql declined to load.
ноя 04 06:38:03 rpiserver asterisk[7985]: [Nov  4 06:38:03] ERROR[7985]: loader.c:2396 load_modules: cel_tds declined to load.
ноя 04 06:38:03 rpiserver asterisk[7985]: [Nov  4 06:38:03] ERROR[7985]: loader.c:2396 load_modules: pbx_dundi declined to load.
ноя 04 06:38:03 rpiserver asterisk[7985]: [Nov  4 06:38:03] ERROR[7985]: loader.c:2396 load_modules: res_hep_rtcp declined to l>
ноя 04 06:38:03 rpiserver asterisk[7985]: [Nov  4 06:38:03] ERROR[7985]: loader.c:2396 load_modules: chan_unistim declined to l>
ноя 04 06:38:03 rpiserver asterisk[7985]: [Nov  4 06:38:03] ERROR[7985]: loader.c:2396 load_modules: res_hep_pjsip declined to >
ноя 04 06:38:03 rpiserver asterisk[7985]: Asterisk Ready.
ноя 04 06:38:03 rpiserver systemd[1]: Started Asterisk PBX.
ноя 04 06:38:21 rpiserver asterisk[7985]: [Nov  4 06:38:21] NOTICE[8043]: chan_sip.c:29041 handle_request_register: Registratio>

It wirks!

And to run at PC startup
sudo systemctl enable asterisk

Let’s see that it listens to the ports it needs
sudo netstat -tulpn | grep asterisk

tcp        0      0 127.0.0.1:5038          0.0.0.0:*               LISTEN      2491/asterisk       
udp        0      0 0.0.0.0:39348           0.0.0.0:*                           2491/asterisk       
udp        0      0 0.0.0.0:5060            0.0.0.0:*                           2491/asterisk       
udp        0      0 0.0.0.0:4569            0.0.0.0:*                           2491/asterisk       
udp6       0      0 :::47426                :::*                                2491/asterisk

Enter the Asterisk
sudo asterisk -rvvvvv

Asterisk 16.16.1~dfsg-1+deb11u1, Copyright (C) 1999 - 2018, Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 16.16.1~dfsg-1+deb11u1 currently running on rpiserver (pid = 7985)

In extensions.conf at the end add
vi /etc/asterisk/extensions.conf

[users]
exten => 6666,1,Goto(spam_ivr,s,1)
exten => 6001,1,Dial(SIP/6001)
exten => 6002,1,Dial(SIP/6002)
 
[spam_ivr]
exten => s,1,Answer(500)
;exten => s,2,Monitor(wav,,m)
same => n(loop),Background(/var/lib/asterisk/sounds/custom/ivr)
exten => 5,1,Dial(SIP/6001)
exten => 7,1,Dial(SIP/6002)

6002 it will be our actual phone that we want to call when a human is on the call. And the 6001 whose phone isn’t there will just hang up.

The second line in [spam_ivr] is commented out, it records conversations.

In users.conf at the end add
vi /etc/asterisk/users.conf

[6001]
fullname = Test Android
secret = 1234
hassip = yes
context = users
host = dynamic
 
[6002]
fullname = Home phone
secret = 1234
hassip = yes
context = users
host = dynamic

Estas son acaunts de nuestros teléfonos

In the folder /var/lib/asterisk/sounds/custom/ put the wav file prepared in your favorite audio editor, with the words “if you are human press 7” etc! You have to prepare it for Asterisk.
sox ivr.wav --rate 8000 --channels 1 --type ul ivr.ulaw lowpass 3400 highpass 300
was ivr.wav now is ivr.ulaw

Here is the finished file, in Russian ivr.ulaw
Julia_antyspam_ivr

We will restart Asterisk
sudo service asterisk restart

Grandstream ht813 setup
cfgHT813G

These are my settings, for my network and phone!

To begin with, it is necessary that calls from a city telephone line ring on an asterisk!
Let’s go to Grandstream ht813 in the BASIC SETTINGS tab at the bottom type Unconditional Call Forward to VOIP:

This setup throws: all calls arriving on the FXO port are sent to the number 6666 on my asterisk IP address on the port!
To apply the changes click Apply

Then in FXO PORT you have to put…

Here we ride inside, a curious thing! The VoIP gateway cannot hang up on its own, it just doesn’t understand that it has hung up on the other end. To do this, you need to tell it which intermittent beeps to listen for – here, for the RV6699 GPON subscriber terminal, they are like mine.

Here I change Enable Current Disconnect and Enable PSTN Disconnect Tone Detection and STN Disconnect Tone and AC Termination Model and >PSTN Ring Thru FXS

How to find parameters for your line, I will tell below.

Also in the FXO deposit must be enabled Account Active
You must indicate the IP 192.168.1.209 of Asterisk!
And SIP User ID with Authenticate Password the account must be indicated, it must be an account specified in Asterisk in users.conf, although it will not be visible as registered neither in Asterisk nor in HT813, but IVR won’t work without it! No matter the number, this account can be on 6666 or on another number 6789 … here is a strange oddity here, incomprehensible incomprehensibility!

To apply the changes click Apply

And the FSX port will be a regular phone number 6002 I go to FXS PORT

Here I change Primary SIP Server and IP User ID and Authenticate Password
To apply the changes click Apply

To call the city directly from a physical device through HT813 (without going through Asterisk) simply in Dial Plan in FXS PORT we put

{ L:x+ }

Everything typed on a landline lands on the phone line. The beeps, by the way, do not appear immediately, they have to wait!

To apply the changes click Apply , Reboot

How to choose the PSTN disconnection tone for your telephone line?
I called from my mobile phone to my house, I waited for IVR, I pressed the number 7, then cut the call, but the bell continued ringing, Grandstream continues calling even though the call stopped, all that call was recorded by Asterisk! all the sounds!

I pick up the audio file and open it in the program Free, open source, cross-platform audio software Audacity.I select one beep from a series of final beeps and see its spectrogram Analyze > Plot Spectrum…

I take the cursir to the top, and immediately jump to the top, I look down Peak 425Hz 20.1Db

I measure the duration of the beep and the silence between them

It’s at the bottom, just select Length and End of Selection I have 359 milliseconds rounded will be 350

And that’s it, then just substitute in the formula

Syntax: f1=freq@vol, f2=freq@vol, c=on1/off1-on2/off2-on3/off3;
Allowed Range: freq = 0 to 4000Hz; vol = -40 to -24dBm
Default: Busy Tone: f1=480@-32,f2=620@-32,c=500/500;

For my MGTS telephone line through GPON RV6699, I need to insert

f1=425@-21,f2=425@-21,c=350/350;

The peak is one, but there may be more therefore f1 and f2 , for one peak everybody describe it twice, then c is the duration of the beep and silence!

One way or another, now everything works!


Leave a Reply

Your email address will not be published. Required fields are marked *