返回列表 發帖

Chan_Dongle 收SMS亂碼

有兩種情況, 有一種直情整死個process, quit左, 連有SMS都唔知.
第二種係出怪碼, SMS forward去email會變成一個垃圾 noname attachment. 會知道收左個SMS但係內容唔知.
有冇解決方法呢?

用既係華為 E180.

本帖最後由 mcdull 於 2017-8-24 18:21 編輯

留返第時recover 用.

dongle.conf

[dongle0]
;audio=/dev/            ; tty port for audio connection;        no default value
;data=/dev/             ; tty port for AT commands;             no default value
imei=XXXXXXXXXXXXXX

[dongle1]
;audio=/dev/           ; tty port for audio connection;        no default value
;data=/dev/             ; tty port for AT commands;             no default value
imei=XXXXXXXXXXXXXX

[dongle2]
;audio=/dev/           ; tty port for audio connection;        no default value
;data=/dev/             ; tty port for AT commands;             no default value
imei=XXXXXXXXXXXXXX

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${DONGLENAME})
exten => sms,3,System(echo " " >> /var/log/asterisk/smsmail${DONGLENAME})
exten => sms,4,System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}' >> /var/log/asterisk/smsmail${DONGLENAME})
exten => sms,5,System(echo " " >> /var/log/asterisk/smsmail${DONGLENAME})
exten => sms,6,System(echo "${BASE64_DECODE(${SMS_BASE64})}" >> /var/log/asterisk/smsmail${DONGLENAME})
exten => sms,7,System(cat /var/log/asterisk/smsmail${DONGLENAME} | tr -d '\r' | mailx -s "SMS Recevied from ${CALLERID(num)} by ${DONGLENUMBER} " -r "fromemail@gmail.com" -S smtp="XXX.XXX.XXX.XXX" toemail@gmail.com)
exten => sms,n,System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)} - ${CALLERID(dnid)}: ${BASE64_DECODE(${SMS_BASE64})}  /////  ${CMGR}' >> /var/log/asterisk/sms${DONGLENAME}.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},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}: ${BASE64_DECODE(${USSD_BASE64})}' >> /var/log/asterisk/ussd${DONGLENAME}.txt)
exten => ussd,n,System(cat /var/log/asterisk/ussd${DONGLENAME}.txt | tr -d '\r' | mailx -s "USSD Recevied from ${CALLERID(num)} by ${CALLERID(dnid)}" -r "fromemail@gmail.com" -S smtp="xxx.xxx.xxx.xxx" toemail@gmail.com)
exten => ussd,n,Hangup()

TOP

Known issue.

Cannot identify concated messages.  It will generate multiple emails in random orders.
Please let me know on how I can fix it. Thanks.

TOP

The most current development of chan_dongle.
https://github.com/wdoekes/asterisk-chan-dongle/issues/40

TOP

update:

all " should be replaced by '

TOP

if your sim has an unknown number, you can store it with the following command.

dongle cmd dongle0 AT+CPBS=\"ON\"
dongle cmd dongle0 AT+CPBW=1,\"+556191000000\",145

TOP

有冇人知道點樣可以將幾個SMS 砌返埋一齊?
分析CMGR係可以知佢係咪split左, 但係 CMGR好似唔係fixed length.

