<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          python-gsmmodem短信發(fā)送和接收庫

          聯(lián)合創(chuàng)作 · 2023-09-30 15:38

          Python實現(xiàn)的短信發(fā)送/接收庫,支持多種型號的短信貓。主要功能有:

          • 發(fā)送短信、檢測信號強度

          • 基于回調(diào)的來電和短信處理方法

          • 支持短信狀態(tài)報告追蹤

          • 使用Python異常包裹AT命令錯誤

          • 模塊化代碼,具有良好的擴展能力

          • 提供了一些簡單的調(diào)試工具。

          示例

          短信接收和回復(fù)

          #!/usr/bin/env python
          
          """\
          Demo: handle incoming SMS messages by replying to them
          Simple demo app that listens for incoming SMS messages, displays the sender's number
          and the messages, then replies to the SMS by saying "thank you"
          """
          
          from __future__ import print_function
          
          import logging
          
          PORT = '/dev/ttyUSB2'
          BAUDRATE = 115200
          PIN = None # SIM card PIN (if any)
          
          from gsmmodem.modem import GsmModem
          
          def handleSms(sms):
              print(u'== SMS message received ==\nFrom: {0}\nTime: {1}\nMessage:\n{2}\n'.format(sms.number, sms.time, sms.text))
              print('Replying to SMS...')
              sms.reply(u'SMS received: "{0}{1}"'.format(sms.text[:20], '...' if len(sms.text) > 20 else ''))
              print('SMS sent.\n')
              
          def main():
              print('Initializing modem...')
              # Uncomment the following line to see what the modem is doing:
              logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
              modem = GsmModem(PORT, BAUDRATE, smsReceivedCallbackFunc=handleSms)
              modem.smsTextMode = False 
              modem.connect(PIN)
              print('Waiting for SMS message...')    
              try:    
                  modem.rxThread.join(2**31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal
              finally:
                  modem.close();
          
          if __name__ == '__main__':
              main()
          瀏覽 28
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  波多野结衣一二三区 | 狠狠综合一区 | 污污污污污www网站免费观看 | 丁香色午夜| 久久艹国产 |