matthijskooijman / arduino-lmic

:warning: This library is deprecated, see the README for alternatives.
708 stars 649 forks source link

Transmission is sending, but I'm not reciving on the gateway/server end #201

Open 6d6176 opened 6 years ago

6d6176 commented 6 years ago

915 freq,

Packet queued 96386060: EV_TXCOMPLETE (includes waiting for RX windows) Packet queued 96829613: EV_TXCOMPLETE (includes waiting for RX windows) Packet queued 97273165: EV_TXCOMPLETE (includes waiting for RX windows) Packet queued 97716714: EV_TXCOMPLETE (includes waiting for RX windows) Packet queued 98160266: EV_TXCOMPLETE (includes waiting for RX windows) Packet queued 98603888: EV_TXCOMPLETE (includes waiting for RX windows)

miguerman commented 5 years ago

Hi. I have the same problem, I have TTGO ESP32 LORA V2, I have configured the mapping pins, and the hal.cpp for SPi. I am using the ABP example. Can somebody help me. Greetings.

trlafleur commented 5 years ago

Here is my code that works for OTAA mode, has been running for a few months... you need to change the APPEUI and DEVEUI to match your application on TTN.

It runs on a TTGO ESP32 LORA V2 with OLED US915MHz IDE 1.8.5

(It has a number of #ifdef for other processors and my special needs, stuff you may want to strip out... but I did not have the time to clean it up.... It run's....)


/*
 * TRL  ver 1.1f   29 Jun 2018
 *  added: ESP32 + OLED Display 3 Mar 2018
 * 
 * 
 *  Test Code running on these processors:
 *    TTGO ESP32
 *    Rocketscream ARM M0 RFM95 LoRa board
 *    MoteinoMega LoRa
 * 
 * 
 *  Notes: TTN Port numbers of 1-223 are legal for application
 * 
 * 
 * 
 * 
 * 
 * */

 /* *******************************************************************************
 * Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
 *
 * Permission is hereby granted, free of charge, to anyone
 * obtaining a copy of this document and accompanying files,
 * to do whatever they want with them without any restriction,
 * including, but not limited to, copying, modification and redistribution.
 * NO WARRANTY OF ANY KIND IS PROVIDED.
 *
 * This example sends a valid LoRaWAN packet with payload "Hello, world!", that
 * will be processed by The Things Network server.
 * 
 * This uses OTAA (Over-the-air activation), where where a DevEUI and
 * application key is configured, which are used in an over-the-air
 * activation procedure where a DevAddr and session keys are
 * assigned/generated for use with all further communication.
 *
 * Note: LoRaWAN per sub-band duty-cycle limitation is enforced (1% in g1, 
 *  0.1% in g2). <--- Not in US
 *
 * Change DEVADDR to a unique address! 
 * See http://thethingsnetwork.org/wiki/AddressSpace
 *
 * Do not forget to define the radio type correctly in config.h, default is:
 *   #define CFG_sx1272_radio 1
 * for SX1272 and RFM92, but change to:
 *   #define CFG_sx1276_radio 1
 * for SX1276 and RFM95.
 *
 *******************************************************************************/

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <stdarg.h>
//#include <gBase64.h>
#include <Streaming.h>
#include <Wire.h>         // http://arduino.cc/en/Reference/Wire ??

/* ************************************************************************************** */
// User defines
//#define OLED              // If we are using OLED display

#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))

#define TX_INTERVAL_TASK1 60
#define KeepAlive_TX_INTERVAL 600

/* ************************************************************************************** */
#ifdef __AVR_ATmega1284P__      // MoteinoMega LoRa
// Pin mapping
const lmic_pinmap lmic_pins = 
{
  .nss  = 4,
  .rxtx = LMIC_UNUSED_PIN,    // Not connected on RFM92/RFM95
  .rst  = 3,                  // Needed on RFM92/RFM95 ??
  .dio  = {2, 22, 21},
};
#define myLED 15
#define MyFlashCS 23
#define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__)

/* ************************************************************************************** */
#elif __SAMD21G18A__            // RocketScream
#define Serial SerialUSB
#include <SerialFlash.h>
#include <RTCZero.h>

#define myLED 13              // Is 13 on M0
#define MyFlashCS 4
#define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__)
#define EUI64
#define EUI64_CHIP_ADDRESS 0x50
#define EUI64_MAC_ADDRESS 0xF8
#define EUI64_MAC_LENGTH 0x08

RTCZero rtc;

// Pin mapping
const lmic_pinmap lmic_pins = 
{
  .nss  = 5,
  .rxtx = LMIC_UNUSED_PIN,    // Not connected on RFM92/RFM95
  .rst  = 3,                  // Needed on RFM92/RFM95 ??
  .dio  = {2, 6, LMIC_UNUSED_PIN},
};

/* ************************************************************************************** */
#elif ARDUINO_ARCH_ESP32        // TTGO ESP32
// Pin mapping
const lmic_pinmap lmic_pins = {
    .nss = 18,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 14,   // was 14
    .dio = {26, 33, 32}     // Pins for the Heltec ESP32 Lora board/ TTGO Lora32 with 3D metal antenna
};

#define myLED           2   // Is 2 on ESP32 TTGO
#define OLED                // If we are using OLED display
/* ************************************************************************************** */
#else
#error Wrong Processor defined
#endif
/* ************************************************************************************** */

#ifdef OLED
  // If using 128x64 OLED display
  // OLED display lines are: 0, 8, 16, 24, 32, 40, 48, ~56
  unsigned int counter = 0;
  char TTN_response[30];
  #define OLED_I2C_ADDR   0x3C
  #define OLED_RESET      16
  #define OLED_SDA        4
  #define OLED_SCL        15
  #include <SSD1306.h>        // Using OLED Display on board
  SSD1306 display (OLED_I2C_ADDR, OLED_SDA, OLED_SCL);
#endif

/* ************************************************************************************** */
/*  Enable debug prints to serial monitor on port 0 */
#define MY_DEBUG            // used by MySensor
#define MY_DEBUG1           // used in this program, level 1 debug
//#define MY_DEBUG2           // used in this program, level 2 debug

#define SKETCHNAME "LMiC Test"
#define SKETCHVERSION "1.1f"

/* ************************************************************************************** 
 *            TTN Key's in OTAA Mode
 *          
 *   DEVEUI   Unique ID for each device, we supply per device  64bits   
 *   APPEUI   Unique Application ID, as we registered our Application with TTN 64bits 
 *   APPKEY   Unique to our Application, 128bits, TTN use's it to derived --> NwkSKey and AppSKey
 *   
 *   NwkSKey  Network Session Key, Generated by TTN per session     
 *   AppSKey  Application Session Key, Generated by TTN per session      
 *   DEVADDR  Device Address, Assigned to us when we join the network by TTN
 *   
 *   If EUI64 is define, it will compute the DEVEUI from processer resources
 *          
 * ************************************************************************************** */

// The next two EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70. We have implement a byte swap in this applacation to take care of this.
/* ************************************************************************************** */

#ifdef EUI64
// This should also be in little endian format, see above.
u1_t DEVEUI[EUI64_MAC_LENGTH];
#else
// LoRaWAN DevEUI, unique device ID (LSBF)
//static const u1_t DEVEUI[8]  = { 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const u1_t DEVEUI[8]  = { 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x08 };
#endif

/* ************************************************************************************** */
// LoRaWAN Application EUI identifier (AppEUI) --> (ArtEui in LMiC)
//static const u1_t APPEUI[8]  = { 0x40, 0x1e, 0x00, 0xf0, 0x7e, 0xd5, 0xb3, 0x70 };
static const u1_t APPEUI[8]  = { 0x70, 0xc3, 0xd5, 0x7e, 0xf0, 0xc0, 0x1e, 0x40 };

/* ************************************************************************************** */
// LoRaWAN NwkSKey, network session key (NwkSKey) --> (DEVKEY) --> APPkey
// Use this key for The Things Network, supplied by TTN
static const u1_t DEVKEY[16] = {0xCC, 0x93, 0x5C, 0x8D, 0xA6, 0x9E, 0x93, 0xAE, 0x0B, 0xA6, 0x42, 0x93, 0xA4, 0xCD, 0xB2, 0xE9 };  // <--- Your key here

//////////////////////////////////////////////////
// APPLICATION CALLBACKS
//////////////////////////////////////////////////

/* ************************************************************************************** */
#ifdef EUI64
void os_getDevEui (u1_t* buf) {
  memcpy(buf, DEVEUI, EUI64_MAC_LENGTH);
}
#else
// provide device ID (8 bytes, LSBF)
void os_getDevEui (u1_t* buf) {
    memcpy(buf, DEVEUI, 8);
    RevBytes(buf, 8);      // TTN requires it in LSB First order, so lets swap byte's
}
#endif

/* ************************************************************************************** */
// provide application router ID (APPEUI) (8 bytes, LSBF)
void os_getArtEui (u1_t* buf) {
    memcpy(buf, APPEUI, 8);
    RevBytes(buf, 8);      // TTN requires it in LSB First order, so lets swap byte's
}

/* ************************************************************************************** */
// provide device key (16 bytes)
void os_getDevKey (u1_t* buf) {
    memcpy(buf, DEVKEY, 16);
}

/* ************************************************************************************** */
uint8_t mydata[] = "Hello, World!";
static osjob_t sendjob;
static osjob_t keepalivejob;
bool JoinedFlag = false;

/* ************************************************************************************** */
#ifdef MY_DEBUG
void hwDebugPrint(const char *fmt, ... ) 
{
  char fmtBuffer[300];
  va_list args;
  va_start (args, fmt );
  va_end (args);

#ifdef __SAMD21G18A__             // RocketScream
  vsnprintf(fmtBuffer, 299, fmt, args); 
#elif ARDUINO_ARCH_ESP32          // ESP32
  vsnprintf(fmtBuffer, 299, fmt, args);
#else   
  vsnprintf_P(fmtBuffer, 299, fmt, args);
#endif 

  va_end (args);
  Serial.print(fmtBuffer);    // <---------------------
  Serial.flush();
}

#endif

/* ************************************************************************************** */
/* These are use for local debug of code, hwDebugPrint is defined in MyHwATMega328.cpp */
#ifdef MY_DEBUG
#define debug(x,...) hwDebugPrint(x, ##__VA_ARGS__)
#else
#define debug(x,...)
#endif

#ifdef MY_DEBUG1
#define debug1(x,...) hwDebugPrint(x, ##__VA_ARGS__)
#else
#define debug1(x,...)
#endif

#ifdef MY_DEBUG2
#define debug2(x,...) hwDebugPrint(x, ##__VA_ARGS__)
#else
#define debug2(x,...)
#endif

// **********************************************************
// Function to do a byte swap in a byte array
void RevBytes(unsigned char* b, size_t c)
{
  u1_t i;
  for (i = 0; i < c / 2; i++)
  {
     unsigned char t = b[i];
    b[i] = b[c - 1 - i];
    b[c - 1 - i] = t;
  }
}

// Will display a byte array in hex
void DisplayHex(uint8_t * key, uint8_t len, bool lsb) 
{
  uint8_t start=lsb?len:0;
  uint8_t end = lsb?0:len;
   uint8_t * p ;
    //debug(PSTR(("0x"));
  for (uint8_t i=0; i<len ; i++) {
    p = lsb ? key+len-i-1 : key+i;
    debug(PSTR("%02X "), *p);
  }
  debug(PSTR("\n"));
}

void setDevEui(unsigned char* buf)
{
  Wire.begin();
  Wire.beginTransmission(EUI64_CHIP_ADDRESS);
  Wire.write(EUI64_MAC_ADDRESS);
  Wire.endTransmission();
  Wire.requestFrom(EUI64_CHIP_ADDRESS, EUI64_MAC_LENGTH);

  // Format needs to be little endian (LSB...MSB)
  while (Wire.available())
  {
    *buf-- = Wire.read();
  }
}

// used by onEvent to display keys
u4_t netid = 0;
devaddr_t devaddr = 0;
u1_t nwkKey[16];
u1_t artKey[16];

/* ************************************************************************************** */
void onEvent (ev_t ev) 
{
    debug2(PSTR("---> Event: %02xh, time: %u \n"), ev, millis() / 1000);
    switch(ev) 
    {
/* ************************************************************************************** */      
// scheduled data sent (optionally data received)
// note: this includes the receive window!
      case EV_TXCOMPLETE:
          // use this event to keep track of actual transmissions
          debug(PSTR("Event EV_TXCOMPLETE, time: %u \n"), millis() / 1000);
          JoinedFlag = true;
#ifdef OLED
          display.clear();
          display.drawString (0, 0, "EV_TXCOMPLETE!");
          display.display();
#endif
          digitalWrite(myLED, 0);

          if (LMIC.txrxFlags & TXRX_ACK)
            {
              debug(PSTR("***  Received ACK, time: %u \n"), millis() / 1000);
#ifdef OLED
             display.drawString (0, 16, "Received ACK\n");
             display.display();
#endif
            }

          if(LMIC.dataLen)                                            // chek to see if we have RX data
            {     // data received in rx slot after tx
           // DisplayHex(LMIC.frame, sizeof(LMIC.frame) , false);     // Dump the complete RX frame
              u1_t port = LMIC.frame[LMIC.dataBeg-1];                 // get the port number

              debug(PSTR("**  Data Received! Len: %d Port: %02x\n"), LMIC.dataLen, port );           
              DisplayHex(LMIC.frame+LMIC.dataBeg, LMIC.dataLen, false);   // Get the data

#ifdef OLED           
            int i = 0;
            display.drawString (0, 9, "Received DATA.");
            for ( i = 0 ; i < LMIC.dataLen ; i++ )
            {
                TTN_response[i] = LMIC.frame[LMIC.dataBeg+i];
            }
                TTN_response[i] = 0;
                display.drawString (0, 24, String(TTN_response));
                display.drawString (0, 32, String(LMIC.rssi));
                display.drawString (64,32, String(LMIC.snr));
                display.display();
#endif
            }

           // Schedule next transmission
          os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL_TASK1), do_send_task1);
          break;

/* ************************************************************************************** */
       case EV_JOIN_FAILED:
          debug(PSTR("Event EV_JOIN_FAILED, time: %u \n"), millis() / 1000);
          JoinedFlag = false;
          LMIC_startJoining();    // lets try again...
#ifdef OLED
          display.drawString(0, 32, "EV_JOIN_FAILED....");
          display.display();
#endif
          break;

/* ************************************************************************************** */
       case EV_RXCOMPLETE:
          debug(PSTR("Event EV_RXCOMPLETE, time: %u \n"), millis() / 1000);
          JoinedFlag = true;
          break;

/* ************************************************************************************** */
       case EV_LINK_DEAD:
          debug(PSTR("Event EV_LINK_DEAD, time: %u \n"), millis() / 1000);
          JoinedFlag = false;
          LMIC_startJoining();    // lets try again..
          break;

/* ************************************************************************************** */
       case EV_RESET:
          debug(PSTR("Event EV_RESET, time: %u \n"), millis() / 1000);
          JoinedFlag = false;
          LMIC_startJoining();    // lets try again..
          break;

/* ************************************************************************************** */
       case EV_JOINING:
          debug(PSTR("Event EV_JOINING, time: %u \n"), millis() / 1000);
          JoinedFlag = false;
#ifdef OLED          
          display.drawString(0, 16, "OTTA joining....");
          display.display();
#endif          
          break;

/* ************************************************************************************** */
       case EV_REJOIN_FAILED:
          debug(PSTR("Event EV_REJOIN_FAILED, time: %u \n"), millis() / 1000);
          //JoinedFlag = false;
          break;

/* ************************************************************************************** */
       case EV_JOINED:
          debug(PSTR("Event EV_JOINED, time: %u \n"), millis() / 1000);
          JoinedFlag = true;
#ifdef OLED          
          display.clear();
          display.drawString(0 , 0 ,  "Joined!...");
          display.display();
#endif 
          LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
          debug1(PSTR("\nNetID: %d\n"),netid);

          debug1(PSTR("Device Addr: %02x\n"),devaddr);

          debug1(PSTR("App Session Key: "));
          DisplayHex((uint8_t *)artKey, sizeof (artKey), false);

          debug1(PSTR("Network Key:     "));
          DisplayHex((uint8_t *)nwkKey, sizeof (nwkKey), false);

// Disable link check validation (automatically enabled during join, 
// but because slow data rates change max TX size, we don't use it in this example.
          LMIC_setLinkCheckMode(0);

          do_send_task1(&sendjob);

          break;

/* ************************************************************************************** */
       case EV_BEACON_FOUND:
          debug(PSTR("Event EV_BEACON_FOUND, time: %u \n"), millis() / 1000);
          break;

/* ************************************************************************************** */
       case EV_SCAN_TIMEOUT:
          debug(PSTR("Event EV_SCAN_TIMEOUT, time: %u \n"), millis() / 1000);
          break;

/* ************************************************************************************** */
       case EV_LOST_TSYNC:
          debug(PSTR("Event EV_LOST_TSYNC, time: %u \n"), millis() / 1000);
          break;

/* ************************************************************************************** */
       case EV_BEACON_TRACKED:
          debug(PSTR("Event EV_BEACON_TRACKED, time: %u \n"), millis() / 1000);
          break;

/* ************************************************************************************** */
       case EV_BEACON_MISSED:
          debug(PSTR("Event EV_BEACON_MISSED, time: %u \n"), millis() / 1000);
          break;

/* ************************************************************************************** */
       case EV_RFU1:
          debug(PSTR("Event RGU1, time: %u \n"), millis() / 1000);
          break;

/* ************************************************************************************** */
       case EV_LINK_ALIVE:
          debug(PSTR("Event EV_LINK_ALIVE, time: %u \n"), millis() / 1000);
          break;

/* ************************************************************************************** */
       case EV_TXSTART:
          debug(PSTR("Event TXSTART, time: %u \n"), millis() / 1000);
          break;

/* ************************************************************************************** */
       default:
          debug(PSTR("Event Unknown: %02xh, time: %u \n"), ev, millis() / 1000);
          break;
    }
}