TOP

  1. [from-pstn-custom]
  2. include => dongle-incoming-sms
  3. include => dongle-incoming-ussd

  4. [dongle-incoming-sms]
  5. exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
  6. exten => sms,2,System(echo '${BASE64_DECODE(${SMS_BASE64})}' >> /var/log/asterisk/smscontent${DONGLENAME})
  7. exten => sms,3,System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)} - ${CALLERID(dnid)}: ${BASE64_DECODE(${SMS_BASE64})}  /////  ${CMGR}' >> /var/log/asterisk/sms${DONGLENAME}.txt)
  8. exten => sms,4,System(echo "INSERT INTO sms (DONGLENAME,CALLERID,EPOCH,SMS_BASE64,DONGLENUMBER,CMGR) values ('${DONGLENAME}','${CALLERID(num)}','${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)}','${BASE64_DECODE(${SMS_BASE64})}','${DONGLENUMBER}','${CMGR}')\;" > /var/log/asterisk/smssql${DONGLENAME}.txt)
  9. exten => sms,5,System(mysql -uuser -ppassword -h192.168.0.1 -P3307 smslog < /var/log/asterisk/smssql${DONGLENAME}.txt)
  10. exten => sms,6,Set(channelID=${CHANNEL:-10:8})
  11. exten => sms,7,System(echo '${CMGR}' > /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID})
  12. exten => sms,8,System(awk '{if ( NR == "2" ) print}' /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID} | tee -a /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})
  13. exten => sms,9,NoOp(cmdstr = /usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})))
  14. exten => sms,10,Set(completeSMS=${SHELL(/usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID}))})
  15. exten => sms,n,NoOp(result is ${completeSMS})
  16. exten => sms,n,Set(completeSMS=${completeSMS:0:1})
  17. ;exten => sms,9,Set(completeSMS=${SYSTEMSTATUS})
  18. ;exten => sms,n,System(echo ${completeSMS})
  19. exten => sms,n,System(rm -f /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID})
  20. exten => sms,n,System(rm -f /var/log/asterisk/smsCMGRraw${DONGLENAME}_${channelID})
  21. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?wait(10))
  22. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(echo 'Subject: SMS received from ${CALLERID(num)}' > /var/log/asterisk/smsmail${DONGLENAME})
  23. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(echo ' ' >> /var/log/asterisk/smsmail${DONGLENAME})
  24. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}' >> /var/log/asterisk/smsmail${DONGLENAME})
  25. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(echo ' ' >> /var/log/asterisk/smsmail${DONGLENAME})
  26. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(cat '/var/log/asterisk/smscontent${DONGLENAME}' >> /var/log/asterisk/smsmail${DONGLENAME})
  27. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(cat '/var/log/asterisk/smsmail${DONGLENAME}' | tr -d '\r' | mailx -s 'SMS Recevied from ${CALLERID(num)} by ${DONGLENUMBER} ' -r 'xxxxx@myemail.com' -S smtp='192.168.0.1' xxxxx@gmail.com)
  28. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(rm -f /var/log/asterisk/smscontent${DONGLENAME})
  29. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(echo 'I am DONE' >> /var/log/asterisk/test${DONGLENAME})
  30. exten => sms,n,ExecIf($[ ${completeSMS}!=1 ]?System(echo '${STRFTIME(${EPOCH},Hongkong,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${completeSMS}' >> /var/log/asterisk/test${DONGLENAME})
  31. exten => sms,n,System(asterisk -rx 'dongle cmd ${DONGLENAME} AT+CMGD=1,4')
  32. exten => sms,n,Hangup()
複製代碼

TOP

經幾星期發癲, 暫時做到我想佢做既野... asterisk dialplan function 好鬼煩, 尤其係啲 variable.

TOP

  1. exten => sms,10,Set(completeSMS=${SHELL(/usr/bin/python /etc/asterisk/pdudecode.py $(cat /var/log/asterisk/smsPDUraw${DONGLENAME}_${channelID}))})
複製代碼
What is the logic behind in your python to check if all SMS received?

TOP

What is the logic behind in your python to check if all SMS received?
ttmuskie 發表於 2017-9-26 19:51



the python will return 0 if the SMS is single or the last part of the concat message.
and 1 if the SMS is incomplete.. yet.

Originally I intended to use exit code but I cannot capture the return result properly. So I changed it to use the print out.

TOP

How to check if that's a single SMS or last part of the concat msg?

TOP

That was the tricky part.  I initially want to decode the pdu just for the concat msg information.  And it was found too complicated and I had to decode much variation of UDH. A lot of tools were available online only. And local library will NOT decode concat message correctly.  So I have to make reference to http://smspdu.benjaminerhart.com/
I have much hesitation to post my sms online as it may contain verification from online banking, so I pulled the javascript (source provided in the site).  With the same reason, I given up to port the javascript to python, so I have to set up a webserver (luckily I already got my own) and use beautifulsoup to capture the output for return.

TOP

  1. #!/usr/bin/env python
  2. #coding:utf-8
  3. import sys
  4. import unittest2
  5. from selenium import webdriver
  6. from bs4 import BeautifulSoup

  7. driver = webdriver.PhantomJS()
  8. pdu = str(sys.argv[1])
  9. concatpart = '1'
  10. concattotal = '1'
  11. url = 'http://xxx.xxx.xxx.xxx/jsPduDecoder-master/index.html?pdu='
  12. driver.get(url+pdu)
  13. soup = BeautifulSoup(driver.page_source, 'html.parser')
  14. udhs = soup.findAll('td', text = 'User Data Header')
  15. for i in udhs:
  16.     if i.next_sibling.get_text().find('Concatenated message') != -1:
  17.         s = i.next_sibling.get_text()
  18.         concatpart = s[s.find("part")+5:s.find("part")+6]
  19.         concattotal = s[s.find("parts")-2:s.find("parts")-1]
  20.         if concatpart == concattotal:
  21.             print '0 Message Completed'
  22.             sys.exit(0)
  23.         else:
  24.             print '1 Message Incomplete. ' + s
  25.             sys.exit(1)
  26. print '0 Single Message'
  27. sys.exit(0)
複製代碼
I will use only the first return character as specified in the dialplan rule.

TOP

These should work with multiple dongles.  I have 5 installed currently but it is not stable.  I guess the hub cannot power 5 dongles so I removed one and left 4.

TOP

返回列表