AB02S not connecting after updating Duty Cycle

Hello. New here. New to hardware coding. I am using the CubeCell AB02S. This weekend I was able to connect and have the device functioning. Today, I went in and changed the appTxDutyCycle from the default to 180 * 1000 ms. Now, the device will not connect. Just says “Joining” the whole time. Serial output is “join failed, join again at 30s later” I removed the OTAA keys to keep them safe. Also, the White LED flashes 3-4 times when joining. This was not happening before.

Everything was working as expected. I just wanted to not send data so much - eventually every hour, but wanted to try 18 seconds.

/* The example is for CubeCell_GPS,
 * GPS works only before lorawan uplink, the board current is about 45uA when in lowpower mode.
 */
#include "LoRaWan_APP.h"
#include "Arduino.h"
#include "GPS_Air530.h"
#include "cubecell_SSD1306Wire.h"

extern SSD1306Wire  display; 

//when gps waked, if in GPS_UPDATE_TIMEOUT, gps not fixed then into low power mode
#define GPS_UPDATE_TIMEOUT 120000

//once fixed, GPS_CONTINUE_TIME later into low power mode
#define GPS_CONTINUE_TIME 60000
/*
   set LoraWan_RGB to Active,the RGB active in loraWan
   RGB red means sending;
   RGB purple means joined done;
   RGB blue means RxWindow1;
   RGB yellow means RxWindow2;
   RGB green means received done;
*/

/* OTAA para*/
uint8_t devEui[] = { };
uint8_t appEui[] = { };
uint8_t appKey[] = { };

/* ABP para*/
uint8_t nwkSKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t appSKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint32_t devAddr =  ( uint32_t )0x00000000;

/*LoraWan channelsmask, default channels 0-7*/ 
uint16_t userChannelsMask[6]={ 0xFF00,0x0000,0x0000,0x0000,0x0000,0x0000 };

/*LoraWan region, select in arduino IDE tools*/
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;

/*LoraWan Class, Class A and Class C are supported*/
DeviceClass_t  loraWanClass = LORAWAN_CLASS;

/*the application data transmission duty cycle.  value in [ms].*/
uint32_t appTxDutyCycle = 180 * 1000;  /* Should be 180 seconds */

/*OTAA or ABP*/
bool overTheAirActivation = LORAWAN_NETMODE;

/*ADR enable*/
bool loraWanAdr = LORAWAN_ADR;

/* set LORAWAN_Net_Reserve ON, the node could save the network info to flash, when node reset not need to join again */
bool keepNet = LORAWAN_NET_RESERVE;

/* Indicates if the node is sending confirmed or unconfirmed messages */
bool isTxConfirmed = LORAWAN_UPLINKMODE;

/* Application port */
uint8_t appPort = 2;
/*!
  Number of trials to transmit the frame, if the LoRaMAC layer did not
  receive an acknowledgment. The MAC performs a datarate adaptation,
  according to the LoRaWAN Specification V1.0.2, chapter 18.4, according
  to the following table:

  Transmission nb | Data Rate
  ----------------|-----------
  1 (first)       | DR
  2               | DR
  3               | max(DR-1,0)
  4               | max(DR-1,0)
  5               | max(DR-2,0)
  6               | max(DR-2,0)
  7               | max(DR-3,0)
  8               | max(DR-3,0)

  Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
  the datarate, in case the LoRaMAC layer did not receive an acknowledgment
*/
uint8_t confirmedNbTrials = 4;

int32_t fracPart(double val, int n)
{
  return (int32_t)((val - (int32_t)(val))*pow(10,n));
}

void VextON(void)
{
  pinMode(Vext,OUTPUT);
  digitalWrite(Vext, LOW);
}

