Пример #1
0
void onEvent (ev_t ev) {
    debug_event(ev);

    switch(ev) {
   
      // network joined, session established
      case EV_JOINED:
          // enable pinging mode, start scanning...
          // (set local ping interval configuration to 2^1 == 2 sec)
          LMIC_setPingable(1);
          debug_str("SCANNING...\r\n");
          break;

      // beacon found by scanning
      case EV_BEACON_FOUND:
          // send empty frame up to notify server of ping mode and interval!
          LMIC_sendAlive();
          break;

      // data frame received in ping slot
      case EV_RXCOMPLETE:
          // log frame data
          debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
          if(LMIC.dataLen == 1) {
              // set LED state if exactly one byte is received
              debug_led(LMIC.frame[LMIC.dataBeg] & 0x01);
          }
          break;    
    }
}
Пример #2
0
// initial job
static void initfunc (osjob_t* j) {

    LMIC_reset();	// reset MAC state

   LMIC_setSession(0x12345678, 0xB710566C, nwkKey, artKey);

   //LMIC_startJoining();	// start joining
   // init done - onEvent() callback will be invoked...

/*void LMIC_setSession (u4_t netid, devaddr_t(u4_t) devaddr, xref2u1_t nwkKey, xref2u1_t artKey) {
LMIC.netid = netid;
LMIC.devaddr = devaddr;
if( nwkKey != (xref2u1_t)0 )
os_copyMem(LMIC.nwkKey, nwkKey, 16);
if( artKey != (xref2u1_t)0 )
os_copyMem(LMIC.artKey, artKey, 16);*/

debug_str("\r\nSending");
// immediately prepare next transmission
LMIC.frame[0] = LMIC.snr;
// schedule transmission (port 1, datalen 1, no ack requested)
LMIC_setTxData2(1, LMIC.frame, 1, 0);
// (will be sent as soon as duty cycle permits)

LMIC_sendAlive();
}