IOS-nRF-Mesh-Library icon indicating copy to clipboard operation
IOS-nRF-Mesh-Library copied to clipboard

Send message await forever

Open jack8525 opened this issue 1 year ago • 11 comments

Where do you suspect the issue?

Issue in mesh library, e.g. packets being dropped

Version

4.1.0 (latest)

Describe the issue

_ = try? await globalMeshNetworkManager?.send(meshMessage, to: MeshAddress(sendMessageTask.address), using: applicationKey)

I send an AcknowledgedMeshMessage but get bearerDidClose error. image this else isn't handled, so the library awaits forever. What should I do?

jack8525 avatar Jan 04 '24 03:01 jack8525

Thank you for reporting the issue. I'll look into it and come back to you.

philips77 avatar Jan 04 '24 10:01 philips77

For Acknowledged messages there's a timer on Access Layer that should try to retransmit the message and time out eventually.

philips77 avatar Jan 04 '24 10:01 philips77

OK. I see where the issue may occur.

AccessLayer sets the repeat & timeout timer only for acknowledge messages sent to a Unicast Address: https://github.com/NordicSemiconductor/IOS-nRF-Mesh-Library/blob/293210d4827ab865462f70aa32daa9493cb13fbd/nRFMeshProvision/Layers/Access%20Layer/AccessLayer.swift#L239-L244

That means, that acknowledged messages sent to a Group Address (or Virtual Address) don't get that timer set. Such messages may be sent to 0+ nodes and the transmitter can receive 0+ responses. In that case, it is the underlying layer that should notify the network manager, just like for unacknowledged messages.

However, as you pointed out, when the Acknowledged Mesh Message is unsegmented, like ConfigOnOffSet, and sending the message fails, the network manager is never notified: https://github.com/NordicSemiconductor/IOS-nRF-Mesh-Library/blob/293210d4827ab865462f70aa32daa9493cb13fbd/nRFMeshProvision/Layers/Lower%20Transport%20Layer/LowerTransportLayer.swift#L257-L260

I'll prepare a fix.

philips77 avatar Jan 04 '24 11:01 philips77

image

philips77 avatar Jan 04 '24 12:01 philips77

Btw, for multicast addresses it is recommended not to use Acknowledged messages, but their Unacknowledged counterparts. This significantly decreases the traffic in the network.

philips77 avatar Jan 04 '24 12:01 philips77

Hmm... I did some more digging and seems like the Network Layer doesn't throw bearerDidClose when the message is sent to a group address, as such message may be handled internally: https://github.com/NordicSemiconductor/IOS-nRF-Mesh-Library/blob/293210d4827ab865462f70aa32daa9493cb13fbd/nRFMeshProvision/Layers/Network%20Layer/NetworkLayer.swift#L156-L167

This is the shouldLoopback method: https://github.com/NordicSemiconductor/IOS-nRF-Mesh-Library/blob/293210d4827ab865462f70aa32daa9493cb13fbd/nRFMeshProvision/Layers/Network%20Layer/NetworkLayer.swift#L444-L450

As you're getting that error, that means, that you're sending the message to a Unicast Address. In that case, the network manager should wait until the response is received from the target, which happens on Access Layer. I'll leave #600 open, but don't think it's required.

philips77 avatar Jan 04 '24 13:01 philips77

Could you say what message are you trying to send exactly, what are your network parameters (default?) and what is the destination address of the message?

philips77 avatar Jan 04 '24 13:01 philips77

Thank you for your help. I just send some GenericOnOffSet to a Unicast Address when not connected.In this case, a timeout will not be thrown?

jack8525 avatar Jan 05 '24 01:01 jack8525

There will be a timeout. The timeout is set using: https://github.com/NordicSemiconductor/IOS-nRF-Mesh-Library/blob/293210d4827ab865462f70aa32daa9493cb13fbd/nRFMeshProvision/Layers/NetworkParameters.swift#L219-L230 Documentatuion

philips77 avatar Jan 05 '24 12:01 philips77

I found failedToSendMessage is no callback. Because Address change to MeshMessage. After fix it. I can handle the timeout here.

jack8525 avatar Jan 06 '24 09:01 jack8525

image Can I handle deliveryCallbacks here?

jack8525 avatar Jan 06 '24 09:01 jack8525