Database error after creating a block caller list

My setup-
Asterisk version 15 on my home router with openwrt 15 variant.

Hello I am new to asterisk, I have a very basic setup for my home.
1 Gateway with 1 landline attached and a cell (mobile) phone on WiFi.

I am trying to create a block caller list on my device.

I have added to my database a number and checked it is there.

/blockcaller/222 : 1

I am calling from exten 222 to exten 333, no matter if 222 is on the database or not I get the Number_not_avaliable playback.

I added the following code to my extensions.conf-

exten => 333,1,NoOp(line1)
same => n,GotoIf($[“${DB(blockcaller/${CALLERID(num)})}” = “1”]?blocked)
same => n(blocked),Playback(Number_not_avaliable)

I get the following in the CLI-

– Executing [333@phones:1] NoOp(“SIP/mobile-home-00000020”, “line 1”) in new stack
ERROR[14546][C-00000014]: pbx_functions.c:606 ast_func_read: Function DB not registered
– Executing [333@phones:2] GotoIf(“SIP/mobile-home-00000020”, “0?blocked”) in new stack
– Executing [333@phones:3] Playback(“SIP/mobile-home-00000020”, “Number_not_avaliable”) in new stack
– <SIP/mobile-home-00000020> Playing ‘Number_not_avaliable.alaw’ (language ‘en’)

The only thing I could find close to my issue is here and I do not have the files mentioned in the thread.
However I am not sure if every asterisk is meant to have this or if it is just certain systems. My system is very small and running on a modified version of openwrt.
My query-
If my system is damaged or missing the file, how can I repair it of do I need to reinstall asterisk?
Maybe my goto is wrong?
If the DB is damaged is there another way I can do the block caller in the extensions.conf so I don’t have to use the database? I only have 3 numbers I want to block for now.

Thanks for any help.

Asterisk is modular, it can be chosen what modules to build and be available. It sounds like the dialplan database one is not available on yours. It would be the func_db module.

1 Like

Thanks for the reply, yes I have only loaded what I need as it has to be small for my device.
Thank you very much you have given me the answer I needed as I did not know where the func_db module was.
From your answer I see that it is in the asterisk15-func-dialplan.ipk.
Do you think I need to install any other .ipk to satisfy this error?
What I installed initially was-
asterisk15 asterisk15-bridge-simple asterisk15-codec-alaw asterisk15-codec-ulaw asterisk15-res-rtp-asterisk asterisk15-chan-iax2 asterisk15-app-queue asterisk15-chan-sip

Thanks again you saved me, I was about to give up.

I have no idea, I have never used such packages or have any involvement in them.

OK, so after installing I still got the error so I searched the install files for asterisk15-func and came up with asterisk15-func-db.ipk.
Installed this and then in my /usr/lib/asterisk/modules I see the file
I went to CLI and did -
module load
but this did not work so I changed the name of my new file from to then did -
module load
in CLI and it worked.

There is still something wrong with my extensions.conf file as the error is gone but the Goto command is not working. I will look at it later as I have no time now.
If anyone can see what is wrong with my Goto command please let me know. :wink:

1 Like

You said you have the following lines in your dialplan:

same => n,GotoIf($[“${DB(blockcaller/${CALLERID(num)})}” = “1”]?blocked)
same => n(blocked),Playback(Number_not_avaliable)

What is supposed to happen if the test fails (ie: the DB result is not “1”?).

This dialplan will simply drop through to the next line in sequence in that
case, and therefore your “blocked” label and the Playback command gets
processed every time.

I would suggest instead something like:

same => n,GotoIf($[“${DB(blockcaller/${CALLERID(num)})}” != “1”]?allowed)
same => n,Playback(Number_not_avaliable)
same => n,Hangup()

same =>n(allowed), carry on and do whatever you want to with the call


1 Like

He fixed problem, error cause by module func_DB not loaded

Hi Anthony,
Yes you are absolutely right, that is what is happening, the blocked Playback gets played every time.
Your code is much better and I can follow the logic.
As I am a novice my Goto was pieced together from what info I could find with a internet search.
I have put your lines in and the first part works great but I cant test when I add number to DB.
For some strange reason now I can’t add to the database, in CLI I tried-
database put blockcaller 222 1
and get error-
WARNING[14744]: db.c:348 ast_db_put: Couldn’t execute statment: SQL logic error or missing database
This has only occured after I fixed the prevoius error by installing the asterisk15-func-dialplan.ipk and asterisk15-func-db.ipk
I will have to do more research into why I am getting this error now.

Anthony thanks for the code, I love it.

I tried to find the problem, but had no luck.
I tried adding permission to the DB for asterisk user-
chown -R asterisk /usr/lib/asterisk
no good.
I performed the steps in the last post on this thread.
Still no luck.
I am thinking about removing asterisk15-func-dialplan.ipk and asterisk15-func-db.ipk temporary to see if that will allow me to add to the database.
Strange thing is I can view the database with-
database show

I fixed this by stopping asterisk-
/etc/init.d/asterisk stop
removing asterisk DB

cd /usr/lib/asterisk
rm astdb.sqlite3

and restarting asterisk-
/etc/init.d/asterisk start
This made a new astdb file.
But you loose everything in the old file so check first and maybe backup.
I had nothing else important in mine.

1 Like

I tested the new code after I fixed the database problems, but now both times it went through with the call. Even when the database had the calling number in the block caller list.
/blockcaller/222 : 1
So it kinda did the exact opposite of what the original code did. I have no idea why.

Have you checked what ${DB(blockcaller/${CALLERID(num)})} actually returns?

That said, you are likely to run into more problems with openwrt. Years ago, the Asterisk packages were not really well maintained and meanwile the OS has been upgraded giving more chances to break things. Sucess probably depends on how much of Asterisk you intend to use.

Also, you generally do not know a lot about the background of the packages. I think it is far easier to build from source on an extra box with an OS that one knows really well.

I think a VoIP proxy (like a basic Kamailio) on a router is fine, but not a program like Asterisk that rquires a lot of additional libraries.

1 Like

After many hours of trying to figure out what was wrong with it. I had a "you plonker!’ moment.
I was testing the code using my internal numbers, dialing something like 222 but the callerID on these numbers is not 222 rather the name of the extension.
So now I feel like a right fool, but I guess that is what happens when you are not experienced.
From now on my extensions will start like this-
exten => xxx,1,NoOp(${CALLERID(num)})
Learn from my mistake all you novices.

Everything works nice now, my next task to to get incoming calls to forward to my cell (mobile) with the callerID showing, when there is no one there to answer them. More reading ahead.

Thanks for the reply EkFudrek as you can see above I got it working.
I did look into Kamailio but I could not find many tutorials online so I stuck with asterisk.
The device I am using is a all in one device and I can plug a land line phone into it, which is what I need as I have elderly people living in the house also. All in one devices with landline phone ports seem hard to get.
I will start with basic asterisk but it does have a 4G sim card slot in the device and it would be nice to get messing with that- sms forwarded to email and forwarding the sim line for access when overseas
I would like to be able to access the device when overseas and get calls.from all phones, maybe openVPN. But baby steps for now.

openVPN related to your OS , not related to asterisk.

you can search guide to setup openVPN on your linux server, many guide on internet.

Yes thank you for the reply, I have been looking into the VPN and have used openVPN on a raspberry pi in the past. I hope to try wireguard if my firmware is able to work with it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.