     }
 
     // now that we have a pinmap, initalize the low levels accordingly.
+    hal_set_failure_handler(log_assertion);
     os_init_ex(pPinMap);
 
     // LMIC_reset() doesn't affect callbacks, so we can do this first.

            Serial.print(F(", datum=0x")); Serial.print(e.datum, HEX);
        }
        printOpmode(e.opmode, '.');
    } else {
        if (ev < sizeof(evNames) / sizeof(evNames[0])) {
            Serial.print(evNames[ev]);

    }
#endif // LMIC_ENABLE_event_logging

hal_failure_handler_t log_assertion;

void log_assertion(const char *pMessage, uint16_t line) {
    eventQueue.putEvent(ev_t(-3), pMessage, line);
    eventPrintAll();
    Serial.println("***HALTED BY ASSERT***");
    while (true)
        yield();
}

uint8_t lastTxChannel;
bool lastTxStart;