void VextOFF(void) //Vext default OFF
{
  pinMode(Vext,OUTPUT);
  digitalWrite(Vext, HIGH);
}
void displayGPSInof()
{
  char str[30];
  display.clear();
  display.setFont(ArialMT_Plain_10);
  int index = sprintf(str,"%02d-%02d-%02d",Air530.date.year(),Air530.date.day(),Air530.date.month());
  str[index] = 0;
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(0, 0, str);
  
  index = sprintf(str,"%02d:%02d:%02d",Air530.time.hour(),Air530.time.minute(),Air530.time.second(),Air530.time.centisecond());
  str[index] = 0;
  display.drawString(60, 0, str);

  if( Air530.location.age() < 1000 )
  {
display.drawString(120, 0, "A");
  }
  else
  {
display.drawString(120, 0, "V");
  }
  
  index = sprintf(str,"alt: %d.%d",(int)Air530.altitude.meters(),fracPart(Air530.altitude.meters(),2));
  str[index] = 0;
  display.drawString(0, 16, str);
   
  index = sprintf(str,"hdop: %d.%d",(int)Air530.hdop.hdop(),fracPart(Air530.hdop.hdop(),2));
  str[index] = 0;
  display.drawString(0, 32, str); 
 
  index = sprintf(str,"lat :  %d.%d",(int)Air530.location.lat(),fracPart(Air530.location.lat(),4));
  str[index] = 0;
  display.drawString(60, 16, str);   
  
  index = sprintf(str,"lon:%d.%d",(int)Air530.location.lng(),fracPart(Air530.location.lng(),4));
  str[index] = 0;
  display.drawString(60, 32, str);

  display.display();
}

void printGPSInof()
{
  Serial.print("Date/Time: ");
  if (Air530.date.isValid())
  {
Serial.printf("%d/%02d/%02d",Air530.date.year(),Air530.date.day(),Air530.date.month());
  }
  else
  {
Serial.print("INVALID");
  }

  if (Air530.time.isValid())
  {
Serial.printf(" %02d:%02d:%02d.%02d",Air530.time.hour(),Air530.time.minute(),Air530.time.second(),Air530.time.centisecond());
  }
  else
  {
Serial.print(" INVALID");
  }
  Serial.println();
  
  Serial.print("LAT: ");
  Serial.print(Air530.location.lat(),6);
  Serial.print(", LON: ");
  Serial.print(Air530.location.lng(),6);
  Serial.print(", ALT: ");
  Serial.print(Air530.altitude.meters());

  Serial.println(); 
  
  Serial.print("SATS: ");
  Serial.print(Air530.satellites.value());
  Serial.print(", HDOP: ");
  Serial.print(Air530.hdop.hdop());
  Serial.print(", AGE: ");
  Serial.print(Air530.location.age());
  Serial.print(", COURSE: ");
  Serial.print(Air530.course.deg());
  Serial.print(", SPEED: ");
  Serial.println(Air530.speed.kmph());
  Serial.println();
}

