if prefs file open fails, don't try other operations

This commit is contained in:
geeksville 2020-01-20 10:51:58 -08:00
parent 5a11a7a880
commit e84a840190

View File

@ -176,12 +176,13 @@ void onEvent(ev_t event) {
Serial.println(); Serial.println();
Preferences p; Preferences p;
p.begin("lora", false); if(p.begin("lora", false)) {
p.putUInt("netId", netid); p.putUInt("netId", netid);
p.putUInt("devAddr", devaddr); p.putUInt("devAddr", devaddr);
p.putBytes("nwkKey", nwkKey, sizeof(nwkKey)); p.putBytes("nwkKey", nwkKey, sizeof(nwkKey));
p.putBytes("artKey", artKey, sizeof(artKey)); p.putBytes("artKey", artKey, sizeof(artKey));
p.end(); p.end();
}
break; } break; }
case EV_TXCOMPLETE: case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (inc. RX win. wait)")); Serial.println(F("EV_TXCOMPLETE (inc. RX win. wait)"));
@ -226,10 +227,11 @@ void ttn_response(uint8_t * buffer, size_t len) {
static void initCount() { static void initCount() {
if(count == 0) { if(count == 0) {
Preferences p; Preferences p;
p.begin("lora", true); if(p.begin("lora", true)) {
count = p.getUInt("count", 0); count = p.getUInt("count", 0);
p.end(); p.end();
} }
}
} }
@ -326,7 +328,7 @@ void ttn_join() {
#endif #endif
Preferences p; Preferences p;
p.begin("lora", true); p.begin("lora", true); // we intentionally ignore failure here
uint32_t netId = p.getUInt("netId", UINT32_MAX); uint32_t netId = p.getUInt("netId", UINT32_MAX);
uint32_t devAddr = p.getUInt("devAddr", UINT32_MAX); uint32_t devAddr = p.getUInt("devAddr", UINT32_MAX);
uint8_t nwkKey[16], artKey[16]; uint8_t nwkKey[16], artKey[16];
@ -377,10 +379,11 @@ static void ttn_set_cnt() {
lastWriteMsec = now; lastWriteMsec = now;
Preferences p; Preferences p;
p.begin("lora", false); if(p.begin("lora", false)) {
p.putUInt("count", count); p.putUInt("count", count);
p.end(); p.end();
} }
}
} }
void ttn_send(uint8_t * data, uint8_t data_size, uint8_t port, bool confirmed){ void ttn_send(uint8_t * data, uint8_t data_size, uint8_t port, bool confirmed){