LMiC adapted to work with SX1272MB2xAS LoRa shield.

Fork of LMiC by Timothy Mulrooney

Files at this revision

API Documentation at this revision

Comitter:
GTsapparellas
Date:
Mon Apr 02 12:04:59 2018 +0000
Parent:
7:29058a7ccf23
Commit message:
LoRa Node consisting of FRDM-K64F along with SX1272MB2xAS LoRa shield employed through IBM's LMiC library.

Changed in this revision

aes.cpp Show annotated file Show diff for this revision Revisions of this file
hal.h Show annotated file Show diff for this revision Revisions of this file
lmic.cpp Show annotated file Show diff for this revision Revisions of this file
lmic.h Show annotated file Show diff for this revision Revisions of this file
lorabase.h Show annotated file Show diff for this revision Revisions of this file
oslmic.cpp Show annotated file Show diff for this revision Revisions of this file
oslmic.h Show annotated file Show diff for this revision Revisions of this file
radio.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/aes.cpp	Thu Feb 25 21:28:23 2016 +0000
+++ b/aes.cpp	Mon Apr 02 12:04:59 2018 +0000
@@ -7,11 +7,23 @@
  *
  * Contributors:
  *    IBM Zurich Research Lab - initial API, implementation and documentation
- *******************************************************************************/
+ *
+ * /////////////////////////////////////////////////////////////////////////////
+ *
+ * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring
+ * device for agriculture using LoRaWAN technology.
+ *
+ * Date of issued copy: 25 January 2018
+ *
+ * Modifications: 
+ * - No external modifications of the existing "AS IT IS" software.
+ * - Added some external comments for meeting good principles of 
+ *   source code re-usability.   
+ ******************************************************************************/
 
 #include "oslmic.h"
 
-#define AES_MICSUB 0x30 // internal use only
+#define AES_MICSUB 0x30 // Internal use only.
 
 static const u4_t AES_RCON[10] = { 
     0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 
@@ -199,12 +211,18 @@
                                    a ^= (AES_S[u1(r2>> 8)]<< 8); \
                                    a ^=  AES_S[u1(r3)    ]
 
-// global area for passing parameters (aux, key) and for storing round keys
+// Global area for passing parameters (aux, key) and for storing round keys.
 u4_t AESAUX[16/sizeof(u4_t)];
 u4_t AESKEY[11*16/sizeof(u4_t)];
 
-// generate 1+10 roundkeys for encryption with 128-bit key
-// read 128-bit key from AESKEY in MSBF, generate roundkey words in place
+/* 
+* aesroundkeys function of type static void.
+* Generate 1+10 roundkeys for encryption with 128-bit key.
+* Read 128-bit key from AESKEY in MSBF, generate roundkey words in place.
+*
+* Input parameters: None
+*
+*/ 
 static void aesroundkeys () {
     int i;
     u4_t b;
@@ -225,8 +243,17 @@
         }
         AESKEY[i] = b ^= AESKEY[i-4];
     }
-}
+} // end of aesroundkeys function.
 
+/* 
+* os_aes function of type unsigned integer.
+*
+* Input parameters: unsigned int mode
+*                   unsigned int buf
+*                   unsigned int short len
+*
+* Return: AESAUX[0]
+*/ 
 u4_t os_aes (u1_t mode, xref2u1_t buf, u2_t len) {
         
         aesroundkeys();
@@ -363,5 +390,5 @@
             mode |= AES_MICNOAUX;
         }
         return AESAUX[0];
-}
+} // end of os_aes function.
 
--- a/hal.h	Thu Feb 25 21:28:23 2016 +0000
+++ b/hal.h	Mon Apr 02 12:04:59 2018 +0000
@@ -7,77 +7,145 @@
  *
  * Contributors:
  *    IBM Zurich Research Lab - initial API, implementation and documentation
- *******************************************************************************/
+ * /////////////////////////////////////////////////////////////////////////////
+ *
+ * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring
+ * device for agriculture using LoRaWAN technology.
+ * 
+ * Date of issued copy: 25 January 2018
+ *
+ * Modifications: 
+ * - No external modifications of the existing "AS IT IS" software.
+ * - Added some external comments for meeting good principles of 
+ *   source code re-usability.   
+ ******************************************************************************/
 
 #ifndef _hal_hpp_
 #define _hal_hpp_
 
-/*
- * initialize hardware (IO, SPI, TIMER, IRQ).
- */
+/* 
+ * hal_init function of type void.
+ *
+ * Initializes hardware (IO, SPI, TIMER, IRQ).
+ *
+ * Input parameters: None
+ *
+ */ 
 void hal_init (void);
 
-/*
- * drive radio NSS pin (0=low, 1=high).
- */
+/* 
+ * hal_pin_nss function of type void.
+ *
+ * Drives radio NSS pin (0=low, 1=high).
+ *
+ * Input parameters: unsigned int val
+ *
+ */ 
 void hal_pin_nss (u1_t val);
 
-/*
- * drive radio RX/TX pins (0=rx, 1=tx).
- */
+/* 
+ * hal_pin_rxtx function of type void.
+ *
+ * Drives radio RX/TX pins (0=rx, 1=tx).
+ *
+ * Input parameters: unsigned int val
+ *
+ */ 
 void hal_pin_rxtx (u1_t val);
 
-/*
- * control radio RST pin (0=low, 1=high, 2=floating)
- */
+/* 
+ * hal_pin_rst function of type void.
+ *
+ * Controls radio RST pin (0=low, 1=high, 2=floating).
+ *
+ * Input parameters: unsigned int val
+ *
+ */ 
 void hal_pin_rst (u1_t val);
 
-/*
- * perform 8-bit SPI transaction with radio.
+/* 
+ * hal_spi function of type unsigned integer.
+ *
+ * Performs 8-bit SPI transaction with radio.
  *   - write given byte 'outval'
- *   - read byte and return value
- */
+ *   - read byte
+ *
+ * Input parameters: unsigned int outval
+ * Return: value
+ *
+ */ 
 u1_t hal_spi (u1_t outval);
 
-/*
- * disable all CPU interrupts.
+/* 
+ * hal_disableIRQs function of type void.
+ *
+ * Disables all CPU interrupts.
  *   - might be invoked nested 
  *   - will be followed by matching call to hal_enableIRQs()
- */
+ *
+ * Input parameters: None
+ *
+ */ 
 void hal_disableIRQs (void);
 
-/*
- * enable CPU interrupts.
- */
+/* 
+ * hal_enableIRQs function of type void.
+ *
+ * Enables CPU interrupts.
+ *
+ * Input parameters: None
+ *
+ */ 
 void hal_enableIRQs (void);
 