static void prepareTxFrame( uint8_t port )
{
  /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h".
appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
for example, if use REGION_CN470,
the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
  */

  float lat, lon, alt, course, speed, hdop, sats;
  
  Serial.println("Waiting for GPS FIX ...");

  VextON();// oled power on;
  delay(10); 
  display.init();
  display.clear();
  
  display.setTextAlignment(TEXT_ALIGN_CENTER);
  display.setFont(ArialMT_Plain_16);
  display.drawString(64, 32-16/2, "GPS Searching...");
  Serial.println("GPS Searching...");
  display.display();
  
  Air530.begin();

  uint32_t start = millis();
  while( (millis()-start) < GPS_UPDATE_TIMEOUT )
  {
while (Air530.available() > 0)
{
  Air530.encode(Air530.read());
}
   // gps fixed in a second
if( Air530.location.age() < 1000 )
{
  break;
}
  }
  
  //if gps fixed,  GPS_CONTINUE_TIME later stop GPS into low power mode, and every 1 second update gps, print and display gps info
  if(Air530.location.age() < 1000)
  {
start = millis();
uint32_t printinfo = 0;
while( (millis()-start) < GPS_CONTINUE_TIME )
{
  while (Air530.available() > 0)
  {
    Air530.encode(Air530.read());
  }

  if( (millis()-start) > printinfo )
  {
    printinfo += 1000;
    printGPSInof();
    displayGPSInof();
  }
}
  }
  else
  {
display.clear();  
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setFont(ArialMT_Plain_16);
display.drawString(64, 32-16/2, "No GPS signal");
Serial.println("No GPS signal");
display.display();
delay(2000);
  }
  Air530.end(); 
  display.clear();
  display.display();
  display.stop();
  VextOFF(); //oled power off
  
  lat = Air530.location.lat();
  lon = Air530.location.lng();
  alt = Air530.altitude.meters();
/*
  course = Air530.course.deg();
  speed = Air530.speed.kmph();
  sats = Air530.satellites.value();
  hdop = Air530.hdop.hdop();
*/
  uint16_t batteryVoltage = getBatteryVoltage();

  unsigned char *puc;

  appDataSize = 0;
  puc = (unsigned char *)(&lat);
  appData[appDataSize++] = puc[0];
  appData[appDataSize++] = puc[1];
  appData[appDataSize++] = puc[2];
  appData[appDataSize++] = puc[3];
  puc = (unsigned char *)(&lon);
  appData[appDataSize++] = puc[0];
  appData[appDataSize++] = puc[1];
  appData[appDataSize++] = puc[2];
  appData[appDataSize++] = puc[3];
  puc = (unsigned char *)(&alt);
  appData[appDataSize++] = puc[0];
  appData[appDataSize++] = puc[1];
  appData[appDataSize++] = puc[2];
  appData[appDataSize++] = puc[3];
/*
  puc = (unsigned char *)(&course);
  appData[appDataSize++] = puc[0];
  appData[appDataSize++] = puc[1];
  appData[appDataSize++] = puc[2];
  appData[appDataSize++] = puc[3];
  puc = (unsigned char *)(&speed);
  appData[appDataSize++] = puc[0];
  appData[appDataSize++] = puc[1];
  appData[appDataSize++] = puc[2];
  appData[appDataSize++] = puc[3];
  puc = (unsigned char *)(&hdop);
  appData[appDataSize++] = puc[0];
  appData[appDataSize++] = puc[1];
  appData[appDataSize++] = puc[2];
  appData[appDataSize++] = puc[3];
*/
  appData[appDataSize++] = (uint8_t)(batteryVoltage >> 8);
  appData[appDataSize++] = (uint8_t)batteryVoltage;

  Serial.print("SATS: ");
  Serial.print(Air530.satellites.value());
  Serial.print(", HDOP: ");
  Serial.print(Air530.hdop.hdop());
  Serial.print(", LAT: ");
  Serial.print(Air530.location.lat());
  Serial.print(", LON: ");
  Serial.print(Air530.location.lng());
  Serial.print(", AGE: ");
  Serial.print(Air530.location.age());
  Serial.print(", ALT: ");
  Serial.print(Air530.altitude.meters());
  Serial.print(", COURSE: ");
  Serial.print(Air530.course.deg());
  Serial.print(", SPEED: ");
  Serial.println(Air530.speed.kmph());
  Serial.print(" BatteryVoltage:");
  Serial.println(batteryVoltage);
 
}


void setup() {
  boardInitMcu();
  Serial.begin(115200);

#if(AT_SUPPORT)
  enableAt();
#endif
  LoRaWAN.displayMcuInit();
  deviceState = DEVICE_STATE_INIT;
  LoRaWAN.ifskipjoin();
}

