Use RAI in mqtt_simple

Hello,

I want to implement RAI using MQTT, but so far I haven't had success.

I can use RAI without problems through the modem shell, using the command "sock rai -i 0 --rai_last" before each sending of data through the UDP, however I cannot replicate this behavior in the mqtt_simple sample!

I tried sending AT commands in the mqtt_simple sample, through nrf_modem_at_cmd, but sending AT commands (AT%RAI=4, AT%RAI=3, AT%XRAI=1...) did not work.

Should I directly change the socket configuration as is done through the modem shell? How could this be done in the mqtt_simple sample, is it possible to provide some example? I saw several topics with the same question and in none of them there was a solution or working example.

I know the limitations of using RAI over TCP, and I also saw that some people don't recommend it, but I would like to implement and test it in practice.

Thanks.

Parents
  • Hi,

     

    I can use RAI without problems through the modem shell, using the command "sock rai -i 0 --rai_last" before each sending of data through the UDP, however I cannot replicate this behavior in the mqtt_simple sample!

    You are testing a UDP scenario on a TCP-based connection.

    You should not use RAI with any TCP based protocol, due to the three-way ACK in TCP, more detailed information can be found here:

     RE: MQTT service cannot work when RAI is set  

     

    Kind regards,

    Håkon

  • Hello Hakon,

    I had already read this post. I know these limitations and recommendations!

    I don't want to set RAI during the entire MQTT communication, my intention was to set it only on my last packet where I definitely don't need to wait for any more data or send any more data!

    My last package is already identified and distinguished from the others, because in this package I send information regarding the network signal strength, consumption estimate, operator, network and bandwidth used. I would simply like to enable RAI for this package and disable it after the device goes into PSM.

    When I'm going to send this last packet, I've already received everything I should from the network, and I don't need to receive anything else, including not receiving the last ACK, I won't miss anything. I would just like to have an example to try to adapt this to my needs! This RAI issue is very confusing here, some moderators say that it can't be implemented, others say that if it's possible to include only in the last package it might work, but until today I haven't found any example here.

Reply
  • Hello Hakon,

    I had already read this post. I know these limitations and recommendations!

    I don't want to set RAI during the entire MQTT communication, my intention was to set it only on my last packet where I definitely don't need to wait for any more data or send any more data!

    My last package is already identified and distinguished from the others, because in this package I send information regarding the network signal strength, consumption estimate, operator, network and bandwidth used. I would simply like to enable RAI for this package and disable it after the device goes into PSM.

    When I'm going to send this last packet, I've already received everything I should from the network, and I don't need to receive anything else, including not receiving the last ACK, I won't miss anything. I would just like to have an example to try to adapt this to my needs! This RAI issue is very confusing here, some moderators say that it can't be implemented, others say that if it's possible to include only in the last package it might work, but until today I haven't found any example here.

Children
  • Hi,

     

    Thabet said:
    and I don't need to receive anything else, including not receiving the last ACK, I won't miss anything.

    If this is a UDP packet, then it's most likely going to be fine.

    If TCP: This becomes much more complex due to the nature of TCP, with retransmissions etc.

    What happens if you queue data to the socket, with what you think is your last packet, but the modem is still handling re-transmits of your former transaction?

    Then you will end up in a scenario where you terminate the connection before your last packet is sent and ACK'ed by the server.

     

    Testing this with optimal conditions will highly likely always work, but if you test this with a worse signal (ie. RSRP near the RX sensitivity of the radio) and introducing re-transmits on-air, which is a normal use-case for a end-product, you can end up terminating the connection prematurely.

     

    Kind regards,

    Håkon

     

  • Hello,

    What happens if you queue data to the socket, with what you think is your last packet, but the modem is still handling re-transmits of your former transaction?

    Then you will end up in a scenario where you terminate the connection before your last packet is sent and ACK'ed by the server.

    To deal with this, I thought I'd flag in a thread that I'm subscribed when the broker receives the last packet, so I would re-send a "last packet" with the RAI active just to make sure the modem goes to the RRC Idle, that would lead me to having an extra package "unnecessarily" would still save more energy than staying in RRC Connected mode for another 20 seconds, which is the current scenario without using RAI.

    I have a way of knowing when the broker received the last relevant packet, so I would just like an example of how to send a next packet with RAI active to take my device to RRC Idle.

  • Hi,

     

    Thabet said:

    To deal with this, I thought I'd flag in a thread that I'm subscribed when the broker receives the last packet, so I would re-send a "last packet" with the RAI active just to make sure the modem goes to the RRC Idle, that would lead me to having an extra package "unnecessarily" would still save more energy than staying in RRC Connected mode for another 20 seconds, which is the current scenario without using RAI.

    I have a way of knowing when the broker received the last relevant packet, so I would just like an example of how to send a next packet with RAI active to take my device to RRC Idle.

    For anyone else reading this thread, I want to make this as clear as possible:

    RAI + TCP is essentially very hard to implement, so please reconsider.

    For your use-case, you're free to test your scenario with RAI. You can choose the socket option, as per the modem_shell implementation, or to enable RAI on a AT level.

     

    Please note that RAI is supported with NB1, and not LTE M.

     

    Kind regards,

    Håkon

Related