Skip to main content

ATtila

Communicate easily with modems and RF modules using AT commands

Developed by @veeso Current version: 1.2.2 (07/09/2022)

pip3 install attila

About ATtila 📢

ATtila is both a Python3 🐍 module and a CLI utility. The module's purpose is to ease the communication with devices through serial port, automating the scripts execution workflow; in particular ATtila is designed for RF modules which use AT commands.

It is both possible to send single AT commands indicating what is the expected response, what information to store for each command and define an alternative behaviour in case of an unexpected responses.
These are the main functionalities that ATtila provides:

  • Façade to communicate with the serial devices
  • Sending AT commands and define the expected response for it
  • Collect values from response and store them in the session storage
  • Define a command to execute in case the previously executed command fails
  • Sending individual AT command to RF module/modem through serial port and get the response

ATtila comes, as said before, with a binary (which can be used instead of the classic chat binary) to pair with pppd, or for anything you want. You can run ATtila binary with

python3 -m attila
#Or if installed, just
attila
Usage: attila [OPTION]... [FILE]

  With no FILE, run in interactive mode

  -p  <device path>     Use this device to communicate
  -b  <baud rate>       Use the specified baudrate to communicate
  -T  <default timeout> Use the specified timeout as default to communicate
  -B  <break>           Use the specified line break [CRLF, LF, CR, NONE] (Default: CRLF)
  -A  <True/False>      Abort on failure (Default: True)
  -L  <logfile>         Enable log and log to the specified log file (stdout is supported)
  -l  <loglevel>        Specify the log level (0: CRITICAL, 1: ERROR, 2: WARN, 3: INFO, 4: DEBUG) (Default: INFO)
  -v                    Be more verbose
  -q                    Be quiet (print only PRINT ESKs and ERRORS)
  -h                    Show this page

Requirements 🛒

  • Python3.5 (>= 1.2.0)
    • Python3.4 (up to 1.1.x - switch to 1.1.x branch)
  • pyserial3

Get Started 🛠

In order to build your own implementation using ATtila these are the steps you need to follow:

  1. Import the AT Runtime Environment into your project

    The first thing you have to do is to import the AT Runtime Environment and the exceptions it can raise in your project

    from attila.atre import ATRuntimeEnvironment
    from attila.exceptions import ATREUninitializedError, ATRuntimeError, ATScriptNotFound, ATScriptSyntaxError, ATSerialPortError
    
  2. Instantiate an ATRuntimeEnvironment object

    atrunenv = ATRuntimeEnvironment(abort_on_failure)
    
  3. Configure the communicator

    This is the component which will communicate with your device

    atrunenv.configure_communicator(device, baud_rate, default_timeout, line_break)
    
  4. Open the serial port

    Be careful, this function can return an ATSerialPortError

    atrunenv.open_serial()
    
  5. Choose how to parse commands:

    1. Parse an ATScript

      parse_ATScript can raise ATScriptNotFound or ATScriptSyntaxError

      atrunenv.parse_ATScript(script_file)
      
    2. Execute directly a command (or an ESK)

      response = atrunenv.exec(command_str)
      
    3. Add an ATCommand to the session

      atrunenv.add_command(command_str)
      
  6. Execute commands:

    1. Run everything at once and then get a list of ATResponse

      if abort_on_failure is True, the ATRE will raise ATRuntimeError during execution

      response_list = atrunenv.run()
      
    2. Run one command a time (if abort_on_failure is True, the ATRE will raise ATRuntimeError):

      response = atrunenv.exec_next()
      
  7. Collect the values you need

    rssi = atrunenv.get_session_value("rssi")
    
  8. Close serial

    atrunenv.close_serial()
    

Virtual Device ⌨

Since version 1.1.0, it is possible to use a virtual serial device, instead of a real one. This has been introduced for test purposes, but can actually be used in case you need to emulate a serial device and you want to keep using ATtila. In this case, in the ATRE, instead of using configure_communicator use:

def configure_virtual_communicator(self, serial_port, baud_rate, timeout = None, line_break = "\r\n", read_callback = None, write_callback = None, in_waiting_callback = None)

The virtual communicator, in addition to the standard one, requires a read, a write and an in_waiting callback. These callbacks must replace the I/O operations of the serial device, with something else (e.g. a socket with an HTTP request)

ATScripts 💻

ATtila uses its own syntax to communicate with the serial device, which is called ATScript (ATS). The basic syntax for it, is:

COMMAND;;RESPONSE_EXPR;;DELAY;;TIMEOUT;;["COLLECTABLE1",...];;DOPPELGANGER;;DOPPELGANGER_RESPONSE

To know more about ATS see the ATScript documentation


Contributions 🤝🏻

Contributions are welcome! 😉

If you think you can contribute to ATtila, please follow ATtila's Contributions Guidelines


Known Issues 🧻

None, as far as I know at least.


Changelog 🕑

View Changelog HERE


Branches 🌳

  • master: stable only with latest features
  • 1.1.x: LTS with Python3.4 support; this version will receive only patch for major issues
  • dev: main development branch
  • other features

Support the developer ☕

If you like ATtila and you're grateful for the work I've done, please consider a little donation 🥳

You can make a donation on the following platforms:

ko-fi PayPal


License 📜

View LICENSE HERE

Metadata

Release files for attila 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for attila 1.2.2
File Size Uploaded
attila-1.2.2.tar.gz 21.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for attila 1.2.2
File Interpreter ABI Platform
attila-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 49.0 kB

Release files / attila-1.2.2.tar.gz

Download URL attila-1.2.2.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a81a1ada868b445cd4be5811c5d8160f76db94348f30303c4c6e95e1f8d9c592
BLAKE2b-256 checksum
How to use checksums
4ada1a2c9967e0f7cbd50bc2dedf3093dd580becdf8bf7171351325ab6d5ce50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / attila-1.2.2-py3-none-any.whl

Download URL attila-1.2.2-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c8cee3d9da2e502d25f024533f806a71f29f35fa339c9b8e59b5480174ef95b
BLAKE2b-256 checksum
How to use checksums
dd3689ff258fe51f83f281737cceabc2505ef1b9c95dcdff116b2909aa53dfd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page