Help for a newbie ! Lorawan and TTN

Dear All,
i’m Gianmario from Italy and i’m prototiping a WisBlock based on RAK 5005, with RAK4631 and GPS, temp and humidity, accelerometer 3 axis . I wrote an arduino program starting from the examples and i had add the code for the sensors and on serial all look like going good as u can see on the bottom of this post , but on The Things network i seen only the OTAA connection . So i integrated MyDevice as experiment because i doesn’t seen any data , and from MyDevices i receive only the Timestamp
I have a gateway 2 channels of Heltec , model HT-M00

i attach the code :**

   @file LoRaWAN_OTAA_ABP.ino
   @author rakwireless.com
   @brief LoRaWan node example with OTAA/ABP registration
   @version 0.1
   @date 2020-08-21

   @copyright Copyright (c) 2020

   @note RAK4631 GPIO mapping to nRF52840 GPIO ports
   RAK4631    <->  nRF52840
   WB_IO1     <->  P0.17 (GPIO 17)
   WB_IO2     <->  P1.02 (GPIO 34)
   WB_IO3     <->  P0.21 (GPIO 21)
   WB_IO4     <->  P0.04 (GPIO 4)
   WB_IO5     <->  P0.09 (GPIO 9)
   WB_IO6     <->  P0.10 (GPIO 10)
   WB_SW1     <->  P0.01 (GPIO 1)
   WB_A0      <->  P0.04/AIN2 (AnalogIn A2)
   WB_A1      <->  P0.31/AIN7 (AnalogIn A7)
*/
#include <Arduino.h>
#include <LoRaWan-RAK4630.h> //http://librarymanager/All#SX126x
#include <SPI.h>
#include "SparkFun_SHTC3.h"     //Click here to get the library: http://librarymanager/All#SparkFun_SHTC3
SHTC3 g_shtc3;                  // Declare an instance of the SHTC3 class

// RAK4630 supply two LED
#ifndef LED_BUILTIN
#define LED_BUILTIN 35
#endif

#ifndef LED_BUILTIN2
#define LED_BUILTIN2 36
#endif

bool doOTAA = true;   // OTAA is used by default.
#define SCHED_MAX_EVENT_DATA_SIZE APP_TIMER_SCHED_EVENT_DATA_SIZE /**< Maximum size of scheduler events. */
#define SCHED_QUEUE_SIZE 60										  /**< Maximum number of events in the scheduler queue. */
#define LORAWAN_DATERATE DR_0									  /*LoRaMac datarates definition, from DR_0 to DR_5*/
#define LORAWAN_TX_POWER TX_POWER_5							/*LoRaMac tx power definition, from TX_POWER_0 to TX_POWER_15*/
#define JOINREQ_NBTRIALS 3										  /**< Number of trials for the join request. */
DeviceClass_t g_CurrentClass = CLASS_A;					/* class definition*/
LoRaMacRegion_t g_CurrentRegion = LORAMAC_REGION_EU868;    /* Region:EU868*/
lmh_confirm g_CurrentConfirm = LMH_CONFIRMED_MSG;				  /* confirm/unconfirm packet definition*/
uint8_t gAppPort = LORAWAN_APP_PORT;							        /* data port*/

/**@brief Structure containing LoRaWan parameters, needed for lmh_init()
*/
static lmh_param_t g_lora_param_init = {LORAWAN_ADR_ON, LORAWAN_DATERATE, LORAWAN_PUBLIC_NETWORK, JOINREQ_NBTRIALS, LORAWAN_TX_POWER, LORAWAN_DUTYCYCLE_OFF};

// Foward declaration
static void lorawan_has_joined_handler(void);
static void lorawan_join_failed_handler(void);
static void lorawan_rx_handler(lmh_app_data_t *app_data);
static void lorawan_confirm_class_handler(DeviceClass_t Class);
static void send_lora_frame(void);

/**@brief Structure containing LoRaWan callback functions, needed for lmh_init()
*/
static lmh_callback_t g_lora_callbacks = {BoardGetBatteryLevel, BoardGetUniqueId, BoardGetRandomSeed,
                                          lorawan_rx_handler, lorawan_has_joined_handler, lorawan_confirm_class_handler, lorawan_join_failed_handler
                                         };
