无法使用gammu发送SMS(错误500)

2024-05-17 13:09:13 发布

您现在位置:Python中文网/ 问答频道 /正文

问题:


    pi@raspberrypi:~ $ echo "Test" | sudo gammu sendsms TEXT +937********

    If you want break, press Ctrl+C...
    Sending SMS 1/1....waiting for network answer..error 500, message reference=-1
    Unknown error.

甚至我运行脚本,它也失败了 sms.py


    import gammu
    import sys

    # Create state machine object 
    sm = gammu.StateMachine()
    # Read ~/.gammurc
    sm.ReadConfig()
    # Connect to phone
    sm.Init()

    message= {
        'Text': sys.argv[1],
        'SMSC': { 'Location': 1},
        'Number': sys.argv[2]
    }
    print(message)

    sm.SendSMS(message)
    print("Message Sent...")

输出为


    pi@raspberrypi:~ $ sudo python sms.py "Test Message" 00937********
    {'Text': 'Test Message', 'SMSC': {'Location': 1}, 'Number': '00937********'}
    Traceback (most recent call last):
        File "sms.py", line 18, in 
        sm.SendSMS(message)
    gammu.ERR_UNKNOWN: {'Text': u'Unknown error.', 'Code': 27, 'Where': 'SendSMS'}

Gammu监视器


    SIM phonebook: 0 used, 254 free
    Own numbers: 0 used,   1 free
    Battery level: 0 percent
    Charge state: powered from battery
    Signal strength: -79 dBm
    Network level: 51 percent
    SIM SMS status: 2 used, 0 unread, 70 locations
    Phone SMS status: 0 used, 0 unread, 20 locations
    Network state: requesting network
    Packet network state: requesting network
    GPRS: detached

dmesg|grep tty


    [0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 cma=64M cma=256M video=HDMI-A-1:1920x1080M@60,margin_left=48,margin_right=48,margin_top=48,margin_bottom=48 smsc95xx.macaddr=DC:A6:32:48:2A:DE vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  console=tty1 root=PARTUUID=d9b3f436-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
    [0.000265] console [tty1] enabled
    [0.878196] fe201000.serial: ttyAMA0 at MMIO 0xfe201000 (irq = 34, base_baud = 0) is a PL011 rev2
    [2.523260] systemd[1]: Created slice system-getty.slice.
    [11.364721] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB0
    [11.364939] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB1
    [11.365131] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB2

这里如何知道我们的加密狗连接到哪个ttyUSB0/1/2

gammu——识别


    Warning: No configuration file found!
    Warning: No configuration read, using builtin defaults!
    Device: /dev/ttyUSB0
    Manufacturer: Huawei
    Model: E303 (E303)
    Firmware: 22.157.59.00.00
    IMEI: 864567010180944
    SIM IMSI: 412500242818912

gammu——调试文本AllDate——调试文件/home/pi/gammu.log标识

sudo gammu配置

gammu config命令用于设置配置,这些配置也可以在~/.gammurc文件中找到

sudo gammu——网络信息

sudo gammu getallsms

检查/dev/ttyUSB*的权限


    pi@raspberrypi:~ $ ls -l /dev/ttyUSB*
    crw-rw---- 1 root dialout 188, 0 Jan 15 12:59 /dev/ttyUSB0
    crw-rw---- 1 root dialout 188, 1 Jan 15 12:57 /dev/ttyUSB1
    crw-rw---- 1 root dialout 188, 2 Jan 15 12:57 /dev/ttyUSB2

基于以上详细信息,使用gammu的用户必须是拨号组的成员


    pi@raspberrypi:~ $ id
    uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),105(input),109(netdev),997(gpio),998(i2c),999(spi)

幸运的是,我是拨号组的成员

pi@raspberrypi:~ $ sudo usermod -a -G dialout pi

Tags: tomargindevmessagepisudorootnetwork
1条回答
网友
1楼 · 发布于 2024-05-17 13:09:13

我发现了问题。这是因为wvdial配置不正确。首先确保为wvdial设置正确的配置,并将其设置为gsm文本模式

要正确配置wvdial模式,请遵循本帖子中的步骤https://stackoverflow.com/a/59697399/8403256

相关问题 更多 >