Skip to content

0.0.7 last working version with LoraWAN and HTCC-AB01 #195

@nmaas87

Description

@nmaas87

I got 2 HTCC-AB01 868 MHz and my own TTN / Chirpstack Gateway (depending on switching SDcard :) ) - for quite a long time I have been trying to get both modules working, however, like said in #107 - with 1.3.0 and 1.2.0 - most of the time my board only does authenticate with TTN, but does not work further - or lose a lot of packets (never receiving the gateway, even though very close to it - on another table). I went down with the LoraWAN example all versions until i reached stable service.

All the other versions never worked.
How can I fix that?
Are both modules defective and should be given back?

Working settings and code as follows:
CubeCell Version 0.0.7 - everything above and it will break - code will compile, but most the thing will do is activated on TTN and then nothing will happen....

Region REGION_EU868
Class_A
Netmode: OTAA
ADR: ON
Uplinkmode: Unconfirmed
Net_Res: OFF
AT_SUPPORT: OFF
RGB_DEACT

#include <LoRaWan_APP.h>
#include <Arduino.h>

/*
Code from: https://github.com/LukePrior/TTN-BME280-Weather-Station-Heltec-CubeCell-HTCC-AB01

function Decoder(bytes, port) {
  var temperature = bytes[0]<<24>>16 | bytes[1];
  var humidity = (bytes[2] << 8) | bytes[3];
  var pressure = ((bytes[4]) << 24) + ((bytes[5]) << 16) + ((bytes[6]) << 8) + ((bytes[7]));
  var battery = (bytes[8] << 8) | bytes[9];
  var battery_level = bytes[11];
  
  return {
    temperature: temperature / 100,
    humidity: humidity,
    pressure: pressure / 100,
    battery: battery / 1000,
    battery_level: battery_level
  }
}
*/

/* OTAA para*/
uint8_t devEui[] = { REDACTED }; //#Insert you Development EUI here as indivudal bytes replacing each XX pair
uint8_t appEui[] = { REDACTED }; //#Insert you Application EUI here as indivudal bytes replacing each XX pair
uint8_t appKey[] = { REDACTED }; //#Insert you Application Key here as indivudal bytes replacing each XX pair


/* ABP para*/

uint8_t nwkSKey[] = { REDACTED };
uint8_t appSKey[] = { REDACTED };
uint32_t devAddr =  ( uint32_t )REDACTED;


bool ENABLE_SERIAL = true; // enable serial debug output here if required
uint32_t appTxDutyCycle = 100000; // the frequency of readings, in milliseconds(set 100s)

uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 };
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;
DeviceClass_t  loraWanClass = LORAWAN_CLASS;
bool overTheAirActivation = LORAWAN_NETMODE;
bool loraWanAdr = LORAWAN_ADR;
bool keepNet = LORAWAN_NET_RESERVE;
bool isTxConfirmed = LORAWAN_UPLINKMODE;
uint8_t appPort = 2;
uint8_t confirmedNbTrials = 4;

int temperature, humidity, batteryVoltage, batteryLevel;
long pressure;

int counter = 0;

static void prepareTxFrame( uint8_t port )
{
  counter = counter + 1;

  temperature = counter;
  humidity = 0;
  pressure = 0;
  
  batteryVoltage = getBatteryVoltage();
  batteryLevel = (BoardGetBatteryLevel() / 254) * 100; 

  appDataSize = 12;
  appData[0] = highByte(temperature);
  appData[1] = lowByte(temperature);

  appData[2] = highByte(humidity);
  appData[3] = lowByte(humidity);

  appData[4] = (byte) ((pressure & 0xFF000000) >> 24 );
  appData[5] = (byte) ((pressure & 0x00FF0000) >> 16 );
  appData[6] = (byte) ((pressure & 0x0000FF00) >> 8  );
  appData[7] = (byte) ((pressure & 0X000000FF)       );

  appData[8] = highByte(batteryVoltage);
  appData[9] = lowByte(batteryVoltage);

  appData[10] = highByte(batteryLevel);
  appData[11] = lowByte(batteryLevel);

  if(ENABLE_SERIAL){
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.print(" mbar, Battery Voltage: ");
    Serial.print(batteryVoltage);
    Serial.print(" mV, Battery Level: ");
    Serial.print(batteryLevel);
    Serial.println(" %");
  }
}

void setup()
{
  
  boardInitMcu();
  if(ENABLE_SERIAL){
    Serial.begin(115200); 
  }
  deviceState = DEVICE_STATE_INIT;
  LoRaWAN.ifskipjoin();

}

void loop()
{
  switch( deviceState )
  {
    case DEVICE_STATE_INIT:
    {
      printDevParam();
      LoRaWAN.init(loraWanClass,loraWanRegion);
      deviceState = DEVICE_STATE_JOIN;
      break;
    }
    case DEVICE_STATE_JOIN:
    {
      LoRaWAN.join();
      break;
    }
    case DEVICE_STATE_SEND:
    {
      prepareTxFrame( appPort );
      LoRaWAN.send();
      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.sleep();
      break;
    }
    default:
    {
      deviceState = DEVICE_STATE_INIT;
      break;
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions