@harish-kumar Well, you're not sleeping, so you shouldn't need to nvram_save/restore, but you're re-creating the LoRa object (twice!) in your loop, using two different modes (raw LoRa and LoRaWAN), and re-joining each time, so no wonder your frame counters get re-initialised.
I'm really not sure you can use the current LoRa stack like this to achieve what you want. I'm quite certain it would require some extensive changes to the stack, especially if you really want to maintain true LoRaWAN compatibility (i.e. including ADR, MAC commands, etc.).
I am using Lopy, I am new to this. I need to send some data to cloud via Lorawan instead of using wifi. Is it possible ? If it is , can anyone say me the procedures ?
First check whether LoRaWAN is good for your application, it depends on the volume of data you are transmitting, what is the latency your application can accept, etc. Provide details. If it fits to your use case from networking view we can discuss how to implement.
Yes I use a similar thing for my commercial product. But remember that nodes may miss (due to RF issues, power) the "key change" message and still use the old one.
What I did was to clone the existing device on the server backend but with the new keys. Then when a transmission arrives on the new device (which means the node has updated the keys) the old device is deleted.
If the next transmission still arrives on the old device it means the node has not picked it up so a new key change message is scheduled for retransmission - this is repeated until it's finally picked up.