void loop()
{
  switch( deviceState )
  {
case DEVICE_STATE_INIT:
{
  #if(LORAWAN_DEVEUI_AUTO)
        LoRaWAN.generateDeveuiByChipID();
  #endif
  #if(AT_SUPPORT)
        getDevParam();
  #endif
  printDevParam();
  LoRaWAN.init(loraWanClass,loraWanRegion);
  deviceState = DEVICE_STATE_JOIN;
  break;
}
case DEVICE_STATE_JOIN:
{
  LoRaWAN.displayJoining();
  LoRaWAN.join();
  break;
}
case DEVICE_STATE_SEND:
{
  prepareTxFrame( appPort );
  LoRaWAN.displaySending();
  LoRaWAN.send();
  display.stop();
  deviceState = DEVICE_STATE_CYCLE;
  break;
}
case DEVICE_STATE_CYCLE:
{
  // Schedule next packet transmission
  txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND );
  LoRaWAN.cycle(txDutyCycleTime);
  deviceState = DEVICE_STATE_SLEEP;
  break;
}
case DEVICE_STATE_SLEEP:
{
  LoRaWAN.displayAck();
  LoRaWAN.sleep();
  break;
}
default:
{
  deviceState = DEVICE_STATE_INIT;
  break;
}
  }
}

Also, is there any way to get the error as to why it didn’t connect? I am a web developer by trade and I can debug when I know the error codes. I couldn’t figure out how to get the errors here. thanks!

My apologies! I was able to add in some debugging code and found the issue. I save my project last night, but when I opened it today the CubeCell parameters in the tools menu reset themselves. Once I fixed those, everything came back.

1 Like

Hi! Can you explain how you managed to fix the problem?

The OP created a problem for himself that appears to have magically fixed itself.

So unless you have altered the code, this isn’t likely to help. Perhaps you could tell us what issue you are facing?

For the context: I use an HTCC-AB02S with the following code LoRaWan_OnBoardGPS_Air530Z .

The problem is I can’t connect to TTN unless I’m in the same room with the gateway.
If I’m outside the building the connection is lost . My concern is that the problem is caused by a hardware problem. The serial monitor looks like this:

LoRaWAN EU868 Class A start!
joining...TX on freq 868100000 Hz at DR 5
TX on freq 868100000 Hz at DR 5
Event : Tx Done
RX on freq 868100000 Hz at DR 5
Event : Rx Timeout
RX on freq 869525000 Hz at DR 0
Event : Rx Timeout
TX on freq 868300000 Hz at DR 5
TX on freq 868300000 Hz at DR 5
Event : Tx Done
RX on freq 868300000 Hz at DR 5
Event : Rx Timeout
RX on freq 869525000 Hz at DR 0
Event : Rx Timeout
TX on freq 868300000 Hz at DR 5
TX on freq 868300000 Hz at DR 5
Event : Tx Done
RX on freq 868300000 Hz at DR 5
Event : Rx Timeout
RX on freq 869525000 Hz at DR 0

Any ideas?

Format posts and check your antennas.

What are the antenna look like, gateway and node?

What do you see in the console when it connects?

The antenna is the original one that came with the board. I don’t think it’s a problem with the gateway because I have another board (HTCC-AB01) with whom I can easily connect with 2 GWs from the neighborhood (that one included).

Here is the serial monitor when it connects. The board’s display remains stuck on “JOINING”.
The OTAA keys are the same as the registered device on TTN.

Copyright @2019-2020 Heltec Automation.All rights reserved.

AT Rev 1.3

+AutoLPM=1

+LORAWAN=1

+KeepNet=0

+OTAA=1

+Class=A

+ADR=1

+IsTxConfirmed=1

+AppPort=2

+DutyCycle=120000

+ConfirmedNbTrials=4

+ChMask=0000000000000000000000FF

+DevEui=...(For OTAA Mode)

+AppEui=....(For OTAA Mode)

+AppKey=...(For OTAA Mode)

+NwkSKey=00000000000000000000000000000000(For ABP Mode)

+AppSKey=00000000000000000000000000000000(For ABP Mode)

+DevAddr=00000000(For ABP Mode)

Format logs with the </> tool please