//OTAA keys !!!! KEYS ARE MSB !!!!001D49E711CECDAB
uint8_t nodeDeviceEUI[8] = { 0x00, 0x1D, 0x49, 0xE7, 0x11, 0xCE, 0xCD, 0xAB };
uint8_t nodeAppEUI[8] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x04, 0x14, 0x80 };
uint8_t nodeAppKey[16] = { 0x78, 0xDE, 0x42, 0x3A, 0xDD, 0xF4, 0xB6, 0x38, 0x6A, 0xDF, 0x0F, 0xA7, 0x7E, 0xEE, 0xA5, 0x3C };

// ABP keys
uint32_t nodeDevAddr = 0x260116F8;
uint8_t nodeNwsKey[16] = {0x7E, 0xAC, 0xE2, 0x55, 0xB8, 0xA5, 0xE2, 0x69, 0x91, 0x51, 0x96, 0x06, 0x47, 0x56, 0x9D, 0x23};
uint8_t nodeAppsKey[16] = {0xFB, 0xAC, 0xB6, 0x47, 0xF3, 0x58, 0x45, 0xC7, 0x50, 0x7D, 0xBF, 0x16, 0x8B, 0xA8, 0xC1, 0x7C};

// Private defination
#define LORAWAN_APP_DATA_BUFF_SIZE 64                     /**< buffer size of the data to be transmitted. */
#define LORAWAN_APP_INTERVAL 20000                        /**< Defines for user timer, the application data transmission interval. 20s, value in [ms]. */
static uint8_t m_lora_app_data_buffer[LORAWAN_APP_DATA_BUFF_SIZE];            //< Lora user application data buffer.
static lmh_app_data_t m_lora_app_data = {m_lora_app_data_buffer, 0, 0, 0, 0}; //< Lora user application data structure.

TimerEvent_t appTimer;
static uint32_t timers_init(void);
static uint32_t count = 0;
static uint32_t count_fail = 0;
// sensore BM 
void errorDecoder(SHTC3_Status_TypeDef message)   // The errorDecoder function prints "SHTC3_Status_TypeDef" resultsin a human-friendly way
{
  switch (message)
  {
    case SHTC3_Status_Nominal:
      Serial.print("Nominal");
      break;
    case SHTC3_Status_Error:
      Serial.print("Error");
      break;
    case SHTC3_Status_CRC_Fail:
      Serial.print("CRC Fail");
      break;
    default:
      Serial.print("Unknown return code");
      break;
  }
}

void shtc3_read_data(void)
{
  float Temperature = 0;
  float Humidity = 0;
  
  g_shtc3.update();
  if (g_shtc3.lastStatus == SHTC3_Status_Nominal) // You can also assess the status of the last command by checking the ".lastStatus" member of the object
  {

    Temperature = g_shtc3.toDegC();               // Packing LoRa data
    Humidity = g_shtc3.toPercent();
    
    Serial.print("RH = ");
    Serial.print(g_shtc3.toPercent());            // "toPercent" returns the percent humidity as a floating point number
    Serial.print("% (checksum: ");
    
    if (g_shtc3.passRHcrc)                        // Like "passIDcrc" this is true when the RH value is valid from the sensor (but not necessarily up-to-date in terms of time)
    {
      Serial.print("pass");
    }
    else
    {
      Serial.print("fail");
    }
    
    Serial.print("), T = ");
    Serial.print(g_shtc3.toDegC());               // "toDegF" and "toDegC" return the temperature as a flaoting point number in deg F and deg C respectively
    Serial.print(" deg C (checksum: ");
    
    if (g_shtc3.passTcrc)                         // Like "passIDcrc" this is true when the T value is valid from the sensor (but not necessarily up-to-date in terms of time)
    {
      Serial.print("pass");
    }
    else
    {
      Serial.print("fail");
    }
    Serial.println(")");
  }
  else
  {
    Serial.print("Update failed, error: ");
    errorDecoder(g_shtc3.lastStatus);
    Serial.println();
  }
}

