diondokter / nrf-modem

Apache License 2.0
25 stars 10 forks source link

Modem library returns an error code of -1 #10

Open dkhayes117 opened 1 year ago

dkhayes117 commented 1 year ago

I'm using the DTLS Socket with LTE-M. It seems to connect to the cloud fine and send the data, but right after I see the drop() function called, I get an unwrap error.

10.717010 DEBUG Turning off LTE synchronously. Use async function `deactivate` to avoid blocking.
└─ nrf_modem::lte_link::{impl#2}::drop @ /home/dkhayes117/.cargo/registry/src/github.com-1ecc6299db9ec823/nrf-modem-0.2.0/src/lte_link.rs:168
12.492462 ERROR panicked at 'called `Result::unwrap()` on an `Err` value: NrfError(65536)', /home/dkhayes117/.cargo/registry/src/github.com-1ecc6299db9ec823/nrf-modem-0.2.0/src/lte_link.rs:177:60
└─ panic_probe::print_defmt::print @ /home/dkhayes117/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-probe-0.3.0/src/lib.rs:91
dkhayes117 commented 1 year ago

I added the ffi::get_last_error() function after I socket.send(...) and it shows error code 127. Based on the Nordic SDK the error means Key has expired. However, some of my payloads successfully made it to the cloud, and my PSK info is correct.

diondokter commented 1 year ago

So this is kinda weird. The error comes from the place where we turn off the sim card. Somebody noticed that the power draw was a bit higher than expected and turning off the sim would fix that. All was well, but there's now (since 4 days ago!) a v2.2 of the nrf9160 at commands specification.

It added a new note to the cereg set command:

• The response for CFUN=40 is ERROR if the modem has been activated with CFUN=1 or CFUN=21.

This is new! Are you using the new 1.3.4 modem firmware? They released that one in tandem with the v2.2 at commands.

The annoying thing though is that the new note is kinda ambiguous. We do activate the LTE modem with CFUN=21. However, we also deactivate it with CFUN=20 before we do CFUN=40. There are three meanings to be found:

I would find the last one most reasonable. But who knows.

@dkhayes117 can you do these two things for me? It might give some clarification.

dkhayes117 commented 1 year ago

Using nrf-modem v0.1.1, everything worked without any errors and did not panic. I couldn't try deactivate() as the socket is being held in a struct and this would move the socket.

I think the modem firmware is v1.3.2, but I will have to double check that later.

diondokter commented 1 year ago

I've asked for clarification on their forum: https://devzone.nordicsemi.com/f/nordic-q-a/96170/ambiguous-new-note-for-cfun-at-command-nrf9160