Skip to content

Fix CoAP test stability and runtime issues#70

Open
tfeseker wants to merge 2 commits into
QuickSpot:mainfrom
tfeseker:fix/coap-tests-stability
Open

Fix CoAP test stability and runtime issues#70
tfeseker wants to merge 2 commits into
QuickSpot:mainfrom
tfeseker:fix/coap-tests-stability

Conversation

@tfeseker
Copy link
Copy Markdown
Contributor

I tried to run test_coap and ran into a few issues with the coap mixin. With the proposed changes, the test is successful.

@daanpape daanpape requested a review from FoxyHunter7 May 11, 2026 08:58
@daanpape
Copy link
Copy Markdown
Contributor

Hi @tfeseker, thank you very much for your pull request. @FoxyHunter7 will review your changes and merge them accordingly.

Comment on lines +17 to +30
CELL_APN = ''
APN_USERNAME = ''
APN_PASSWORD = ''
AUTHENTICATION_PROTOCOL = WalterModemPDPAuthProtocol.NONE
SIM_PIN = None

COAP_SERVER_ADDRESS = 'coap.me'
COAP_SERVER_PORT = 5683
COAP_PATH = 'test'
COAP_PAYLOAD = '{"message":"Hello from Walter MicroPython"}'

COAP_CTX_ID = 0
COAP_TIMEOUT_SECONDS = 60
RING_WAIT_SECONDS = 20
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CELL_APN = ''
APN_USERNAME = ''
APN_PASSWORD = ''
AUTHENTICATION_PROTOCOL = WalterModemPDPAuthProtocol.NONE
SIM_PIN = None
COAP_SERVER_ADDRESS = 'coap.me'
COAP_SERVER_PORT = 5683
COAP_PATH = 'test'
COAP_PAYLOAD = '{"message":"Hello from Walter MicroPython"}'
COAP_CTX_ID = 0
COAP_TIMEOUT_SECONDS = 60
RING_WAIT_SECONDS = 20
# IMPORTANT
# This is an example sketch with verbose comments and logging,
# in production code such verbose comments could be left out to reduce codesize.
CELL_APN = ''
"""
The cellular Access Point Name (APN).
Set to the APN provided by your network provider.
Leave blank for automatic APN detection only if your provider supports it
"""
APN_USERNAME = ''
"""
The username for APN authentication.
Typically, this is not required and should be left blank.
Only provide a username if your network provider explicitly mandates it.
"""
APN_PASSWORD = ''
"""
The password for APN authentication.
This is generally unnecessary and should remain blank.
Set a password only if it is specifically required by your network provider.
"""
AUTHENTICATION_PROTOCOL = WalterModemPDPAuthProtocol.NONE
"""
The authentication protocol to use if required.
Leave as none when no username/password is set.
"""
SIM_PIN = None
"""
Optional: Set this only if your SIM card requires a PIN for activation.
Most IoT SIMs do not need this.
"""
COAP_SERVER_ADDRESS = 'coap.me'
"""
The address of the CoAP server.
"""
COAP_SERVER_PORT = 5683
"""
The port of the CoAP server to use.
"""
COAP_PATH = 'test'
"""
The CoAP path on which to send.
"""
COAP_PAYLOAD = '{"message":"Hello from Walter MicroPython"}'
"""
The CoAP payload to transmit.
"""
COAP_CTX_ID = 0
"""
The CoAP context ID to use for this connection.
"""
COAP_TIMEOUT_SECONDS = 60
"""
Maximum time in seconds to wait for a CoAP confirmable message acknowledgement.
If no ACK is received within this window the request is considered failed.
"""
RING_WAIT_SECONDS = 20
"""
Maximum time in seconds to wait for an incoming CoAP ring (response notification)
after sending a request.
"""


# endregion

modem = Modem(CoapMixin, load_default_power_saving_mixin=False)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
modem = Modem(CoapMixin, load_default_power_saving_mixin=False)
modem = Modem(CoapMixin, load_default_power_saving_mixin=False)
"""
The modem instance
Loading the MQTT mixin for MQTT functionality.
Loading the TLSCertsMixin to work with tls profiles.
Specificying to not load the default power saving mixin,
as we're not using it in this simple example.
Although in most real-life scenarios it is advised to
configure power-saving for reduced energy consumption
"""

# endregion

modem = Modem(CoapMixin, load_default_power_saving_mixin=False)
modem_rsp = WalterModemRsp()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
modem_rsp = WalterModemRsp()
modem_rsp = WalterModemRsp()
"""
The modem response object that is (re-)used
when we need information from the modem.
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great CoAP example sketch!

However, to stay consistent with the examples sketches it would be best to add verbose comments to config variables and code functions. This to help new programmers to understand code better rather than blindly copy pasting.

I've left a few change-suggestions as examples of what I mean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants