veeso / ATtila

Python module to communicate easily with modems and RF modules using AT commands
MIT License
25 stars 10 forks source link

[BUG] Longer Response time commands do not execute properly #6

Open wildbiotiger opened 1 year ago

wildbiotiger commented 1 year ago

Describe the bug It appears that longer executing commands do not collect all the information from the output, e.g. commands such as AT+CGDCONT? and AT+COPS=?. Most of the time, the parser only catches the echo of the command and not the full response.

To Reproduce

atrunenv = ATRuntimeEnvironment(abort_on_failure=True)
atrunenv.configure_communicator(port_name, baud_rate)
atrunenv.open_serial()

# returns ['AT+CGDCONT?'] or ['AT+CGDCONT?', '', '+CGDCONT: 1,"IPV4V6","","0.0.0.0.0.0.0.0.0.0.0'], not all results
cgdcont_result = self.atrunenv.exec('AT+CGDCONT?')
# fails as it parses only the shortened results
cgdcont_result = self.atrunenv.exec('AT+CGDCONT?;;OK;;;;5')

# sometimes times out, sometimes gets the response if a recent scan - inconsistent
cops_result = self.atrunenv.exec('AT+COPS=?;;OK;;;;900')

Expected behavior CGDCONT should capture all data, there were 3 other PDP contexts displayed normally. COPS should wait for the operator scan to complete and return the data.

Desktop (please complete the following information):

Additional context There may be an additional consistency bug. Some of the normal commands failed with no output, but repeating the command succeeds. The CGDCONT always fails however.

lukipuki commented 1 year ago

I've struggled with a similar problem and I've solved it by setting ATE0 . The setting ATE1 is nice for debugging but causes the modem to output two "batches" of data.

I've spent a couple of hours digging through the source code of ATtila and it seems it only expects one "batch" of data, so the two batches caused by a long running command is something that breaks important assumptions.

nabeel-halo commented 1 year ago

Have you tried setting a longer timeout on the communicator? The default is 10 seconds, but you can make it longer:

atrunenv.configure_communicator(port_name, baud_rate, 180.0)

I wonder if that would help it catch longer running commands.

Cloolalang commented 4 months ago

This is a great project, thank-you Christian.

I am developing on a Seeed E5 LoRaWAN modem, I see that there are various AT command response formats;

1) Simple single-line string. 2) Long single-line strings with comma-separated values 3) Multiple line strings, (some with comma-separated values) 4) Multiple line strings with long time delays between receiving them.

To run the Regex over format-3 responses, In atsession.py, use join method to join combine the strings in each line before the re.search

To allow enough time to capture format-4 responses, adjust;

In atcommunbicator.py, Comment out: lines 213 & 214;

if self._device.in_waiting > 0:
                data_still_available = True
            #else:
                #data_still_available = False