void setup()
{
  {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  // Initialize LoRa chip.
  lora_rak4630_init();

  // Initialize Serial for debug output
  time_t timeout = millis();
  Serial.begin(115200);
  while (!Serial)
  {
    if ((millis() - timeout) < 5000)
    {
      delay(100);
    }
    else
    {
      break;
    }
  }
  Serial.println("=====================================");
  Serial.println("Welcome to RAK4630 LoRaWan!!!");
  if (doOTAA)
  {
    Serial.println("Type: OTAA");
  }
  else
  {
    Serial.println("Type: ABP");
  }

  switch (g_CurrentRegion)
  {
    case LORAMAC_REGION_AS923:
      Serial.println("Region: AS923");
      break;
    case LORAMAC_REGION_AU915:
      Serial.println("Region: AU915");
      break;
    case LORAMAC_REGION_CN470:
      Serial.println("Region: CN470");
      break;
    case LORAMAC_REGION_EU433:
      Serial.println("Region: EU433");
      break;
    case LORAMAC_REGION_IN865:
      Serial.println("Region: IN865");
      break;
    case LORAMAC_REGION_EU868:
      Serial.println("Region: EU868");
      break;
    case LORAMAC_REGION_KR920:
      Serial.println("Region: KR920");
      break;
    case LORAMAC_REGION_US915:
      Serial.println("Region: US915");
      break;
 
  
  time_t timeout = millis();
  Serial.begin(115200);
  while (!Serial)
  {
    if ((millis() - timeout) < 5000)
    {
            delay(100);
        }
        else
        {
            break;
        }
  }
 }
  Wire.begin();
  Serial.println("shtc3 init");
  Serial.print("Beginning sensor. Result = "); // Most SHTC3 functions return a variable of the type "SHTC3_Status_TypeDef" to indicate the status of their execution
  errorDecoder(g_shtc3.begin());              // To start the sensor you must call "begin()", the default settings use Wire (default Arduino I2C port)
  Wire.setClock(400000);                      // The sensor is listed to work up to 1 MHz I2C speed, but the I2C clock speed is global for all sensors on that bus so using 400kHz or 100kHz is recommended
  Serial.println();

  if (g_shtc3.passIDcrc)                      // Whenever data is received the associated checksum is calculated and verified so you can be sure the data is true
  {                                           // The checksum pass indicators are: passIDcrc, passRHcrc, and passTcrc for the ID, RH, and T readings respectively
    Serial.print("ID Passed Checksum. ");
    Serial.print("Device ID: 0b");
    Serial.println(g_shtc3.ID, BIN);          // The 16-bit device ID can be accessed as a member variable of the object
  }
  else
  {
    Serial.println("ID Checksum Failed. ");
  }
}
// fine sensore BM




  Serial.println("=====================================");

  //creat a user timer to send data to server period
  uint32_t err_code;
  err_code = timers_init();
  if (err_code != 0)
  {
    Serial.printf("timers_init failed - %d\n", err_code);
    return;
  }

  // Setup the EUIs and Keys
  if (doOTAA)
  {
    lmh_setDevEui(nodeDeviceEUI);
    lmh_setAppEui(nodeAppEUI);
    lmh_setAppKey(nodeAppKey);
  }
  else
  {
    lmh_setNwkSKey(nodeNwsKey);
    lmh_setAppSKey(nodeAppsKey);
    lmh_setDevAddr(nodeDevAddr);
  }

  // Initialize LoRaWan
  err_code = lmh_init(&g_lora_callbacks, g_lora_param_init, doOTAA, g_CurrentClass, g_CurrentRegion);
  if (err_code != 0)
  {
    Serial.printf("lmh_init failed - %d\n", err_code);
    return;
  }

  // Start Join procedure
  lmh_join();
}

void loop()
{
  // Put your application tasks here, like reading of sensors,
  // Controlling actuators and/or other functions.
  {
  shtc3_read_data();
  delay(1000);
  send_lora_frame();
  
}

}

/**@brief LoRa function for handling HasJoined event.
*/
void lorawan_has_joined_handler(void)
{
  Serial.println("OTAA Mode, Network Joined!");

  lmh_error_status ret = lmh_class_request(g_CurrentClass);
  if (ret == LMH_SUCCESS)
  {
    delay(1000);
    TimerSetValue(&appTimer, LORAWAN_APP_INTERVAL);
    TimerStart(&appTimer);
  }
}
/**@brief LoRa function for handling OTAA join failed
*/
static void lorawan_join_failed_handler(void)
{
  Serial.println("OTAA join failed!");
  Serial.println("Check your EUI's and Keys's!");
  Serial.println("Check if a Gateway is in range!");
}
/**@brief Function for handling LoRaWan received data from Gateway

   @param[in] app_data  Pointer to rx data
*/
void lorawan_rx_handler(lmh_app_data_t *app_data)
{
  Serial.printf("LoRa Packet received on port %d, size:%d, rssi:%d, snr:%d, data:%s\n",
                app_data->port, app_data->buffsize, app_data->rssi, app_data->snr, app_data->buffer);
}

void lorawan_confirm_class_handler(DeviceClass_t Class)
{
  Serial.printf("switch to class %c done\n", "ABC"[Class]);
  // Informs the server that switch has occurred ASAP
  m_lora_app_data.buffsize = 0;
  m_lora_app_data.port = gAppPort;
  lmh_send(&m_lora_app_data, g_CurrentConfirm);
}

