pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
200 stars 166 forks source link

Adding support for AT commands that are longer than 124 bytes. #429

Closed ftylitak closed 4 years ago

ftylitak commented 4 years ago

This Pull Request adds support AT commands of arbitrary length.

The current implementation has an AT command length limit of 124 bytes (LTE_AT_CMD_SIZE_MAX - 4) which is a blocking point when trying to use the complete AT command reference of SEQUANS modem.

The issue has already been reported through #411 and tried to be solved by #414 though not a proper solution has been found. @robert-hh pointed out that bigger buffers would solve the problem though this would affect the buffer handling.

My approach allows to send long AT command in chunks of max size 124. In case the command is smaller than 124 byte long, it will behave as it previously did.

A good example of its usage would be the case of sending byte data through a UDP socket.

from network import LTE
lte = LTE()

# set the socket option to expect the TX bytes to be provided in the form of HEX values.
lte.send_at_cmd('AT+SQNSCFGEXT=1,1,0,0,0,1')

# Open UDP socket in command mode. Google DNS IPv6 address is used of demonstration
lte.send_at_cmd('AT+SQNSD=1,1,5683,"2001:4860:4860::8888",0,8888,1')

# Request the transmission of 70 bytes (which will be 140 long HEX string)
lte.send_at_cmd('AT+SQNSSENDEXT=1,70')

# 140 characters -> 70 bytes. This messages could not be sent with the default implementation.
lte.send_at_cmd('A343164303A3730313A313130303A303A303A303A32303630886368A343164303A3730313A313130303A303A303A303A32303630886368A343164303A3730313A313130303A3')

# Shutdown socket
lte.send_at_cmd('AT+SQNSH=1')

Also allows to pass the 'delay' parameter to the send_at_cmd. It is documented in https://docs.pycom.io/firmwareapi/pycom/network/lte/ though it seems the delay was never actually passed to the underlying code.

Tested and working on gpy device.

amotl commented 4 years ago

Thanks for solving this appropriately, @ftylitak!

cc @LaRox11

ftylitak commented 4 years ago

@peter-pycom thank you for your review.

I have made the changes in the branch and I hope that I have addressed your comments.

It am a bit pussled though because I have pushed the commits in my branch and those commits are not shown here. Normally those are updated automatically in the PR. Any way, I will look it up.

peter-pycom commented 4 years ago

We just merged it internally, so I'm closing this PR. It will be released with next release candidate. Thanks again for the PR @ftylitak !

razvandragomirescu commented 3 years ago

We are experiencing this issue with the latest released firmware, could this please be merged? What is missing? We are sending long APDUs to the SIM via AT+CSIM and it appears that commands of less than 128 bytes work fine, commands over 128 bytes are silently ignored and the response of the previous AT command is returned as the response (very strange) and commands that are exactly 128 bytes appear to freeze the modem (it never replies).