/* ************************************************************************************** */
/* ************************************************************************************** */
void do_keepalive(osjob_t* k)
{
 // Re-Schedule a timed job to run this task again at the given timestamp (absolute system time)
      os_setTimedCallback(k, os_getTime()+sec2osticks(KeepAlive_TX_INTERVAL), do_keepalive); 
} 

/* ************************************************************************************** */
void do_send_task1(osjob_t* j)
{
     debug2(PSTR("---> In Do_Send_Task1\n"));  

  if ( JoinedFlag == true) 
    {
      debug(PSTR("\n***  Joined, Time: %u, Send, txCnhl: %u \n"), millis() / 1000, LMIC.txChnl);
      debug(PSTR("Opmode check: "));   

      // Check if there is not a current TX/RX job running and we are ok to TX
        if (LMIC.opmode & OP_TXRXPEND)                // TXRX-Pending bit 
        {
          debug(PSTR("OP_TXRXPEND, <-- TX/RX was Busy, last msg not yet sent\n"));
        } 
      else 
        {
          debug(PSTR("it's ok to send--\n"));
          // Prepare upstream data transmission at the next possible time.
          LMIC.pendTxConf = true;
          LMIC_setTxData2(1, mydata, sizeof(mydata)-1, true);

            digitalWrite(myLED, HIGH);
    #ifdef OLED        
            display.clear();
            display.drawString (0, 0, "Sending uplink packet...");    
            display.drawString (0, 48, String (++counter));
            display.display ();
    #endif           
        }
    // Next TX is scheduled after TX_COMPLETE event.
    }
   //else   LMIC_startJoining();

    // Schedule a timed job to run this task again at the given timestamp (absolute system time)
    os_setTimedCallback(j, os_getTime()+sec2osticks(TX_INTERVAL_TASK1), do_send_task1);       // <------------------------- time to send
}