-/*
- * put system and CPU in low-power mode, sleep until interrupt.
- */
+/* 
+ * hal_sleep function of type void.
+ *
+ * Puts system and CPU in low-power mode, sleep until interrupt.
+ *
+ * Input parameters: None
+ *
+ */ 
 void hal_sleep (void);
 
-/*
- * return 32-bit system time in ticks.
- */
+/* 
+ * hal_ticks function of type unsigned interger.
+ *
+ * Input parameters: None
+ * Return: 32-bit system time in ticks.
+ */ 
 u4_t hal_ticks (void);
 
-/*
- * busy-wait until specified timestamp (in ticks) is reached.
- */
+/* 
+ * hal_waitUntil function of type void.
+ *
+ * Busy-wait until specified timestamp (in ticks) is reached.
+ *
+ * Input parameters: unsigned int time
+ */ 
 void hal_waitUntil (u4_t time);
 
-/*
- * check and rewind timer for target time.
- *   - return 1 if target time is close
- *   - otherwise rewind timer for target time or full period and return 0
- */
+/* 
+ * hal_checkTimer function of type unsigned char.
+ *
+ * Checks and rewinds timer for target time.
+ *
+ * Input parameters: unsigned int targettime
+ * Return: - 1 if target time is close
+ *         - otherwise rewind timer for target time or full period and return 0 
+ */ 
 u1_t hal_checkTimer (u4_t targettime);
 
-/*
- * perform fatal failure action.
+/* 
+ * hal_failed function of type void.
+ *
+ * Performs fatal failure action.
  *   - called by assertions
  *   - action could be HALT or reboot
- */
+ *
+ * Input parameters: None
+ *
+ */ 
 void hal_failed (void);
 
 #endif // _hal_hpp_
--- a/lmic.cpp	Thu Feb 25 21:28:23 2016 +0000
+++ b/lmic.cpp	Mon Apr 02 12:04:59 2018 +0000
@@ -7,7 +7,20 @@
  *
  * Contributors:
  *    IBM Zurich Research Lab - initial API, implementation and documentation
- *******************************************************************************/
+ *
+ * /////////////////////////////////////////////////////////////////////////////
+ *
+ * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring
+ * device for agriculture using LoRaWAN technology.
+ * 
+ * Date of issued copy: 25 January 2018
+ *
+ * Modifications: 
+ * - No external modifications of the existing "AS IT IS" software.
+ * - Comment out debug messages of each function for more clear 
+ *   debugging procedure.
+ *  
+ ******************************************************************************/
 
 //! \file
 #include "lmic.h"
@@ -60,7 +73,7 @@
 #if !defined(os_rlsbf2)
 u2_t os_rlsbf2 (xref2cu1_t buf) 
 {
-    debug("LMIC os_rlsbf2 enter\r\n");
+    //debug("LMIC os_rlsbf2 enter\r\n");
     return (u2_t)(buf[0] | (buf[1]<<8));
 }
 #endif
@@ -68,7 +81,7 @@
 #if !defined(os_rlsbf4)
 u4_t os_rlsbf4 (xref2cu1_t buf) 
 {
-    debug("LMIC os_rlsbf4 enter\r\n");
+    //debug("LMIC os_rlsbf4 enter\r\n");
     return (u4_t)(buf[0] | (buf[1]<<8) | ((u4_t)buf[2]<<16) | ((u4_t)buf[3]<<24));
 }
 #endif
@@ -77,7 +90,7 @@
 #if !defined(os_rmsbf4)
 u4_t os_rmsbf4 (xref2cu1_t buf) 
 {
-    debug("LMIC os_rmsbf4 enter\r\n");
+    //debug("LMIC os_rmsbf4 enter\r\n");
     return (u4_t)(buf[3] | (buf[2]<<8) | ((u4_t)buf[1]<<16) | ((u4_t)buf[0]<<24));
 }
 #endif
@@ -86,7 +99,7 @@
 #if !defined(os_wlsbf2)
 void os_wlsbf2 (xref2u1_t buf, u2_t v) 
 {
-    debug("LMIC os_wlsbf2 enter\r\n");
+    //debug("LMIC os_wlsbf2 enter\r\n");
     buf[0] = v;
     buf[1] = v>>8;
 }