void send_lora_frame(void)
{
  if (lmh_join_status_get() != LMH_SET)
  {
    //Not joined, try again later
    return;
  }

  uint32_t i = 0;
  memset(m_lora_app_data.buffer, 0, LORAWAN_APP_DATA_BUFF_SIZE);
  m_lora_app_data.port = gAppPort;
  m_lora_app_data.buffer[i++] = 'H';
  m_lora_app_data.buffer[i++] = 'e';
  m_lora_app_data.buffer[i++] = 'l';
  m_lora_app_data.buffer[i++] = 'l';
  m_lora_app_data.buffer[i++] = 'o';
  m_lora_app_data.buffer[i++] = '!';
  m_lora_app_data.buffsize = i;

  lmh_error_status error = lmh_send(&m_lora_app_data, g_CurrentConfirm);
  if (error == LMH_SUCCESS)
  {
    count++;
    Serial.printf("lmh_send ok count %d\n", count);
  }
  else
  {
    count_fail++;
    Serial.printf("lmh_send fail count %d\n", count_fail);
  }
}

/**@brief Function for handling user timerout event.
*/
void tx_lora_periodic_handler(void)
{
  TimerSetValue(&appTimer, LORAWAN_APP_INTERVAL);
  TimerStart(&appTimer);
  shtc3_read_data();
  Serial.println("Sending frame now...");
  send_lora_frame();
}

/**@brief Function for the Timer initialization.

   @details Initializes the timer module. This creates and starts application timers.
*/
uint32_t timers_init(void)
{
  TimerInit(&appTimer, tx_lora_periodic_handler);
  return 0;
}

THE OUTPUT :

