Coder Social home page Coder Social logo

arceryz / atlib Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 21 KB

Send and receive SMS/texts using Python. Low and high level API for sending AT commands over serial bus. Tested with SIM800L.

License: MIT License

Python 100.00%
python serial atcommands raspberry-pi sim800l sms sms-api texting pyserial python-library

atlib's Introduction

ATlib

Python library for sending and receiving SMS texts using AT commands. Higher and lower level features supported. Tested with SIM800L.

The API is relatively straightforward. The API is not asynchronous meaning all methods return the result directly. Take a look at atlib.py for the full library.

For an application of this library, see gsm-agent. Where SMS messages can used to run shell scripts on a server (with security checks & registration).

API

The API features two classes for interfacing with the GSM modem.

The low level is the AT_Device class. This class exposes only a synchronous API for sending AT commands and reading responses. It abstracts the painful process of AT commands not directly responding due to latency. Responses are detected by a terminated OK or ERROR string. The read() commands returns a tokenized list of the reply for easy parsing.

  • Opening serial connection.
  • Synchronizing baudrate using sync_baudrate() (by sending "AT" and awaiting response).
  • Sending AT commands.
  • Reading AT commands reliably.
  • Detecting errors.

The high level is the GSM_Device class. This class inherits from AT_Device. This class provides higher level features such as

  • Unlocking the device sim using pin.
  • Sending text messages.
  • Reading text messages (by category unread, all, read, etc).

This is still a w.i.p class for my personal use cases. Might be extended with call support later on.

Contributing

If you have problems with your modem, you can open issues here. I have tested all commands with a properly hooked up SIM800L on a Raspberry Pi Bullseye. Know that not all devices support all AT commands, and therefore may fail when using this library. However most devices should support the basics.

Examples

A minimal example can be found in /examples directory. Refer to the library itself to see many AT commands in action already (e.g sending commands, checking responses). See below for a minimal texting application:

#!/bin/python
# Console SMS sender using ATlib.

from atlib import *

gsm = GSM_Device("/dev/serial0")
if gsm.is_sim_locked():
    pin = input("SIM Pin: ")
    gsm.unlock_sim(pin)
else:
    print("SIM already unlocked.")

while True:
    print("")
    nr = input("Phone number: ")
    msg = input("Message: ")

    if gsm.send_sms(nr, msg) != OK:
        print("Error sending message.")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.