And check the entire of a response for all the questions because you’ve missed the most important info - the serial log with all the redacted info is of little value.

TTN: in my end device section (Live data) I see nothing, no activity registered.
On Arduino IDE serial monitor I see the logs posted above. The first thing to show is authentification keys and parameters, then it remains stuck in a loop like this

TX on freq 868300000 Hz at DR 5
Event : Tx Done
RX on freq 868300000 Hz at DR 5
Event : Rx Timeout
RX on freq 869525000 Hz at DR 0
Event : Rx Timeout
TX on freq 868300000 Hz at DR 5
TX on freq 868300000 Hz at DR 5
Event : Tx Done
RX on freq 868300000 Hz at DR 5
Event : Rx Timeout

The usual issue (forum search for the win), is that the device & gateway are too close and the gateway output is overloading the devices input stage - so you need 5m & a brick wall between them.

Another simple quick check is EUI’s aren’t as expected so worth making sure they match and they are the correct way round (endian).

Ideally check in the gateway logs to see if the device is actually managing to get some RF as no point fixing credentials if the RF isn’t arriving at a gateway. And check the gateway console to see if it is getting to the servers.

What do you see in the console when it connects? The console is the bit in your application on the TTN website, where you can see the device metrics.

You have not excluded the device antenna yet. That is why what you see in the console, both gateway and application can lead to clue why it only connects when it is close to the gateway.

There is no problem with the distance between the end device and the gateway. I have tested the connection in many ways: outside the building with the gateway and in a range of 0 - 2 km. It connects to the TTN and the gateway can see the end device only if they’re both in the same room.

The DevEUI and AppKey are generated by TTN and match the ones from the end device code. The AppEUI is set to 0000000000000000 and matches as well.

I can’t see anything from my end device in the gateway logs when I am not in the same room with it. The gateway is working correctly, it received RF from my other board and others from the neighborhood too.

We are going in circles here.

Show the console log (json) when the node is connected to the gateway.

And what distance is between the gateway and node?

The device antenna is either not attached, unplugged, has a mismatch in SMA connectors - Female to RP Female for instance or is damaged.

As for all 00’s on the JoinEUI, different code bases cope with varying levels of success with this as an option, it is useful to use an EUI generator to create one rather than leave it all 00’s

Around 5m when I’m in the same room and can connect. These are the first two uplink messages when is connected to the gateway.

{
  "name": "gs.up.receive",
  "time": "2023-03-28T13:46:06.336488795Z",
  "identifiers": [
    {
      "gateway_ids": {
        "gateway_id": "ttnd35"
      }
    }
  ],
  "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.GatewayUplinkMessage",
    "message": {
      "raw_payload": "AAAAAAAAAAAA3L4F0H7Vs3BQ1M195uc=",
      "payload": {
        "m_hdr": {},
        "mic": "zX3m5w==",
        "join_request_payload": {
          "join_eui": "0000000000000000",
          "dev_eui": "70B3D57ED005BEDC",
          "dev_nonce": "D450"
        }
      },
      "settings": {
        "data_rate": {
          "lora": {
            "bandwidth": 125000,
            "spreading_factor": 7,
            "coding_rate": "4/5"
          }
        },
        "frequency": "868100000",
        "timestamp": 892869875
      },
      "rx_metadata": [
        {
          "gateway_ids": {
            "gateway_id": "ttnd35"
          },
          "time": "2023-03-28T13:46:06Z",
          "timestamp": 892869875,
          "rssi": -99,
          "channel_rssi": -99,
          "snr": 9,
          "location": {
            "latitude": 44.435032291883,
            "longitude": 26.0477524995804,
            "altitude": 110,
            "source": "SOURCE_REGISTRY"
          },
          "uplink_token": "CgoKCAoGdHRuZDM1EPO54KkDGgwInt+LoQYQt8evoAEguKrEmf6WAQ==",
          "received_at": "2023-03-28T13:46:06.336323511Z"
        }
      ],
      "received_at": "2023-03-28T13:46:06.336323511Z",
      "correlation_ids": [
        "gs:conn:01GWM6DQN128ZDT878Z15A84SC",
        "gs:uplink:01GWM7G0M0F4BQ9JMJW8TY5YE3"
      ]
    },
    "band_id": "EU_863_870"
  },
  "correlation_ids": [
    "gs:conn:01GWM6DQN128ZDT878Z15A84SC",
    "gs:uplink:01GWM7G0M0F4BQ9JMJW8TY5YE3"
  ],
  "origin": "ip-10-100-6-190.eu-west-1.compute.internal",
  "context": {
    "tenant-id": "CgN0dG4="
  },
  "visibility": {
    "rights": [
      "RIGHT_GATEWAY_TRAFFIC_READ"
    ]
  },
  "unique_id": "01GWM7G0M0R5DC8QWHFPJ9V1NT"
}








