Go Down

Topic: MKR 1310 - cannot send more than 1 msg (Read 2223 times) previous topic - next topic


Hello I have copy/pasted the sample code from the documentation and even by delaying 3mn between 2 messages I always have a sending error. I can send again by rebooting the board.
Must be something obvious...
Thanks for your help

#include <MKRWAN.h>

LoRaModem modem;

// Uncomment if using the Murata chip as a module
// LoRaModem modem(Serial1);

const int PIN_SEUIL = 2;
const int PIN_VALEUR = A1;

static unsigned long time = 0;
const unsigned long SAMPLE_PERIOD = 30000;
const unsigned long SENDING_PERIOD = 180000;

#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
String appEui = SECRET_APP_EUI;
String appKey = SECRET_APP_KEY;

void setup() {
  pinMode(PIN_SEUIL, INPUT);    // sets the digital pin PIN_SEUIL as input
  // put your setup code here, to run once:
  while (!Serial);
  // change this to your regional band (eg. US915, AS923, ...)
  if (!modem.begin(EU868)) {
    Serial.println("Failed to start module");
    while (1) {}
  Serial.print("Your module version is: ");
  Serial.print("Your device EUI is: ");

  int connected = modem.joinOTAA(appEui, appKey);
  if (!connected) {
    Serial.println("Something went wrong; are you indoor? Move near a window and retry");
    while (1) {}

  // Set poll interval to 60 secs.
  // NOTE: independently by this setting the modem will
  // not allow to send more than one message every 2 minutes,
  // this is enforced by firmware and can not be changed.

void loop() {
  int humidite = 0;
  int seuil = 0;
  char buf[10];

  // Lecture du PIN Analogique
  humidite = analogRead(PIN_VALEUR); 
  Serial.print("Lecture Analogique = ");
  Serial.println(humidite);     // La valeur analogique brute

  sprintf(buf, "%04d", humidite);
  Serial.print("time ");

  if (time == 0 || millis() - time > SENDING_PERIOD)
    int err;

    time = millis();

    modem.write(buf, 4);
    err = modem.endPacket(true);
    if (err > 0) {
      Serial.println("Message sent correctly!");
    } else {
      Serial.println("Error sending message :(");
      Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength");
      Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)");



In fact if you increase the sending delay from 3mn to 5mn it works !!!

Go Up