Open ObviousInRetrospect opened 2 years ago
Is there any other information that would be helpful? Thanks.
in case anyone else is stuck on this:
while I still can't get the convoluted NetGetSessionState flow to work, the underlying arduino-lmic library has a far simpler to use set of functions that work fine.
The following example code works (and will wear out eeprom if used as below)
typedef struct{
uint32_t seqnoUp;
uint32_t netid;
devaddr_t devaddr;
uint8_t nwkKey[16];
uint8_t artKey[16];
} eep_sstate_t;
void store_joininfo(u4_t netid, devaddr_t devaddr, uint8_t *nwkKey, uint8_t *artKey){
eep_sstate_t st;
st.seqnoUp=LMIC_getSeqnoUp();
st.netid=netid;
st.devaddr=devaddr;
memcpy(st.nwkKey,nwkKey,16);
memcpy(st.artKey,artKey,16);
uint8_t *r = (uint8_t*)&st;
for(int i=0; i<sizeof(eep_sstate_t); i++){
EEPROM.write(i,r[i]);
}
EEPROM.commit();
}
bool eep_rejoin(){
eep_sstate_t st;
uint8_t *r = (uint8_t*)&st;
for(int i=0; i<sizeof(eep_sstate_t); i++){
r[i]=EEPROM.read(i);
}
if(st.netid == 0xFFFFFFFF || st.netid == 0x0){
Serial.println("no session in EEPROM");
return false;
}
LMIC_reset();
LMIC_setSession(st.netid, st.devaddr, st.nwkKey, st.artKey);
LMIC_setSeqnoUp(st.seqnoUp);
return(true);
}
and then in onEvent:
and then in onEvent:
case EV_JOINED:
...
store_joininfo(netid,devaddr,nwkKey,artKey);
case EV_TXCOMPLETE:
...
uint32_t su = LMIC_getSeqnoUp();
uint8_t *sup = (uint8_t*)&su;
EEPROM.write(0,sup[0]);
EEPROM.write(1,sup[1]);
EEPROM.write(2,sup[2]);
EEPROM.write(3,sup[3]);
EEPROM.commit();
and finally call eep_rejoin(); at startup.
Also, the state this way is 44 bytes instead of far more.
I'm not having much luck getting session save/restore to work.
Multiple examples show that you need to implement NetSaveSessionInfo/NetSaveSessionState/NetGetSessionState.
Based on issue #165 I also added GetAbpProvisioningInfo. When that wasn't actually being called I overrode GetProvisioningStyle to check for a saved session and return ProvisioningStyle::kABP.
At the moment I am using EEPROM as a placeholder. I know it will have endurance problems and once I get it working will switch to storing it in sram on a 2nd mcu acting as an i2c slave (that also acts as a watchdog).
The SessionState gets stored starting at EEPROM address 0. The SessionInfo gets stored starting at EEPROM address sizeof(SessionState):
Here is the output from the first boot with the EEPROM cleared:
Here is the reboot,
You can see it does a rejoin and gets a new AppSKey/NwkSKey
What am I doing wrong? Any chance a fixed version of this could be added as an example?