MKRWAN 1310 failed to send uplink to a LoRaWan gateway

I have a MKRWAN 1310 board equipped with an ADXL335 accelerometer and a LoRa gateway, both of them have been configured on TTN, and the MKR board has been set up as a 'thing' in Arduino Cloud, and the gateway functions well. The IoT sketch for the MKR board also compiled and uploaded successfully in Arduino cloud, however, when I checked the TTN console, the MKR board seems not sending uplinks to the gateway, could anyone please help me check the sketch? I would appreciate any suggestions very much.

#include "thingProperties.h"
#include "SHM.h"
//--------------------------------------------------------------
#define xPin A0
#define yPin A1
#define zPin A2
//--------------------------------------------------------------
//calibrated minimum and maximum Raw Ranges for each axis
//use calibration.ino file to get these values
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMM
int xMin = 615;
int xMax = 966;
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMM
int yMin = 620;
int yMax = 969;
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMM
int zMin = 638;
int zMax = 947;
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//--------------------------------------------------------------
// Take multiple samples to reduce noise
//static const uint16_t N = 512; //MUST BE EXP 2;
//--------------------------------------------------------------
static constexpr double G = 9.80665;           // Gravitational Constant
static const int f = 2;                        // Frequency Target
static const double sampleTime = (Ts * 1000);  //Sampling Period in Miliseconds
//Period for sampling
const long period = 10000;  //10 Sec
static const double EMA_Alpha_low = 0.61;
static const double EMA_Alpha_High = 0.81;

float zFreq = 0.0;
// PHASE SHIFT
//float zPhase = 0.0;
double zAccelArray[N] = { 0 };
double zAccelLPF[N] = { 0 };
double zAccelHPF[N] = { 0 };
double zAccelBP[N];
//Array's for imaginary components of FFT to prevent overflow.
double imagZ[N];
//---------------------------------------------------------

int i;
// Demonstration of soft bricking of native USB board caused by intializing array larger than available SRAM.
// Press and release the reset button on the board twice quickly and then upload a valid sketch to recover the board.
void setup() {
  //analogReference(EXTERNAL);
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);
  //volatile double foo[13 * 512] = {};  // volatile keyword used to prevent the unused array from being optimized away by compiler.
  //Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection,false);

  //Info About Connection (0 - 4) - Higher Number means more Information
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}


void loop() {
  ArduinoCloud.update();
  // Reset arrays
  memset(zAccelArray, 0, sizeof(zAccelArray));
  memset(zAccelLPF, 0, sizeof(zAccelLPF));
  memset(zAccelHPF, 0, sizeof(zAccelHPF));
  memset(zAccelBP, 0, sizeof(zAccelBP));
  memset(imagZ, 0, sizeof(imagZ));

  for (int i = 0; i < N; i++) {

    int zRaw = analogRead(zPin);
    //--------------------------------------------------------------
    //Convert raw values to 'milli-Gs"
    //Convert value of RawMin to -1000
    //Convert value of RawMax to 1000
    long zMilliG = map(zRaw, zMin, zMax, -1000, 1000);
    //--------------------------------------------------------------
    // re-scale to fractional Gs
    float z_g_value = zMilliG / 1000.0;
    //Converts G's to m/s/s
    double zAccel = (z_g_value - 1) * G;
    // Store values in arrays
    zAccelArray[i] = zAccel;
    zAccelLPF[i] = EMA_Alpha_low * zAccelArray[i] + (1 - EMA_Alpha_low) * zAccelLPF[i];
    zAccelHPF[i] = EMA_Alpha_High * zAccelLPF[i] + (1 - EMA_Alpha_High) * zAccelHPF[i];
    zAccelBP[i] = zAccelHPF[i] - zAccelLPF[i];

    imagZ[i] = 0.0;
    //Serial.print(zAccelBP[i]);
    //Serial.println("");
    //Delay between samples
    delay(Ts * 1000);
  }
  // Find maximum values among every 512 samples
  //double xAccelMax = findMaxAmongBlocks(xAccelBP, N, N);
  //double yAccelMax = findMaxAmongBlocks(yAccelBP, N, N);
  float zAccelMin = findMinAmongBlocks(zAccelBP, N, N);
  float zAccelMax = findMaxAmongBlocks(zAccelBP, N, N);
  //Determine Max Acceleration from sensor values.
  //xAccelMax = findMax(xAccelArray);
  //yAccelMax = findMax(yAccelArray);
  //zAccelMax = findMax(zAccelArray);

  //FFT Constructor For Z direction of Accelerometer
  arduinoFFT Z_FFT(zAccelBP, imagZ, N, Fs);

  //Remove DC Component Of the data.
  Z_FFT.DCRemoval();

  //Apply Hamming window to the data to improve resolution
  Z_FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD);

  //Compute the FFT of the data
  Z_FFT.Compute(FFT_FORWARD);

  //Find Maximum Frequency Of Data
  zFreq = float(Z_FFT.MajorPeak());

  //Serial.print("\t");
  Serial.print("zAccelMin: ");
  Serial.print(zAccelMin);
  Serial.print(" ");
  Serial.print("\t");
  Serial.print("zAccelMax: ");
  Serial.print(zAccelMax);
  Serial.print(" ");
  Serial.print("\t");
  Serial.print("Peak Freq: ");
  Serial.print(zFreq);
  Serial.println(" ");


  //Serial.println();  // Add a newline at the end for better formatting

  //Find Bin of Peak Frequency
  //int binZ = zFreq * N / Fs;

  //Check for NaN values in the frequency outputs.
  checkNan(zFreq);

  // Update Arduino IoT Cloud Variables
  
  
  AccelMaxZ = zAccelMax;
  AccelMinZ = zAccelMin;
  freqz = zFreq;
  //Delay between samples
  float start = millis();
  while ((millis() - start) < period);
  //;
}

I also found that when I open the 'Thing' page of this MKR board and go to 'sketch', sometimes it shows "No associated device found", this problem can be solved by double click the reset button of the board, but in some cases even though I could upload the sketch successfully, the serial monitor cannot open the device.

I figured this out for myself... in the properties file it has this:

LoRaConnectionHandler ArduinoIoTPreferredConnection(APPEUI, APPKEY, _lora_band::US915, "00000000000000000000FF00");

I had to remove the 4th parameter, and works perfectly.

LoRaConnectionHandler ArduinoIoTPreferredConnection(APPEUI, APPKEY, _lora_band::US915);

Thanks a lot sigoffice! I'll try this way

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.