/* ************************************************************************************** */
/* ************************************************************************************** */  
/* ************************************************************************************** */  
void setup() 
{

/* ************************************************************************************** */
#ifdef __AVR_ATmega1284P__      // use for Moteino Mega
  Serial.begin(115200);
  delay (2500);

  debug(PSTR("\n ** LMiC Starting on a MoteinoMega **\n") );
    // de-select Flash 
  pinMode(MyFlashCS, OUTPUT);
  digitalWrite(MyFlashCS, HIGH);
    // set the LED digital pin as output:
  pinMode(myLED, OUTPUT);
  digitalWrite(myLED, 0);

/* ************************************************************************************** */
#elif __SAMD21G18A__            // RocketScream Mini Ultra Pro

  Serial.begin(115200);
  while (!Serial);    // wait for USB serial port

  debug(PSTR("\n ** LMiC Starting on a M0 Processor **\n") );

// Initialize serial flash
  SerialFlash.begin(MyFlashCS);
// Put serial flash in sleep
  SerialFlash.sleep();

 // Initialize RTC
  rtc.begin();
// Use RTC as a second timer instead of calendar
  rtc.setEpoch(0);

// ***** Put unused pins into known state *****
  unsigned char pinNumber;

  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);

// D7-D13, A0(D14)-A5(D19), SDA(D20), SCL(D21), MISO(D22)
  for (pinNumber = 7; pinNumber <= 22; pinNumber++)
  {
    pinMode(pinNumber, INPUT_PULLUP);
  }