@@ -95,7 +108,7 @@
 #if !defined(os_wlsbf4)
 void os_wlsbf4 (xref2u1_t buf, u4_t v) 
 {
-    debug("LMIC os_wlsbf4 enter\r\n");
+    //debug("LMIC os_wlsbf4 enter\r\n");
     buf[0] = v;
     buf[1] = v>>8;
     buf[2] = v>>16;
@@ -106,7 +119,7 @@
 #if !defined(os_wmsbf4)
 void os_wmsbf4 (xref2u1_t buf, u4_t v) 
 {
-    debug("LMIC os_wmsbf4 enter\r\n");
+    //debug("LMIC os_wmsbf4 enter\r\n");
     buf[3] = v;
     buf[2] = v>>8;
     buf[1] = v>>16;
@@ -117,7 +130,7 @@
 #if !defined(os_getBattLevel)
 u1_t os_getBattLevel (void) 
 {
-    debug("LMIC os_getBattLevel enter\r\n");
+    //debug("LMIC os_getBattLevel enter\r\n");
     return MCMD_DEVS_BATT_NOINFO;
 }
 #endif
@@ -126,7 +139,7 @@
 // New CRC-16 CCITT(XMODEM) checksum for beacons:
 u2_t os_crc16 (xref2u1_t data, uint len) 
 {
-    debug("LMIC os_crc16 enter\r\n");
+    //debug("LMIC os_crc16 enter\r\n");
     u2_t remainder = 0;
     u2_t polynomial = 0x1021;
     for( uint i = 0; i < len; i++ ) 
@@ -154,7 +167,7 @@
 
 static void micB0 (u4_t devaddr, u4_t seqno, int dndir, int len) 
 {
-    debug("LMIC micB0 enter\r\n");
+    //debug("LMIC micB0 enter\r\n");
     os_clearMem(AESaux,16);
     AESaux[0]  = 0x49;
     AESaux[5]  = dndir?1:0;
@@ -166,7 +179,7 @@
 
 static int aes_verifyMic (xref2cu1_t key, u4_t devaddr, u4_t seqno, int dndir, xref2u1_t pdu, int len) 
 {
-   debug("LMIC aes_verifyMic enter\r\n");
+   //debug("LMIC aes_verifyMic enter\r\n");
     micB0(devaddr, seqno, dndir, len);
     os_copyMem(AESkey,key,16);
     return os_aes(AES_MIC, pdu, len) == os_rmsbf4(pdu+len);
@@ -175,7 +188,7 @@
 
 static void aes_appendMic (xref2cu1_t key, u4_t devaddr, u4_t seqno, int dndir, xref2u1_t pdu, int len) 
 {
-   debug("LMIC aes_appendMic enter\r\n");
+   //debug("LMIC aes_appendMic enter\r\n");
     micB0(devaddr, seqno, dndir, len);
     os_copyMem(AESkey,key,16);
     // MSB because of internal structure of AES
@@ -185,15 +198,15 @@
 
 static void aes_appendMic0 (xref2u1_t pdu, int len) 
 {
-    debug("LMIC aes_appendMic0 enter\r\n");
+   //debug("LMIC aes_appendMic0 enter\r\n");
    os_getDevKey(AESkey);
-    os_wmsbf4(pdu+len, os_aes(AES_MIC|AES_MICNOAUX, pdu, len));  // MSB because of internal structure of AES
+   os_wmsbf4(pdu+len, os_aes(AES_MIC|AES_MICNOAUX, pdu, len));  // MSB because of internal structure of AES
 }
 
 
 static int aes_verifyMic0 (xref2u1_t pdu, int len) 
 {
-   debug("LMIC aes_verifyMic0 enter\r\n");
+    //debug("LMIC aes_verifyMic0 enter\r\n");
     os_getDevKey(AESkey);
     return os_aes(AES_MIC|AES_MICNOAUX, pdu, len) == os_rmsbf4(pdu+len);
 }
@@ -201,7 +214,7 @@
 
 static void aes_encrypt (xref2u1_t pdu, int len) 
 {
-   debug("LMIC aes_encrypt enter\r\n");
+    //debug("LMIC aes_encrypt enter\r\n");
     os_getDevKey(AESkey);
     os_aes(AES_ENC, pdu, len);
 }
@@ -209,7 +222,7 @@
 
 static void aes_cipher (xref2cu1_t key, u4_t devaddr, u4_t seqno, int dndir, xref2u1_t payload, int len) 
 {
-    debug("LMIC aes_cipher enter\r\n");
+   //debug("LMIC aes_cipher enter\r\n");
    if( len <= 0 )
         return;
     os_clearMem(AESaux, 16);
@@ -224,7 +237,7 @@
 
 static void aes_sessKeys (u2_t devnonce, xref2cu1_t artnonce, xref2u1_t nwkkey, xref2u1_t artkey) 
 {
-   debug("LMIC aes_sessKeys enter\r\n");
+    //debug("LMIC aes_sessKeys enter\r\n");
     os_clearMem(nwkkey, 16);
     nwkkey[0] = 0x01;
     os_copyMem(nwkkey+1, artnonce, LEN_ARTNONCE+LEN_NETID);
@@ -310,13 +323,13 @@
 
 int getSensitivity (rps_t rps) 
 {
-      debug("LMIC getSensitivity enter\r\n");
+    //debug("LMIC getSensitivity enter\r\n");
     return -141 + SENSITIVITY[getSf(rps)][getBw(rps)];
 }
 
 ostime_t calcAirTime (rps_t rps, u1_t plen)
  {
-      debug("LMIC calcAirTime enter\r\n");
+   //debug("LMIC calcAirTime enter\r\n");
    u1_t bw = getBw(rps);  // 0,1,2 = 125,250,500kHz
     u1_t sf = getSf(rps);  // 0=FSK, 1..6 = SF7..12
     if( sf == FSK ) {
@@ -433,7 +446,7 @@
 
 static ostime_t calcRxWindow (u1_t secs, dr_t dr) 
 {
-     debug("LMIC calcRxWindow enter\r\n");
+    //debug("LMIC calcRxWindow enter\r\n");
     ostime_t rxoff, err;
     if( secs==0 ) {
         // aka 128 secs (next becaon)
@@ -455,7 +468,7 @@
 // Setup beacon RX parameters assuming we have an error of ms (aka +/-(ms/2))
 static void calcBcnRxWindowFromMillis (u1_t ms, bit_t ini) 
 {
-    debug("LMIC calcBcnRxWindowFromMillis enter\r\n");
+    //debug("LMIC calcBcnRxWindowFromMillis enter\r\n");
     if( ini ) {
         LMIC.drift = 0;
         LMIC.maxDriftDiff = 0;
@@ -471,7 +484,7 @@
 // Setup scheduled RX window (ping/multicast slot)
 static void rxschedInit (xref2rxsched_t rxsched) 
 {
-    debug("LMIC rxschedInit enter\r\n");
+    //debug("LMIC rxschedInit enter\r\n");
     os_clearMem(AESkey,16);
     os_clearMem(LMIC.frame+8,8);
     os_wlsbf4(LMIC.frame, LMIC.bcninfo.time);
@@ -490,7 +503,7 @@
 
 static bit_t rxschedNext (xref2rxsched_t rxsched, ostime_t cando) 
 {
-    debug("LMIC rxschedNext enter\r\n");
+  //debug("LMIC rxschedNext enter\r\n");
   again:
     if( rxsched->rxtime - cando >= 0 )
         return 1;
@@ -510,7 +523,7 @@
 
 static ostime_t rndDelay (u1_t secSpan) 
 {
-   debug("LMIC rndDelay enter\r\n");
+    //debug("LMIC rndDelay enter\r\n");
     u2_t r = os_getRndU2();
     ostime_t delay = r;
     if( delay > OSTICKS_PER_SEC )
@@ -523,7 +536,7 @@
 
 static void txDelay (ostime_t reftime, u1_t secSpan) 
 {
-   debug("LMIC txDelay enter\r\n");
+    //debug("LMIC txDelay enter\r\n");
     reftime += rndDelay(secSpan);
     if( LMIC.globalDutyRate == 0  ||  (reftime - LMIC.globalDutyAvail) > 0 ) {
         LMIC.globalDutyAvail = reftime;
@@ -534,7 +547,7 @@
 
 static void setDrJoin (u1_t reason, u1_t dr) 
 {
-   debug("LMIC setDrJoin enter\r\n");
+    //debug("LMIC setDrJoin enter\r\n");
     EV(drChange, INFO, (e_.reason    = reason,
                         e_.deveui    = MAIN::CDEV->getEui(),
                         e_.dr        = dr|DR_PAGE,
@@ -548,7 +561,7 @@
 
 static void setDrTxpow (u1_t reason, u1_t dr, s1_t pow) 
 {
-   debug("LMIC setDrTxpow enter\r\n");
+   //debug("LMIC setDrTxpow enter\r\n");
    EV(drChange, INFO, (e_.reason    = reason,
                         e_.deveui    = MAIN::CDEV->getEui(),
                         e_.dr        = dr|DR_PAGE,
@@ -571,14 +584,14 @@
 
 void LMIC_stopPingable (void) 
 {
-  debug("LMIC LMIC_stopPingable enter\r\n");
+   //debug("LMIC LMIC_stopPingable enter\r\n");
    LMIC.opmode &= ~(OP_PINGABLE|OP_PINGINI);
 }
 
 
 void LMIC_setPingable (u1_t intvExp) 
 {
-  debug("LMIC LMIC_setPingable enter\r\n");
+    //debug("LMIC LMIC_setPingable enter\r\n");
     // Change setting
     LMIC.ping.intvExp = (intvExp & 0x7);
     LMIC.opmode |= OP_PINGABLE;
@@ -691,7 +704,6 @@
     return 1;
 }
 
-
 static void updateTx (ostime_t txbeg) {
     u4_t freq = LMIC.channelFreq[LMIC.txChnl];
     // Update global/band specific duty cycle stats
@@ -1066,14 +1078,14 @@
 
 static void runEngineUpdate (xref2osjob_t osjob) 
 {
- debug("LMIC runEngineUpdate enter\r\n");
+    //debug("LMIC runEngineUpdate enter\r\n");
     engineUpdate();
 }
 
 
 static void reportEvent (ev_t ev)
 {
- debug("LMIC reportEvent enter %d\r\n",ev);
+    //debug("LMIC reportEvent enter %d\r\n",ev);
     EV(devCond, INFO, (e_.reason = EV::devCond_t::LMIC_EV,
                        e_.eui    = MAIN::CDEV->getEui(),
                        e_.info   = ev));
@@ -1084,7 +1096,7 @@
 
 static void runReset (xref2osjob_t osjob) 
 {
-debug("LMIC runReset enterr\n");
+    //debug("LMIC runReset enterr\n");
     // Disable session
     LMIC_reset();
     LMIC_startJoining();
@@ -1093,7 +1105,7 @@
 
 static void stateJustJoined (void) 
 {
-debug("LMIC stateJustJoined enter\r\n");
+    //debug("LMIC stateJustJoined enter\r\n");
     LMIC.seqnoDn     = LMIC.seqnoUp = 0;
     LMIC.rejoinCnt   = 0;
     LMIC.dnConf      = LMIC.adrChanged = LMIC.ladrAns = LMIC.devsAns = 0;
@@ -1116,7 +1128,7 @@
 // Decode beacon  - do not overwrite bcninfo unless we have a match!
 static int decodeBeacon (void) 
 {
-debug("LMIC decodeBeacon enter\r\n");
+//debug("LMIC decodeBeacon enter\r\n");
     ASSERT(LMIC.dataLen == LEN_BCN); // implicit header RX guarantees this
     xref2u1_t d = LMIC.frame;
     if(
@@ -1154,7 +1166,7 @@
 
 static bit_t decodeFrame (void) 
 {
-debug("LMIC decodeFrame enter\r\n");
+    //debug("LMIC decodeFrame enter\r\n");
     xref2u1_t d = LMIC.frame;
     u1_t hdr    = d[0];
     u1_t ftype  = hdr & HDR_FTYPE;
@@ -1448,7 +1460,7 @@
 
 static void setupRx2 (void) 
 {
-debug("LMIC setupRx2 enter\r\n");
+//debug("LMIC setupRx2 enter\r\n");
     LMIC.txrxFlags = TXRX_DNW2;
     LMIC.rps = dndr2rps(LMIC.dn2Dr);
     LMIC.freq = LMIC.dn2Freq;
@@ -1459,16 +1471,16 @@
 
 static void schedRx2 (ostime_t delay, osjobcb_t func) 
 {
-debug("LMIC schedRx2 enter\r\n");
+    //debug("LMIC schedRx2 enter\r\n");
     // Add 1.5 symbols we need 5 out of 8. Try to sync 1.5 symbols into the preamble.
     LMIC.rxtime = LMIC.txend + delay + (PAMBL_SYMS-MINRX_SYMS)*dr2hsym(LMIC.dn2Dr);
-//    LMIC.rxtime = LMIC.txend + delay;
+    //LMIC.rxtime = LMIC.txend + delay;
     os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
 }
 
 static void setupRx1 (osjobcb_t func) 
 {
-debug("LMIC setupRx1 enter\r\n");
+    //debug("LMIC setupRx1 enter\r\n");
     LMIC.txrxFlags = TXRX_DNW1;
     // Turn LMIC.rps from TX over to RX
     LMIC.rps = setNocrc(LMIC.rps,1);
@@ -1481,7 +1493,7 @@
 // Called by HAL once TX complete and delivers exact end of TX time stamp in LMIC.rxtime
 static void txDone (ostime_t delay, osjobcb_t func) 
 {
-debug("LMIC txDone enter\r\n");
+    //debug("LMIC txDone enter\r\n");
     if( (LMIC.opmode & (OP_TRACK|OP_PINGABLE|OP_PINGINI)) == (OP_TRACK|OP_PINGABLE) ) 
     {
         rxschedInit(&LMIC.ping);    // note: reuses LMIC.frame buffer!
@@ -1502,7 +1514,7 @@
 #endif
     {
         LMIC.rxtime = LMIC.txend + delay + (PAMBL_SYMS-MINRX_SYMS)*dr2hsym(LMIC.dndr);
-//        LMIC.rxtime = LMIC.txend + delay;
+//      LMIC.rxtime = LMIC.txend + delay;
         LMIC.rxsyms = MINRX_SYMS;
     }
     os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
@@ -1514,7 +1526,7 @@
 
 static void onJoinFailed (xref2osjob_t osjob) 
 {
-debug("LMIC onJoinFailed enter\r\n");
+    //debug("LMIC onJoinFailed enter\r\n");
     // Notify app - must call LMIC_reset() to stop joining
     // otherwise join procedure continues.
     reportEvent(EV_JOIN_FAILED);
@@ -1523,7 +1535,7 @@
 
 static bit_t processJoinAccept (void) 
 {
-debug("LMIC processJoinAccept enter\r\n");
+    //debug("LMIC processJoinAccept enter\r\n");
     ASSERT(LMIC.txrxFlags != TXRX_DNW1 || LMIC.dataLen != 0);
     ASSERT((LMIC.opmode & OP_TXRXPEND)!=0);
 
@@ -1624,7 +1636,7 @@
 
 static void processRx2Jacc (xref2osjob_t osjob) 
 {
-debug("LMIC processRx2Jacc enter\r\n");
+    //debug("LMIC processRx2Jacc enter\r\n");
     if( LMIC.dataLen == 0 )
         LMIC.txrxFlags = 0;  // nothing in 1st/2nd DN slot
     processJoinAccept();
@@ -1633,7 +1645,7 @@
 
 static void setupRx2Jacc (xref2osjob_t osjob) 
 {
-debug("LMIC setupRx2Jacc enter\r\n");
+    //debug("LMIC setupRx2Jacc enter\r\n");
     LMIC.osjob.func = FUNC_ADDR(processRx2Jacc);
     setupRx2();
 }
@@ -1641,7 +1653,7 @@
 
 static void processRx1Jacc (xref2osjob_t osjob) 
 {
-debug("LMIC processRx1Jacc enter\r\n");
+    //debug("LMIC processRx1Jacc enter\r\n");
     if( LMIC.dataLen == 0 || !processJoinAccept() )
         schedRx2(DELAY_JACC2_osticks, FUNC_ADDR(setupRx2Jacc));
 }
@@ -1649,14 +1661,14 @@
 
 static void setupRx1Jacc (xref2osjob_t osjob) 
 {
-debug("LMIC setupRx1Jacc enter\r\n");
+    //debug("LMIC setupRx1Jacc enter\r\n");
     setupRx1(FUNC_ADDR(processRx1Jacc));
 }
 
 
 static void jreqDone (xref2osjob_t osjob) 
 {
-debug("LMIC jreqDone enter\r\n");
+    //debug("LMIC jreqDone enter\r\n");
     txDone(DELAY_JACC1_osticks, FUNC_ADDR(setupRx1Jacc));
 }
 
@@ -1667,13 +1679,13 @@
 
 static void processRx2DnDataDelay (xref2osjob_t osjob) 
 {
-debug("LMIC processRx2DnDataDelay enter\r\n");
+    //debug("LMIC processRx2DnDataDelay enter\r\n");
     processDnData();
 }
 
 static void processRx2DnData (xref2osjob_t osjob) 
 {
-debug("LMIC processRx2DnData enter\r\n");
+    //debug("LMIC processRx2DnData enter\r\n");
     if( LMIC.dataLen == 0 ) {
         LMIC.txrxFlags = 0;  // nothing in 1st/2nd DN slot
         // Delay callback processing to avoid up TX while gateway is txing our missed frame! 
@@ -1689,7 +1701,7 @@
 
 static void setupRx2DnData (xref2osjob_t osjob) 
 {
-debug("LMIC setupRx2DnData enter\r\n");
+    //debug("LMIC setupRx2DnData enter\r\n");
     LMIC.osjob.func = FUNC_ADDR(processRx2DnData);
     setupRx2();
 }
@@ -1697,7 +1709,7 @@
 
 static void processRx1DnData (xref2osjob_t osjob) 
 {
-debug("LMIC processRx1DnData enter\r\n");
+    //debug("LMIC processRx1DnData enter\r\n");
     if( LMIC.dataLen == 0 || !processDnData() )
         schedRx2(DELAY_DNW2_osticks, FUNC_ADDR(setupRx2DnData));
 }
@@ -1705,14 +1717,14 @@
 
 static void setupRx1DnData (xref2osjob_t osjob) 
 {
-debug("LMIC setupRx1DnData enter\r\n");
+    //debug("LMIC setupRx1DnData enter\r\n");
     setupRx1(FUNC_ADDR(processRx1DnData));
 }
 
 
 static void updataDone (xref2osjob_t osjob) 
 {
-debug("LMIC updataDone enter\r\n");
+    //debug("LMIC updataDone enter\r\n");
     txDone(DELAY_DNW1_osticks, FUNC_ADDR(setupRx1DnData));
 }
 
@@ -1721,7 +1733,7 @@
 
 static void buildDataFrame (void) 
 {
-debug("LMIC buildDataFrame enter\r\n");
+    //debug("LMIC buildDataFrame enter\r\n");
     bit_t txdata = ((LMIC.opmode & (OP_TXDATA|OP_POLL)) != OP_POLL);
     u1_t dlen = txdata ? LMIC.pendTxLen : 0;
 
@@ -1841,7 +1853,7 @@
 // Callback from HAL during scan mode or when job timer expires.
 static void onBcnRx (xref2osjob_t job) 
 {
-debug("LMIC onBcnRx enter\r\n");
+    //debug("LMIC onBcnRx enter\r\n");
     // If we arrive via job timer make sure to put radio to rest.
     os_radio(RADIO_RST);
     os_clearCallback(&LMIC.osjob);
@@ -1875,7 +1887,7 @@
 // Also cancels an onpoing joining procedure.
 static void startScan (void) 
 {
-debug("LMIC startScan enter\r\n");
+    //debug("LMIC startScan enter\r\n");
     ASSERT(LMIC.devaddr!=0 && (LMIC.opmode & OP_JOINING)==0);
     if( (LMIC.opmode & OP_SHUTDOWN) != 0 )
         return;
@@ -1891,7 +1903,7 @@
 
 bit_t LMIC_enableTracking (u1_t tryBcnInfo) 
 {
-debug("LMIC LMIC_enableTracking enter\r\n");
+    //debug("LMIC LMIC_enableTracking enter\r\n");
     if( (LMIC.opmode & (OP_SCAN|OP_TRACK|OP_SHUTDOWN)) != 0 )
         return 0;  // already in progress or failed to enable
     // If BCN info requested from NWK then app has to take are
@@ -1904,7 +1916,7 @@
 
 void LMIC_disableTracking (void) 
 {
-debug("LMIC LMIC_disableTracking enter\r\n");
+    //debug("LMIC LMIC_disableTracking enter\r\n");
     LMIC.opmode &= ~(OP_SCAN|OP_TRACK);
     LMIC.bcninfoTries = 0;
     engineUpdate();
@@ -1919,7 +1931,7 @@
 
 static void buildJoinRequest (u1_t ftype) 
 {
-debug("LMIC buildJoinRequest enter\r\n");
+    //debug("LMIC buildJoinRequest enter\r\n");
     // Do not use pendTxData since we might have a pending
     // user level frame in there. Use RX holding area instead.
     xref2u1_t d = LMIC.frame;
@@ -1944,14 +1956,14 @@
 
 static void startJoining (xref2osjob_t osjob) 
 {
-debug("LMIC startJoining enter\r\n");
+    //debug("LMIC startJoining enter\r\n");
     reportEvent(EV_JOINING);
 }
 
 // Start join procedure if not already joined.
 bit_t LMIC_startJoining (void) 
 {
-debug("LMIC LMIC_startJoining enter\r\n");
+    //debug("LMIC LMIC_startJoining enter\r\n");
     if( LMIC.devaddr == 0 ) 
     {
         // There should be no TX/RX going on
@@ -1980,7 +1992,7 @@
 
 static void processPingRx (xref2osjob_t osjob) 
 {
-debug("LMIC processPingRx enter\r\n");
+    //debug("LMIC processPingRx enter\r\n");
     if( LMIC.dataLen != 0 ) {
         LMIC.txrxFlags = TXRX_PING;
         if( decodeFrame() ) {
@@ -1995,7 +2007,7 @@
 
 static bit_t processDnData (void) 
 {
-debug("LMIC processDnData enter\r\n");
+    //debug("LMIC processDnData enter\r\n");
     ASSERT((LMIC.opmode & OP_TXRXPEND)!=0);
 
     if( LMIC.dataLen == 0 ) {
@@ -2061,7 +2073,7 @@
 
 static void processBeacon (xref2osjob_t osjob) 
 {
-debug("LMIC processBeacon enter\r\n");
+    //debug("LMIC processBeacon enter\r\n");
     ostime_t lasttx = LMIC.bcninfo.txtime;   // save here - decodeBeacon might overwrite
     u1_t flags = LMIC.bcninfo.flags;
     ev_t ev;
@@ -2124,7 +2136,7 @@
 
 static void startRxBcn (xref2osjob_t osjob) 
 {
-debug("LMIC startRxBcn enter\r\n");
+    //debug("LMIC startRxBcn enter\r\n");
     LMIC.osjob.func = FUNC_ADDR(processBeacon);
     os_radio(RADIO_RX);
 }
@@ -2132,7 +2144,7 @@
 
 static void startRxPing (xref2osjob_t osjob) 
 {
-debug("LMIC startRxPing enter\r\n");
+    //debug("LMIC startRxPing enter\r\n");
     LMIC.osjob.func = FUNC_ADDR(processPingRx);
     os_radio(RADIO_RX);
 }
@@ -2141,7 +2153,7 @@
 // Decide what to do next for the MAC layer of a device
 static void engineUpdate (void) 
 {
-debug("LMIC engineUpdate enter\r\n");
+    //debug("LMIC engineUpdate enter\r\n");
     // Check for ongoing state: scan or TX/RX transaction
     if( (LMIC.opmode & (OP_SCAN|OP_TXRXPEND|OP_SHUTDOWN)) != 0 ) 
         return;
@@ -2289,7 +2301,7 @@
 
 void LMIC_setAdrMode (bit_t enabled) 
 {
-debug("LMIC LMIC_setAdrMode enter\r\n");
+    //debug("LMIC LMIC_setAdrMode enter\r\n");
     LMIC.adrEnabled = enabled ? FCT_ADREN : 0;
 }
 
@@ -2297,14 +2309,14 @@
 //  Should we have/need an ext. API like this?
 void LMIC_setDrTxpow (dr_t dr, s1_t txpow) 
 {
-debug("LMIC LMIC_setDrTxpow enter\r\n");
+    //debug("LMIC LMIC_setDrTxpow enter\r\n");
     setDrTxpow(DRCHG_SET, dr, txpow);
 }
 
 
 void LMIC_shutdown (void) 
 {
-debug("LMIC LMIC_shutdown enter\r\n");
+    //debug("LMIC LMIC_shutdown enter\r\n");
     os_clearCallback(&LMIC.osjob);
     os_radio(RADIO_RST);
     LMIC.opmode |= OP_SHUTDOWN;
@@ -2313,7 +2325,7 @@
 
 void LMIC_reset (void) 
 {
-debug("LMIC LMIC_reset enter\r\n");
+    //debug("LMIC LMIC_reset enter\r\n");
     EV(devCond, INFO, (e_.reason = EV::devCond_t::LMIC_EV,
                        e_.eui    = MAIN::CDEV->getEui(),
                        e_.info   = EV_RESET));
@@ -2345,14 +2357,14 @@
 
 
 void LMIC_init (void) {
-    debug("LMIC_init enter\r\n");
+    // debug("LMIC_init enter\r\n");
     LMIC.opmode = OP_SHUTDOWN;
 }
 
 
 void LMIC_clrTxData (void) 
 {
-debug("LMIC LMIC_clrTxData enter\r\n");
+    //debug("LMIC LMIC_clrTxData enter\r\n");
     LMIC.opmode &= ~(OP_TXDATA|OP_TXRXPEND|OP_POLL);
     LMIC.pendTxLen = 0;
     if( (LMIC.opmode & (OP_JOINING|OP_SCAN)) != 0 ) // do not interfere with JOINING
@@ -2365,7 +2377,7 @@
 
 void LMIC_setTxData (void) 
 {
-debug("LMIC LMIC_setTxData enter\r\n");
+    //debug("LMIC LMIC_setTxData enter\r\n");
     LMIC.opmode |= OP_TXDATA;
     if( (LMIC.opmode & OP_JOINING) == 0 )
         LMIC.txCnt = 0;             // cancel any ongoing TX/RX retries
@@ -2376,7 +2388,7 @@
 //
 int LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed) 
 {
-debug("LMIC LMIC_setTxData2 enter\r\n");
+    //debug("LMIC LMIC_setTxData2 enter\r\n");
     if( dlen > SIZEOFEXPR(LMIC.pendTxData) )
         return -2;
     if( data != (xref2u1_t)0 )
@@ -2392,7 +2404,7 @@
 // Send a payload-less message to signal device is alive
 void LMIC_sendAlive (void) 
 {
-debug("LMIC LMIC_sendAlive enter\r\n");
+    //debug("LMIC LMIC_sendAlive enter\r\n");
     LMIC.opmode |= OP_POLL;
     engineUpdate();
 }
@@ -2401,7 +2413,7 @@
 // Check if other networks are around.
 void LMIC_tryRejoin (void) 
 {
-debug("LMIC LMIC_tryRejoin enter\r\n");
+    //debug("LMIC LMIC_tryRejoin enter\r\n");
     LMIC.opmode |= OP_REJOIN;
     engineUpdate();
 }
@@ -2422,7 +2434,7 @@
 //!     If NULL the caller has copied the key into `LMIC.artKey` before.
 void LMIC_setSession (u4_t netid, devaddr_t devaddr, xref2u1_t nwkKey, xref2u1_t artKey) 
 {
-debug("LMIC LMIC_setSession enter\r\n");
+    //debug("LMIC LMIC_setSession enter\r\n");
     LMIC.netid = netid;
     LMIC.devaddr = devaddr;
     if( nwkKey != (xref2u1_t)0 )
@@ -2449,7 +2461,7 @@
 // This must be called only if a session is established (e.g. after EV_JOINED)
 void LMIC_setLinkCheckMode (bit_t enabled) 
 {
-debug("LMIC LMIC_setLinkCheckMode enter\r\n");
+    //debug("LMIC LMIC_setLinkCheckMode enter\r\n");
     LMIC.adrChanged = 0;
     LMIC.adrAckReq = enabled ? LINK_CHECK_INIT : LINK_CHECK_OFF;
 }
--- a/lmic.h	Thu Feb 25 21:28:23 2016 +0000
+++ b/lmic.h	Mon Apr 02 12:04:59 2018 +0000
@@ -7,7 +7,19 @@
  *
  * Contributors:
  *    IBM Zurich Research Lab - initial API, implementation and documentation
- *******************************************************************************/
+ *
+ * /////////////////////////////////////////////////////////////////////////////
+ *
+ * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring
+ * device for agriculture using LoRaWAN technology.
+ *
+ * Date of issued copy: 25 January 2018
+ *
+ * Modifications: 
+ * - No external modifications of the existing "AS IT IS" software.
+ * - Set CFG_eu868 and CFG_sx1272_radio definitions to 1 for European's 
+ *   frequency band listening and sx1272 radio usage.
+ ******************************************************************************/
 
 //! @file
 //! @brief LMIC API
@@ -16,15 +28,12 @@
 #define _lmic_h_
 
 // MBED compiler options
-//#define CFG_eu868                                   1
-#define CFG_us915                                   1
+#define CFG_eu868                                   1
+//#define CFG_us915                                 1
 #define CHNL_HYBRID     0       /* US915: 0-7 to select block of 8 channels used */
 //#define JOIN_REQ_DEBUG 0
-
 #define USE_SMTC_RADIO_DRIVER                       1
-
-#define CFG_sx1272_radio                            0
-//#define CFG_sx1276_radio                            1
+#define CFG_sx1272_radio                            1
 // End MBED compiler options
 
 #include "oslmic.h"
--- a/lorabase.h	Thu Feb 25 21:28:23 2016 +0000
+++ b/lorabase.h	Mon Apr 02 12:04:59 2018 +0000
@@ -7,6 +7,17 @@
  *
  * Contributors:
  *    IBM Zurich Research Lab - initial API, implementation and documentation
+ *
+ * /////////////////////////////////////////////////////////////////////////////
+ *
+ * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring
+ * device for agriculture using LoRaWAN technology.
+ *
+ * Date of issued copy: 25 January 2018
+ *
+ * Modifications: 
+ * - No external modifications of the existing "AS IT IS" software.
+ *
  *******************************************************************************/
 
 #ifndef _lorabase_h_
--- a/oslmic.cpp	Thu Feb 25 21:28:23 2016 +0000
+++ b/oslmic.cpp	Mon Apr 02 12:04:59 2018 +0000
@@ -7,7 +7,19 @@
  *
  * Contributors:
  *    IBM Zurich Research Lab - initial API, implementation and documentation
- *******************************************************************************/
+ *
+ * /////////////////////////////////////////////////////////////////////////////
+ *
+ * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring
+ * device for agriculture using LoRaWAN technology.
+ * 
+ * Date of issued copy: 25 January 2018
+ *
+ * Modifications: 
+ * - No external modifications of the existing "AS IT IS" software.
+ * - Comment out debug messages of each function for more clear 
+ *   debugging procedure.
+ ******************************************************************************/
 
 #include "lmic.h"
 #include "debug.h"
@@ -21,23 +33,23 @@
 
 void os_init () 
 {
-    debug("os_init enter\r\n");
+    //debug("os_init enter\r\n");
     memset(&OS, 0x00, sizeof(OS));
     hal_init();
     radio_init();
     LMIC_init();
-   debug("os_init exit\r\n");
+    //debug("os_init exit\r\n");
 }
 
 ostime_t os_getTime () 
 {
-    debug("os_getTime enter %d\r\n",hal_ticks());
+    //debug("os_getTime enter %d\r\n",hal_ticks());
     return hal_ticks();
 }
 
 static u1_t unlinkjob (osjob_t** pnext, osjob_t* job) 
 {
-   debug("unlinkjob enter\r\n");
+    //debug("unlinkjob enter\r\n");
     for( ; *pnext; pnext = &((*pnext)->next)) {
         if(*pnext == job) { // unlink
             *pnext = job->next;
@@ -50,7 +62,7 @@
 // clear scheduled job
 void os_clearCallback (osjob_t* job) 
 {
-   debug("os_clearCallback enter\r\n");
+    //debug("os_clearCallback enter\r\n");
     hal_disableIRQs();
     unlinkjob(&OS.scheduledjobs, job) || unlinkjob(&OS.runnablejobs, job);
     hal_enableIRQs();
@@ -59,7 +71,7 @@
 // schedule immediately runnable job
 void os_setCallback (osjob_t* job, osjobcb_t cb) 
 {
-   debug("os_setCallback enter\r\n");
+    //debug("os_setCallback enter\r\n");
     osjob_t** pnext;
     hal_disableIRQs();
     // remove if job was already queued
@@ -76,7 +88,7 @@
 // schedule timed job
 void os_setTimedCallback (osjob_t* job, ostime_t time, osjobcb_t cb) 
 {
-   debug("os_setTimedCallback enter %d\r\n",time);
+    //debug("os_setTimedCallback enter %d\r\n",time);
     osjob_t** pnext;
     hal_disableIRQs();
     // remove if job was already queued
@@ -100,7 +112,7 @@
 // execute jobs from timer and from run queue
 void os_runloop () 
 {
-   debug("os_runloop enter\r\n");
+   debug_str("os_runloop enter\r\n");
     while(1) {
         osjob_t* j = NULL;
         hal_disableIRQs();
@@ -120,3 +132,27 @@
         }
     }
 }
+
+void os_runloop_once() {
+    
+    bool has_deadline = false;
+    osjob_t* j = NULL;
+    hal_disableIRQs();
+    
+    // check for runnable jobs
+    if(OS.runnablejobs) {
+        j = OS.runnablejobs;
+        OS.runnablejobs = j->next;
+    } else if(OS.scheduledjobs && hal_checkTimer(OS.scheduledjobs->deadline)) { // check for expired timed jobs
+        j = OS.scheduledjobs;
+        OS.scheduledjobs = j->next;
+            has_deadline = true;
+    } else { // nothing pending
+        hal_sleep(); // wake by irq (timer already restarted)
+    }
+    hal_enableIRQs();
+    if(j) { // run job callback
+           // printf("%lu: Running job %p, cb %p, deadline %lu\r\n", os_getTime(), j, j->func, has_deadline ? j->deadline : 0);
+        j->func(j);
+    }
+}
--- a/oslmic.h	Thu Feb 25 21:28:23 2016 +0000
+++ b/oslmic.h	Mon Apr 02 12:04:59 2018 +0000
@@ -7,7 +7,17 @@
  *
  * Contributors:
  *    IBM Zurich Research Lab - initial API, implementation and documentation
- *******************************************************************************/
+ *
+ * /////////////////////////////////////////////////////////////////////////////
+ *
+ * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring
+ * device for agriculture using LoRaWAN technology.
+ * 
+ * Date of issued copy: 25 January 2018
+ *
+ * Modifications: 
+ * - No external modifications of the existing "AS IT IS" software.
+ ******************************************************************************/
 
 //! \file
 #ifndef _oslmic_h_
@@ -81,6 +91,7 @@
 void radio_irq_handler (u1_t dio);
 void os_init (void);
 void os_runloop (void);
+void os_runloop_once (void);
 
 //================================================================================
 
--- a/radio.cpp	Thu Feb 25 21:28:23 2016 +0000
+++ b/radio.cpp	Mon Apr 02 12:04:59 2018 +0000
@@ -13,6 +13,18 @@
  *                              radio driver. The selection is done by setting
  *                              USE_SMTC_RADIO_DRIVER preprocessing directive
  *                              in lmic.h
+ *
+ * /////////////////////////////////////////////////////////////////////////////
+ *
+ * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring
+ * device for agriculture using LoRaWAN technology.
+ * 
+ * Date of issued copy: 25 January 2018
+ *
+ * Modifications: 
+ * - Updated to support MBED sx1272 driver library.
+ * - Disabled continuous reception od sx1272 LoRa shield under radio_init funtion
+ *   as it is used only for transmitting data.
  *******************************************************************************/
 
 #include "lmic.h"
@@ -73,7 +85,7 @@
  * Radio object declraration
  */
 //SX1272MB1xAS Radio( NULL );
-SX1272MB1xAS *Radio;
+SX1272MB2xAS *Radio;
 
 static const u2_t LORA_RXDONE_FIXUP[] = {
     [FSK]  =     us2osticks(0), // (   0 ticks)
@@ -87,7 +99,7 @@
 
 void OnTxDone( void )
 {
-    debug("OnTxDone enter\r\n");
+    //debug("OnTxDone enter\r\n");
     ostime_t now = os_getTime( );
     // save exact tx time
     LMIC.txend = now - us2osticks( RADIO_WAKEUP_TIME ); // TXDONE FIXUP
@@ -100,7 +112,7 @@
 
 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
 {
-   debug("OnRxDone enter\r\n");
+   //debug("OnRxDone enter\r\n");
     ostime_t now = os_getTime( );
     // save exact rx time
     if( getBw( LMIC.rps ) == BW125 )
@@ -124,7 +136,7 @@
 
 void OnTxTimeout( void )
 {
-   debug("OnTxTimeout enter\r\n");
+   //debug("OnTxTimeout enter\r\n");
    ostime_t now = os_getTime( );
 
     // indicate error
@@ -138,7 +150,7 @@
 
 void OnRxTimeout( void )
 {
-   debug("OnRxTimeout enter\r\n");
+   //debug("OnRxTimeout enter\r\n");
    ostime_t now = os_getTime( );
     // indicate timeout
     LMIC.dataLen = 0;
@@ -151,7 +163,7 @@
 
 void OnRxError( void )
 {
-  debug("OnRxError enter\r\n");
+  //debug("OnRxError enter\r\n");
     ostime_t now = os_getTime( );
 
     // indicate error
@@ -173,8 +185,8 @@
 // get random seed from wideband noise rssi
 void radio_init( void ) 
 {
-    debug("radio_init1 enter\r\n");
-    Radio = new SX1272MB1xAS(NULL);
+    //debug_str("radio_init1 enter\r\n");
+    Radio = new SX1272MB2xAS(NULL);
       hal_disableIRQs( );
 
     // Initialize Radio driver
@@ -199,7 +211,7 @@
                   RFLR_IRQFLAGS_CADDETECTED );
 
     // Set radio in continuous reception
-    Radio->Rx( 0 );
+    /*Radio->Rx( 0 );
 
     for( int i = 1; i < 16; i++ )
     {
@@ -209,23 +221,23 @@
             while( ( b = Radio->Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) == ( Radio->Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) );
             randbuf[i] = ( randbuf[i] << 1 ) | b;
         }
-    }
+    }*/
     randbuf[0] = 16; // set initial index
-
+    
     // Change LoRa modem SyncWord
     Radio->Write( REG_LR_SYNCWORD, LORA_MAC_SYNCWORD );
     
     Radio->Sleep( );
     
     hal_enableIRQs( );
- debug("radio_init exit\r\n");
+    //debug_str("radio_init exit\r\n");
 }
 
 // return next random byte derived from seed buffer
 // (buf[0] holds index of next byte to be returned)
 u1_t radio_rand1( void )
 {
- debug("radio_rand1 enter\r\n");
+    //debug("radio_rand1 enter\r\n");
     u1_t i = randbuf[0];
     ASSERT( i != 0 );
     if( i == 16 )
@@ -240,7 +252,7 @@
 
 void os_radio( u1_t mode )
 {
-//debug_val("os_radio enter ",mode);
+    //debug_val("os_radio enter ",mode);
     hal_disableIRQs( );
     switch( mode ) 
     {
@@ -1030,7 +1042,7 @@
     hal_disableIRQs();
 
     // manually reset radio
-#ifdef CFG_sx1276_radio
+#ifdef CFG_sx1272_radio
     hal_pin_rst(0); // drive RST pin low
 #else
     hal_pin_rst(1); // drive RST pin high
@@ -1197,8 +1209,8 @@
 
 void os_radio (u1_t mode) 
 {
-//debug("os_radio enter\r\n");
- //   hal_disableIRQs();
+    //debug("os_radio enter\r\n");
+   //   hal_disableIRQs();
     switch (mode) {
       case RADIO_RST:
         // put radio to sleep