Problems with Things Network Downlink (LoRaWANStack.cpp)

Hi, I’ve been having problems with trying to send data to a Things Network node. I’ve tracked it down to this section of code
if (_rx_msg.msg.mcps_indication.port != port || !(flags & received_flags)) {
If I add an extra set of brackets to get this
if (_rx_msg.msg.mcps_indication.port != (port || !(flags & received_flags))) {
it works OK, however I don’t understand why the extra set of brackets should make any difference.

Any suggestions?

Best wishes,


Hi Jeremy,
You are just changing the order of operation of the logic. Before the bracket, you would compare the port and rx_msg.msg.mcps_indication.port and then do a logical “or” with “!(flags & received_flags)”. After the bracket, you are comparing rx_msg.msg.mcps_indication.port and “(port || !(flags & received_flags)”. Therefore, the second work probably because you isolate the pin and then compare with the rx_msg.msg.mcps_indication.port.


Hi Peter,

Thanks for the reply. I had spotted this almost immediately after I posted the message to the forum (it had been a long day) , but due to the permission required for the forum I couldn’t get back in and edit my post.

With hindsight I still think this code
(_rx_msg.msg.mcps_indication.port != port || !(flags & received_flags))
would be better written as
((_rx_msg.msg.mcps_indication.port != port) || !(flags & received_flags))
I’m not a great fan of having to remember precedence.

For those looking at the Things Network and Lorawan, the problem was I wasn’t sending the message to the right port, which under MBED is port 15. This is defined by the macro MBED_CONF_LORA_APP_PORT which is in the mbed_config.h file if you export the mbed project to uVision. I don’t think I found how to change it in the MBed cloud environment.

Thanks again,