I am a beginner in doing LoRa projects and using TTN and would really appreciate any help I can get.
I am trying to connect my device to TTN. Despite various attempts to, I am still failing. I am using an Arduino MKR WAN 1300 board together with a DHT11 Temperature & Humidity Sensor connecting to a public gateway. At this point, I am able to connect to the gateway but I get stuck at this point where nothing happens beyond this.
I have read some forums which directed me to look into the duty cycles and network limitations but those are parameters that I am unable to modify or even look at. Thank you in advance for any help.
Your problem doesn’t seem to have anything to do with downlink messages.
Rather, it looks like the firmware’s duty cycle accounting is blocking transmission. The possibility of a downlink would exist only after the uplink is sent, and it appears no uplinks are being sent after the join/accept cycle.
Oh I see. I have reached this part many times before but it doesnt allow me to progress beyond this. Below is the code I am using.
#include <MKRWAN.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht (DHTPIN,DHTTYPE);
LoRaModem modem;
//#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
String appEui = "0000000000000000";
String appKey = "****";
void setup()
{
Serial.begin(9600);
while(!Serial);
dht.begin();
pinMode(LED_BUILTIN, OUTPUT); //check if board is receiving
for (int i=1; i<=5; i++) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
// wait for a second
Serial.println(5-i);
}
// change this to your regional band (eg. US915, AS923, ...)
if (!modem.begin(AU915)) {
Serial.println("Failed to start module");
while (1) {}
};
delay(5000);
Serial.print("Your module version is: ");
Serial.println(modem.version());
Serial.print("Your device EUI is: ");
Serial.println(modem.deviceEUI());
modem.sendMask("ff000000f000ffff00020000");
Serial.println(modem.getChannelMask());
modem.setADR(true);
join();
modem.minPollInterval(30);
}
void join(){
Serial.println("Trying to join TTN ...");
int connected = modem.joinOTAA(appEui, appKey);
if (!connected) {
Serial.println("Something went wrong; are you indoor? Move near a window and retry");
join();
}
else
Serial.println("Successfully joined"); // 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()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h)||isnan(t)||isnan(f)){
Serial.println(F("Fail to read sensor"));
float hif = dht.computeHeatIndex(f,h);
float hic = dht.computeHeatIndex(t,h,false);
return;
}
int err;
modem.beginPacket();
err = modem.endPacket(true);
modem.write(t);
Serial.println("Packet Sent.Sending Temperature");
if (err > 0) {
Serial.println("Message sent correctly!");
// Serial.print(F(" Humidity: "));
// Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
// Serial.print(F("Celcius "));
// Serial.print(f);
// Serial.print(F(" Heat Index: "));
// Serial.print(hic);
// Serial.print(F("Celcius "));
// Serial.print(hif);
// Serial.println(F("Farenheit "));
} 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.");
}
else {
String rcv;
rcv.reserve(64);
while (modem.available()) {
rcv += (char)modem.read();
}
Serial.print("Received: " + rcv + " - ");
for (unsigned int i = 0; i < rcv.length(); i++) {
Serial.print(rcv[i] >> 4, HEX);
Serial.print(rcv[i] & 0xF, HEX);
Serial.print(" ");
}
Serial.println();
}
Serial.println("waiting 60 seconds");
delay(60000);
}