open-electronics / LoRa

LoRa library for Arduino
32 stars 13 forks source link

Error on LR.sendMess() #6

Closed LasaleFamine closed 6 years ago

LasaleFamine commented 6 years ago

Hi and firstly thank you for this awesome library.

I'm trying to test the LoRa shield with a simple sketch got from an example. Basically I'm getting always a -1 from the LR.sendMess() within the sendBuff() function, but I'm not understanding why. Is there any specific thing I can check for finding the problem?

Thank you in advance!

The case is the follow:


#include <LORA.h>
#include <SPI.h>

#define led 8

#define MESS "Simple echo test"

#define RXTIMEOUT 500

LORA LR;

#define inplen 64
#define reclen 64
char inpbuff[inplen];
char recbuff[reclen];

char data[64];
#define format "|RSSI: %d RSSIpk: %d SNRpk %d|  "

int SF = 9;
int BW = 6;

int PWR = 2;

boolean SHIELD = true;

void setup() {
  digitalWrite(led, 0);
  pinMode(led, OUTPUT);

  Serial.begin(9600);

  if (!LR.begin()) {
    Serial.println("No LoRa! STOP");
    SHIELD = false;
    return; 
  }

  Serial.println("LoRa running");

  SX.setPower(PWR);
  LR.setConfig(SF, BW, 4);

  showConfig();

  strlcpy(inpbuff, MESS, inplen);

  Serial.println("Send S for sending the message");
}

void loop() {
  delay(2000);
  if (!SHIELD) {
    return;
  }

  if(getInput()) {
    sendBuff();
  }
}

void sendBuff() {
  Serial.print("> ");
  Serial.println(inpbuff);

  int f = LR.sendMess(inpbuff);
  Serial.print("Status: ");
  Serial.println(f);
  if (f < 0) {
    Serial.println("ERROR: Error in transmission.");
  }

  SX.setState(STDBY);
}

void showConfig() {
  Serial.print("Replay timeout (milliseconds): ");
  Serial.println(RXTIMEOUT*10);
  Serial.print("Freq: ");
  Serial.println(SX.readFreq());
  Serial.print("PT (mW): ");
  Serial.println(SX.getPower(3));
  Serial.print("Preamble bytes: ");
  Serial.print(SX.getLoraPreambleLen());
  Serial.println("+4");
  snprintf(data, 63, "SpFactor: %d BandW: %d Cr: %d", SX.getLoraSprFactor(), SX.getLoraBw(), SX.getLoraCr());
  Serial.println(data);
  Serial.print("Rate (byte/sec): ");
  Serial.println(SX.getSRate());
}

boolean getInput() {
  if (Serial.available()) {
    char ch = Serial.read();
    if (ch == 'S') {
      return true;
    }
  }

  return false;
}
danieledenaro commented 6 years ago

Please tell me if transmission occurs in any case. Have you tried to use any other example not modified?

LasaleFamine commented 6 years ago

Hi @danieledenaro, thank you for your response.

It turns out that for some reason the cause was a missing connected pin for the led. Actually I don't know why this was problematic for the board, but at the end now it returns 0.

Now I think I have a problem on receiving using LR.dataRead() method on the other Arduino (with another LoRa shield). It always returns -1 like the sendMess() before (of course I'm using this script above posted on the issue for sending the message). I don't have the source code with me right now, but maybe it's better to open another issue for this.

Thank you anyway!