Package: attila
ATtilaCommunicate easily with modems and RF modules using AT commandsDeveloped by@veesoCurrent version: 1.2.2 (07/09/2022)pip3installattilaAbout ATtila 📢ATtila is both aPython3 🐍 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 devicesSending AT commands and define the expected response for itCollect values from response and store them in the session storageDefine a command to execute in case the previously executed command failsSending individual AT command to RF module/modem through serial port and get the responseATtila comes, as said before, with a binary (which can be used instead of the classicchatbinary) to pair withpppd, or for anything you want.
You can run ATtila binary withpython3-mattila#Or if installed, justattilaUsage: 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 pageRequirements 🛒Python3.5 (>= 1.2.0)Python3.4 (up to 1.1.x - switch to1.1.xbranch)pyserial3Get Started 🛠In order to build your own implementation using ATtila these are the steps you need to follow:Import the AT Runtime Environment into your projectThe first thing you have to do is to import the AT Runtime Environment and the exceptions it can raise in your projectfromattila.atreimportATRuntimeEnvironmentfromattila.exceptionsimportATREUninitializedError,ATRuntimeError,ATScriptNotFound,ATScriptSyntaxError,ATSerialPortErrorInstantiate an ATRuntimeEnvironment objectatrunenv=ATRuntimeEnvironment(abort_on_failure)Configure the communicatorThis is the component which will communicate with your deviceatrunenv.configure_communicator(device,baud_rate,default_timeout,line_break)Open the serial portBe careful, this function can return anATSerialPortErroratrunenv.open_serial()Choose how to parse commands:Parse an ATScriptparse_ATScript can raiseATScriptNotFoundorATScriptSyntaxErroratrunenv.parse_ATScript(script_file)Execute directly a command (or an ESK)response=atrunenv.exec(command_str)Add an ATCommand to the sessionatrunenv.add_command(command_str)Execute commands:Run everything at once and then get a list of ATResponseifabort_on_failureisTrue, the ATRE will raiseATRuntimeErrorduring executionresponse_list=atrunenv.run()Run one command a time (ifabort_on_failureis True, the ATRE will raiseATRuntimeError):response=atrunenv.exec_next()Collect the values you needrssi=atrunenv.get_session_value("rssi")Close serialatrunenv.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 usingconfigure_communicatoruse:defconfigure_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 aread, awriteand anin_waitingcallback. 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 calledATScript(ATS).
The basic syntax for it, is:COMMAND;;RESPONSE_EXPR;;DELAY;;TIMEOUT;;["COLLECTABLE1",...];;DOPPELGANGER;;DOPPELGANGER_RESPONSETo know more about ATS see theATScript documentationContributions 🤝🏻Contributions are welcome! 😉If you think you can contribute to ATtila, please follow ATtila'sContributions GuidelinesKnown Issues 🧻None, as far as I know at least.Changelog 🕑View ChangelogHEREBranches 🌳master: stable only with latest features1.1.x: LTS with Python3.4 support; this version will receive only patch for major issuesdev: main development branchother featuresSupport 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:License 📜ViewLICENSE HERE