// RX_LED (D25) & TX_LED (D26) 
// (both LED not mounted on Mini Ultra Pro)
  pinMode(25, INPUT_PULLUP);
  pinMode(26, INPUT_PULLUP);

// D30 (RX) & D31 (TX) of Serial-1
  pinMode(30, INPUT_PULLUP);
  pinMode(31, INPUT_PULLUP);

// D34-D38 (EBDG Interface)
  for (pinNumber = 34; pinNumber <= 38; pinNumber++)
  {
    pinMode(pinNumber, INPUT_PULLUP);
  }
// ***** End of unused pins state initialization *****

  pinMode(LED_BUILTIN, OUTPUT);

  setDevEui(&DEVEUI[EUI64_MAC_LENGTH - 1]);

// Lets print the LMIC version number in hex format
  debug(PSTR(" ** LMIC Ver: %02x\n"),ARDUINO_LMIC_VERSION);

// set the LED digital pin as output:
  pinMode(myLED, OUTPUT);
  digitalWrite(myLED, 0);

/* ************************************************************************************** */  
#elif ARDUINO_ARCH_ESP32
  Serial.begin(115200);
  delay (2500);

  debug(PSTR("\n ** LMiC Starting on a ESP32 **\n") );
  SPI.begin(5,19,27,18);
  uint64_t chipid;  
  chipid=ESP.getEfuseMac();                                  //The chip ID is essentially its MAC address(length: 6 bytes).
  debug(" ** ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));     //print High 2 bytes
  debug("%08X\n",(uint32_t)chipid);                         //print Low 4bytes.
  pinMode(myLED, OUTPUT);
  digitalWrite(myLED, 0);

#endif

/* ************************************************************************************** */ 
#ifdef OLED
//Set up and reset the OLED display
    pinMode(OLED_RESET, OUTPUT);
    digitalWrite(OLED_RESET, LOW);
    delay(50);
    digitalWrite(OLED_RESET, HIGH);

    display.init ();
   // display.flipScreenVertically ();
    display.setFont (ArialMT_Plain_10);
    display.setTextAlignment (TEXT_ALIGN_LEFT);

    display.drawString (0, 0, "Starting....");
    display.display ();
#endif

/* ************************************************************************************** */ 
  const char compile_file[]  = __FILE__ ;
  debug(PSTR(" ** %s %s\n"), SKETCHNAME, SKETCHVERSION);
  debug(PSTR(" ** %s \n"), compile_file);
  const char compile_date[]  = __DATE__ ", " __TIME__;
  debug(PSTR(" ** %s \n"), compile_date);

  debug(PSTR(" ** LMIC Debug Level: %d\n\n"), LMIC_DEBUG_LEVEL);

 /* ************************************************************************************** */  
 /* ************************************************************************************** */    
  // LMIC init
  debug(PSTR("***  LMiC os_init \n"));
  os_init();

  // Reset the MAC state. Session and pending data transfers will be discarded.
  debug(PSTR("***  LMIC_reset \n"));
  LMIC_reset();

  // Open up clock tolarence
  LMIC_setClockError(MAX_CLOCK_ERROR * 2 / 100);

   debug(PSTR("***  Device EUI: "));
   DisplayHex((uint8_t *)DEVEUI, sizeof (DEVEUI), false);

// Set static session parameters. Instead of OTAA dynamically establishing a session 
// by joining the network, precomputed session parameters are provided.
// debug(PSTR("***  LMIC_setSession \n"));
//  LMIC_setSession (0x1, DEVADDR, (uint8_t*)DEVKEY, (uint8_t*)ARTKEY);

// Disable data rate adaptation
//  debug(PSTR("***  LMIC_setAdrMode \n"));
//  LMIC_setAdrMode(false);

// Disable link check validation
  debug(PSTR("***  LMIC_setLinkCheckMode \n"));
  LMIC_setLinkCheckMode(0);

// Disable beacon tracking
//  debug(PSTR("***  LMIC_disableTracking \n"));
//  LMIC_disableTracking ();  // <------------------- will not run if set on ARM M0

// Stop listening for downstream data (periodical reception)
//  debug(PSTR("***  LMIC_stopPingable \n"));
//  LMIC_stopPingable();

// Set data rate and transmit power (note: txpow seems to be ignored by the library)
  debug(PSTR("***  LMIC_setDrTxpow \n"));
  LMIC_setDrTxpow(DR_SF7,20);

// for now only TX on ch 0->15 , disable all others
//  debug(PSTR("***  LMIC_disableChannel, Using Ch = 0 \n"));

//int i = 16;   // Max channel number to use
//  for( u1_t i; i<71; i++ ) 
//    {
//      LMIC_disableChannel(i);
//    }

    // USA channels 0-71 are configured automatically
    // but only one group of 8 should (a subband) should be active
    // TTN recommends the second sub band, 1 in a zero based count.
    LMIC_selectSubBand(1);

    debug(PSTR("\n***  LMIC_StartJoining \n"));
    JoinedFlag = false;
    LMIC_startJoining();

// Start job's (sending automatically starts OTAA too), they will re schedule themselves
    do_send_task1(&sendjob);

    do_keepalive(&keepalivejob);
    //os_setTimedCallback(&keepalivejob, os_getTime()+sec2osticks(KeepAlive_TX_INTERVAL), do_keepalive);
}

// end of setup
/* ************************************************************************************** */

/* ************************************************************************************** */
/* ************************************************************************************** */  
/* ************************************************************************************** */  
void loop() 
{
    os_runloop_once();      // run the LMIC scheduler

 }
/* ************************************************************************************** */
SandroMoretti commented 4 years ago

@6d6176 @miguerman I'm having saming issue, using esp32 ttgo ABP mode. Did you got this?

tortuderelii commented 3 years ago

@SandroMoretti Hey, did you solve the problem? I have the same issue.

CastilloDelacroix commented 2 years ago

Nobody can solve this? I have the same problem

trlafleur commented 2 years ago

I highly suggest you move on to MCCI version as the this basic LMiC code is no longer supported and is way out of date.

You may also want to look at Seeed E5 module that has LoRa stacks, CPU and radio in one module. (Makes using LoRa easy)

~~ /) ~~~~ /) ~~ _/) ~~ _/) ~~

On Nov 8, 2021, at 6:48 AM, CastilloDelacroix @.***> wrote:

 Nobody can solve this? I have the same problem

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.