Hello,
I'm trying to send data from the MKR WAN 1300 to Thing Park. I can successfully connect via OTAA to the network.
As long as the data stays below 10 bytes everything works fine, but as soon as I try to transmit something larger the network receives empty packets.
With a lot of experimentation I was able to figure out a pattern and this is what I have to do to make it work:
[up] Join request sent
[down] Join accepted
[up] Send <10 byte packet
[down] Receive a MAC request
[up] Send a <10 byte packet (and automatically respond to the MAC)
[down] Receive confirmation
[up] Send a >10 byte packet. There will be 4 errors where empty packets are sent (a modem.endPacket(true) size <0) then the network will send a MAC request. Even though the data is never transmitted this seems to satisfy the MKR that it was received.
[down] Receive the above mentioned MAC request.
[up] Send a >10 byte packet (and automatically respond to the MAC)
[down] Receive confirmation
Only after all that is done can I send packets over 10 bytes reliably. I don't believe this is a problem with the network because other off the shelf products I've connected, such as a GPS and a temperature sensor, have no problem sending large amounts of data immediately after joining.
This can't be the proper way to handle this, does anyone have some suggestions? I saw this post which looks like a very similar problem, but it was apparently solved by not asking for responses. I tried that and it did not solve my issue. I'm using firmware version ARD-078 1.1.9.
I have this issue with all sketches, even the example ones, and used the LoraSendAndReceive example to figure out the above pattern:
/*
Lora Send And Receive
This sketch demonstrates how to send and receive data with the MKR WAN 1300 LoRa module.
This example code is in the public domain.
*/
#include <MKRWAN.h>
LoRaModem modem;
// Uncomment if using the Murata chip as a module
// LoRaModem modem(Serial1);
#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() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial);
// change this to your regional band (eg. US915, AS923, ...)
if (!modem.begin(US915)) {
Serial.println("Failed to start module");
while (1) {}
};
Serial.print("Your module version is: ");
Serial.println(modem.version());
Serial.print("Your device EUI is: ");
Serial.println(modem.deviceEUI());
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.
modem.minPollInterval(60);
// 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() {
Serial.println();
Serial.println("Enter a message to send to network");
Serial.println("(make sure that end-of-line 'NL' is enabled)");
while (!Serial.available());
String msg = Serial.readStringUntil('\n');
Serial.println();
Serial.print("Sending: " + msg + " - ");
for (unsigned int i = 0; i < msg.length(); i++) {
Serial.print(msg[i] >> 4, HEX);
Serial.print(msg[i] & 0xF, HEX);
Serial.print(" ");
}
Serial.println();
int err;
modem.beginPacket();
modem.print(msg);
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)");
}
delay(1000);
if (!modem.available()) {
Serial.println("No downlink message received at this time.");
return;
}
char rcv[64];
int i = 0;
while (modem.available()) {
rcv[i++] = (char)modem.read();
}
Serial.print("Received: ");
for (unsigned int j = 0; j < i; j++) {
Serial.print(rcv[j] >> 4, HEX);
Serial.print(rcv[j] & 0xF, HEX);
Serial.print(" ");
}
Serial.println();
}