13:50:46.443 -> =====================================
13:50:46.443 -> Welcome to RAK4630 LoRaWan!!!
13:50:46.443 -> Type: OTAA
13:50:46.443 -> Region: EU868
13:50:46.443 -> shtc3 init
13:50:46.443 -> Beginning sensor. Result = Nominal
13:50:46.443 -> ID Passed Checksum. Device ID: 0b100001000111
13:50:46.443 -> =====================================
13:50:46.443 -> <LMH> OTAA 
13:50:46.443 -> DevEui=00-1D-49-E7-11-CE-CD-AB
13:50:46.443 -> DevAdd=00000000
13:50:46.443 -> AppEui=70-B3-D5-7E-D0-04-14-80
13:50:46.443 -> AppKey=78-DE-42-3A-DD-F4-B6-38-6A-DF-0F-A7-7E-EE-A5-3C
13:50:46.508 -> <LMH> Selected subband 1
13:50:46.541 -> 
13:50:46.541 -> BSP Library : 0.21.20
13:50:46.541 -> Bootloader  : s140 6.1.1
13:50:46.541 -> Serial No   : B778DD5D8C63174C
13:50:46.541 -> 
13:50:46.541 -> RH = 30.97% (checksum: pass), T = 26.58 deg C (checksum: pass)
13:50:46.608 -> <LM> OnRadioTxDone
13:50:47.572 -> <LM> OnRadioTxDone => RX Windows #1 4989 #2 5995
13:50:47.572 -> <LM> OnRadioTxDone => TX was Join Request
13:50:47.572 -> RH = 30.96% (checksum: pass), T = 26.60 deg C (checksum: pass)
13:50:48.568 -> RH = 30.97% (checksum: pass), T = 26.58 deg C (checksum: pass)
13:50:49.601 -> RH = 30.98% (checksum: pass), T = 26.59 deg C (checksum: pass)
13:50:50.600 -> RH = 30.98% (checksum: pass), T = 26.60 deg C (checksum: pass)
13:50:51.600 -> RH = 30.99% (checksum: pass), T = 26.61 deg C (checksum: pass)
13:50:51.667 -> <LM> OnRadioRxDone
13:50:51.667 -> <LM> OnRadioRxDone => FRAME_TYPE_JOIN_ACCEPT
13:50:51.667 -> OTAA Mode, Network Joined!
13:50:52.631 -> lmh_send ok count 1
13:50:52.631 -> RH = 30.98% (checksum: pass), T = 26.59 deg C (checksum: pass)
13:50:53.629 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:50:53.629 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:50:53.629 -> lmh_send fail count 1
13:50:53.662 -> RH = 31.00% (checksum: pass), T = 26.60 deg C (checksum: pass)
13:50:53.962 -> <LM> OnRadioTxDone
13:50:54.657 -> <LM> OnRadioTxDone => RX Windows #1 1030 #2 1995
13:50:54.657 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:50:54.657 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:50:54.657 -> lmh_send fail count 2
13:50:54.657 -> RH = 30.98% (checksum: pass), T = 26.61 deg C (checksum: pass)
13:50:55.653 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:50:55.653 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:50:55.653 -> lmh_send fail count 3
13:50:55.702 -> RH = 30.98% (checksum: pass), T = 26.58 deg C (checksum: pass)
13:50:56.669 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:50:56.669 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:50:56.669 -> lmh_send fail count 4
13:50:56.702 -> RH = 30.99% (checksum: pass), T = 26.59 deg C (checksum: pass)
13:50:57.702 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:50:57.702 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:50:57.702 -> lmh_send fail count 5
13:50:57.702 -> RH = 30.97% (checksum: pass), T = 26.62 deg C (checksum: pass)
13:50:58.701 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:50:58.701 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:50:58.701 -> lmh_send fail count 6
13:50:58.701 -> RH = 31.01% (checksum: pass), T = 26.61 deg C (checksum: pass)
13:50:58.999 -> <RADIO> RadioIrqProcess => IRQ_RX_TX_TIMEOUT
13:50:58.999 -> <LM> OnRadioRxTimeout
13:50:59.694 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:50:59.694 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:50:59.694 -> lmh_send fail count 7
13:50:59.728 -> RH = 31.00% (checksum: pass), T = 26.63 deg C (checksum: pass)
13:51:00.458 -> <LM> OnRadioTxDone
13:51:00.724 -> <LM> OnRadioTxDone => RX Windows #1 1030 #2 1995
13:51:00.724 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:51:00.724 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:51:00.724 -> lmh_send fail count 8
13:51:00.724 -> RH = 30.98% (checksum: pass), T = 26.63 deg C (checksum: pass)
13:51:01.722 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:51:01.722 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:51:01.722 -> lmh_send fail count 9
13:51:01.755 -> RH = 30.98% (checksum: pass), T = 26.61 deg C (checksum: pass)
13:51:02.752 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:51:02.752 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:51:02.752 -> lmh_send fail count 10
13:51:02.752 -> RH = 31.00% (checksum: pass), T = 26.66 deg C (checksum: pass)
13:51:03.750 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:51:03.750 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:51:03.750 -> lmh_send fail count 11
13:51:03.783 -> RH = 30.96% (checksum: pass), T = 26.62 deg C (checksum: pass)
13:51:04.782 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:51:04.782 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:51:04.782 -> lmh_send fail count 12
13:51:04.782 -> RH = 31.00% (checksum: pass), T = 26.65 deg C (checksum: pass)
13:51:05.512 -> <RADIO> RadioIrqProcess => IRQ_RX_TX_TIMEOUT
13:51:05.512 -> <LM> OnRadioRxTimeout
13:51:05.778 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:51:05.778 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:51:05.778 -> lmh_send fail count 13
13:51:05.778 -> RH = 31.00% (checksum: pass), T = 26.64 deg C (checksum: pass)
13:51:06.807 -> <LM> LoRaMacMcpsRequest LORAMAC_STATUS_BUSY
13:51:06.807 -> <LMH> lmh_send -> LoRaMacMcpsRequest failed
13:51:06.807 -> lmh_send fail count 14
...

And in the TTN i see only one row on my application’s console under the data panel " ACTIVATION " but any of other datas .

Please help me …

That is not a gateway, that is a Dual Channel Packet Forwarder that can only hear two channels and only one Spreading Factor on each channel at a time.

Whereas a gateway can hear on 8 channels and detect transmissions on any of the Spreading Factors at the same time - so there are 48 possibilities that the device can transmit on and your DCPF can only hear 2 of them.

So your device transmits a join request but your DCPF can’t transmit the answer as it won’t understand the request correctly. Until the device joins, it will never be able to uplink. Even if by some statistical co-incidence of channel selection, it would still suffer dropped uplinks as the gateway won’t be able to hear the majority of the frequency & SF combinations.

As this will cause similar disruption to other users of the community TTN, please disconnect your DCPF immediately.

You’ll need to get yourself a RAK7246 or similar to hear your device.

1 Like

dear Mr McCloud , really thank’s , i had unplugged the Heltec and ordered the gateway you suggest !
Thank you very much for the help.

A post was split to a new topic: Point to Point LoRa - how to select only one transmitter?