{
  "name": "gs.up.receive",
  "time": "2023-03-28T13:48:16.976996954Z",
  "identifiers": [
    {
      "gateway_ids": {
        "gateway_id": "ttnd35"
      }
    }
  ],
  "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.GatewayUplinkMessage",
    "message": {
      "raw_payload": "gHy1CyYAAAACpqiPT1+nL7OywPKtwbDTZdncN66hBBkmL850QWSt",
      "payload": {
        "m_hdr": {
          "m_type": "CONFIRMED_UP"
        },
        "mic": "dEFkrQ==",
        "mac_payload": {
          "f_hdr": {
            "dev_addr": "260BB57C",
            "f_ctrl": {}
          },
          "f_port": 2,
          "frm_payload": "pqiPT1+nL7OywPKtwbDTZdncN66hBBkmL84="
        }
      },
      "settings": {
        "data_rate": {
          "lora": {
            "bandwidth": 125000,
            "spreading_factor": 7,
            "coding_rate": "4/5"
          }
        },
        "frequency": "867700000",
        "timestamp": 1023590644
      },
      "rx_metadata": [
        {
          "gateway_ids": {
            "gateway_id": "ttnd35"
          },
          "time": "2023-03-28T13:48:17Z",
          "timestamp": 1023590644,
          "rssi": -103,
          "channel_rssi": -103,
          "snr": -3,
          "location": {
            "latitude": 44.435032291883,
            "longitude": 26.0477524995804,
            "altitude": 110,
            "source": "SOURCE_REGISTRY"
          },
          "uplink_token": "CgoKCAoGdHRuZDM1EPSBi+gDGgwIoOCLoQYQ+Ybn0QMgoPKGluWaAQ==",
          "received_at": "2023-03-28T13:48:16.976864121Z"
        }
      ],
      "received_at": "2023-03-28T13:48:16.976864121Z",
      "correlation_ids": [
        "gs:conn:01GWM6DQN128ZDT878Z15A84SC",
        "gs:uplink:01GWM7M06G7CW3HBE1JTHRAX4G"
      ]
    },
    "band_id": "EU_863_870"
  },
  "correlation_ids": [
    "gs:conn:01GWM6DQN128ZDT878Z15A84SC",
    "gs:uplink:01GWM7M06G7CW3HBE1JTHRAX4G"
  ],
  "origin": "ip-10-100-6-190.eu-west-1.compute.internal",
  "context": {
    "tenant-id": "CgN0dG4="
  },
  "visibility": {
    "rights": [
      "RIGHT_GATEWAY_TRAFFIC_READ"
    ]
  },
  "unique_id": "01GWM7M06GVYXG8DXVXF573HSA"
}






If in the same room per prior posts this is indicative of disconnected Antenna at one end or the other -possibly both!

1 Like

If your antennas were correct this should be -40 or so, look carefully at the antennas.

Pay attention to the connectors, they need to match male to female. The center pins can be tricky.

The antenna could also be broken inside.

Swap the antennas out if you cant see anything wrong.