arduino-libraries / MKRWAN

An Arduino library for sending and receiving data using LoRaWAN protocol and LoRa® radios.
https://www.arduino.cc
GNU Lesser General Public License v3.0
82 stars 60 forks source link

Does this library really support US915? #100

Open MichaelBla opened 2 years ago

MichaelBla commented 2 years ago

I can't get this to connect in the US although I can see it try in my gateway.

I can't find anyone else having success with this in the US so I wonder if it has been tested here.

terryzar commented 2 years ago

It does work in US915. Besides, your gateway sees it, ensure the keys are set exactly the same on both ends and both are configured for the same joining method (OTA or ABP). For joining, use US915_HYBRID, not just US915. Now the sensor will transmit on LoRa channels 1 through 8 instead of all 64 channels (your gateway likely does not support all 64 channels). We are using a Multtitech Conduit Gateway so we also set the ADR mode to 0 and dataRate to 0.

MichaelBla commented 2 years ago

Changed to US915_HYBRID. The activation is OTAA on both ends. LoRaWAN Version is MAC V1.0.2. Got one successful connection this morning and then repeated failures. The only successful connection used PHY V1.0.2 REV A but later tried PHY V1.0.2 REV B but that didn't help. Using US 902-928 MHz, FSB 2. Frame counter width is 32 bit. Nothing set for RX2 Data Rate Index or RX2 Frequency. Two gateways in here. I have Vitron device that seems to use the gateway without problem.

On Wed, Aug 25, 2021 at 10:51 AM terryzar @.***> wrote:

It does work in US915. Besides, your gateway sees it, ensure the keys are set exactly the same on both ends and both are configured for the same joining method (OTA or ABP). For joining, use US915_HYBRID, not just US915. Now the sensor will transmit on LoRa channels 1 through 8 instead of all 64 channels (your gateway likely does not support all 64 channels). We are using a Multtitech Conduit Gateway so we also set the ADR mode to 0 and dataRate to 0.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/arduino-libraries/MKRWAN/issues/100#issuecomment-905573328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDJWN6K4XEXUESRCAIKSVTT6T7QXANCNFSM5CXW6NDA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

hpssjellis commented 2 years ago

I am having success with the Helium network in North America using the new MKRWAN feature on the Portenta where you can enable channels:

For TTN I think you have to enable the "0" channel, can someone check:

  modem.disableChannel(0);
  modem.enableChannel(1);    // only one enabled for Helium

Demo program here

Here is the code I am using:

/*
  Helium Send And Receive
  This sketch demonstrates how to send and receive data with the MKR WAN 1300/1310 LoRa module.
  This example code is in the public domain.
  note: Helium must be setup for what it does with the CayenneLPP encoded data
*/

#include <MKRWAN.h>
#include <CayenneLPP.h>

LoRaModem modem;
CayenneLPP lpp(51);
bool connected = false;

// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// Note: Best to have the App_Device hard coded. Run the program once to see the value.
//#include "arduino_secrets.h"
#define SECRET_APP_EUI "0000000000000000"
#define SECRET_APP_KEY "0000000000000000000000000000000"

String appEui = SECRET_APP_EUI;   // just strings of the above 
String appKey = SECRET_APP_KEY;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(LEDR,OUTPUT);
  pinMode(LEDG,OUTPUT);
  pinMode(LEDB,OUTPUT);
  digitalWrite(LEDR, HIGH); // new boards HIGH = off
  digitalWrite(LEDG, LOW);
  digitalWrite(LEDB, HIGH);

  //while (!Serial);       // don't wait for serial

  Serial.println("Wait 4");
  delay(3000);             // delay instead, so it works when disconnected
  digitalWrite(LEDG, HIGH);// allows time to connect serial monitor

  Serial.println("Wait 3");
  delay(3000);       
  digitalWrite(LEDG, LOW);

  Serial.println("Wait 2");
  delay(3000);       
  digitalWrite(LEDG, HIGH);

  Serial.println("Wait 1");
  delay(3000);       
  digitalWrite(LEDG, LOW);

  // 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());

  myPrintMask();
  delay(3000);
  Serial.println("Now Disabling all channels and enable channel 1 only for Helium ");

  modem.disableChannel(0);
  modem.enableChannel(1);    // only one enabled for Helium
  modem.disableChannel(2);
  modem.disableChannel(3);
  modem.disableChannel(4);
  modem.disableChannel(5);
  modem.disableChannel(6);
  myPrintMask(); 
  delay(3000);
  myPrintMask();
  Serial.println("Now Joining the Helium Network ");
}

void loop() {

  while (!connected) {
    Serial.println("trying to reconnect");
    digitalWrite(LEDR, LOW); // new boards HIGH = off
    digitalWrite(LEDG, LOW);
    digitalWrite(LEDB, HIGH);
    connected = modem.joinOTAA(appEui, appKey);
    delay(5000);    
    digitalWrite(LEDR, HIGH); // new boards HIGH = off
    digitalWrite(LEDG, LOW);
    digitalWrite(LEDB, HIGH);
    delay(1000);
  }

  lpp.reset();
  float x = rand() / 10000000.0; //analogRead(A0)
  lpp.addTemperature(1, x); 

  /*
  // Can do any of these
  lpp.reset();
  lpp.addDigitalInput(1, 0);
  lpp.addDigitalOutput(2, 1);
  lpp.addAnalogInput(3, 1.23f);
  lpp.addAnalogOutput(4, 3.45f);
  lpp.addLuminosity(5, 20304);
  lpp.addPresence(6, 1);
  lpp.addTemperature(7, 26.5f);
  lpp.addRelativeHumidity(8, 86.6f);
  lpp.addAccelerometer(9, 1.234f, -1.234f, 0.567f);
  lpp.addBarometricPressure(10, 1023.4f);
  lpp.addGyrometer(1, -12.34f, 45.56f, 89.01f);
  lpp.addGPS(1, -12.34f, 45.56f, 9.01f);

  lpp.addUnixTime(1, 135005160);

  lpp.addGenericSensor(1, 4294967295);
  lpp.addVoltage(1, 3.35);
  lpp.addCurrent(1, 0.321);
  lpp.addFrequency(1, 50);
  lpp.addPercentage(1, 100);
  lpp.addAltitude(1 , 50);
  lpp.addPower(1 , 50000);
  lpp.addDistance(1 , 10.555);
  lpp.addEnergy(1 , 19.055);
  lpp.addDirection(1 , 90);
  lpp.addSwitch(1 , 0);

  lpp.addConcentration(1 , 512);
  lpp.addColour(1 , 64, 128, 255);

  */

  Serial.println();
  Serial.println("Sending:" + String(x, 1));

  Serial.println();

  int err;
  modem.beginPacket();
  modem.write(lpp.getBuffer(), lpp.getSize());
  err = modem.endPacket(true);
  if (err > 0) {
    Serial.println("Message sent correctly!");
    digitalWrite(LEDR, HIGH); // new boards HIGH = off
    digitalWrite(LEDG, HIGH);
    digitalWrite(LEDB, HIGH);
  } 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)");
    digitalWrite(LEDR, LOW); // new boards HIGH = off
    digitalWrite(LEDG, HIGH);
    digitalWrite(LEDB, LOW);
  }
  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();
  digitalWrite(LEDR, HIGH); // new boards HIGH = off
  digitalWrite(LEDG, HIGH);
  digitalWrite(LEDB, LOW);
  delay(30000);  // delay 30 seconds for testing
}

void myPrintMask(){ 
  delay(30);
  Serial.println("Your module version is: " + String(modem.version()) ); 
  delay(30);
  Serial.println("getDataRate: " + String(modem.getDataRate()) );
  delay(30);
  Serial.println("getADR: " + String(modem.getADR()) );
  Serial.println("getRX2Freq: " + String(modem.getRX2Freq()) );
  Serial.println("getRX2DR(): " + String(modem.getRX2DR()) );

  Serial.println("getFCU: " + String(modem.getFCU()) );
  Serial.println("getFCD: " + String(modem.getFCD()) );
  delay(30);
  Serial.println("getChannelMask: " + String(modem.getChannelMask()));
  delay(30);

  Serial.println("isChannelEnabled(0): " + String(modem.isChannelEnabled(0)));
  delay(30);
  Serial.println("isChannelEnabled(1): " + String(modem.isChannelEnabled(1)));
  delay(30);
  Serial.println("isChannelEnabled(2): " + String(modem.isChannelEnabled(2)));
  delay(30);
  Serial.println("isChannelEnabled(3): " + String(modem.isChannelEnabled(3)));
  delay(30);
  Serial.println("isChannelEnabled(4): " + String(modem.isChannelEnabled(4)));
  delay(30);
  Serial.println("isChannelEnabled(5): " + String(modem.isChannelEnabled(5)));
  delay(30);
  Serial.println("isChannelEnabled(6): " + String(modem.isChannelEnabled(6)));
  delay(30);
  Serial.println("-------------------------------");
}
MichaelBla commented 2 years ago

That worked!

In that I saw my first payload, ever. I was using US915 and enabled channel 0 and disabled channel 1.

I'll have to go through your code and figure out what it was trying to send and if my decoded payload of "\u0001g\u0003!" is meaningful.

Sorry, I'm obviously new to this and having never received a payload before I don't have any experience handling it.

I didn't wire-up any LEDs. I just assigned them to outputs 4-6.

Thanks! I finally feel like I have a foot in the door.

Michael

On Mon, Aug 30, 2021 at 1:44 AM Jeremy Ellis @.***> wrote:

I am having success with the Helium network in North America using the new MKRWAN feature on the Portenta where you can enable channels:

For TTN I think you have to enable the "0" channel, can someone check: ''' modem.disableChannel(0); modem.enableChannel(1); // only one enabled for Helium '''

Demo program here https://github.com/hpssjellis/portenta-pro-community-solutions/blob/main/examples/c-portenta-vision-shields/c-b-lorawan-specific/c-b-b-helium-cayenne-us915/c-b-b-helium-cayenne-us915.ino

Here is the code I am using:

/ Helium Send And Receive This sketch demonstrates how to send and receive data with the MKR WAN 1300/1310 LoRa module. This example code is in the public domain. note: Helium must be setup for what it does with the CayenneLPP encoded data /

include

include

LoRaModem modem; CayenneLPP lpp(51); bool connected = false;

// Please enter your sensitive data in the Secret tab or arduino_secrets.h // Note: Best to have the App_Device hard coded. Run the program once to see the value. //#include "arduino_secrets.h"

define SECRET_APP_EUI "0000000000000000"

define SECRET_APP_KEY "0000000000000000000000000000000"

String appEui = SECRET_APP_EUI; // just strings of the above String appKey = SECRET_APP_KEY;

void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(LEDR,OUTPUT); pinMode(LEDG,OUTPUT); pinMode(LEDB,OUTPUT); digitalWrite(LEDR, HIGH); // new boards HIGH = off digitalWrite(LEDG, LOW); digitalWrite(LEDB, HIGH);

//while (!Serial); // don't wait for serial

Serial.println("Wait 4"); delay(3000); // delay instead, so it works when disconnected digitalWrite(LEDG, HIGH);// allows time to connect serial monitor

Serial.println("Wait 3"); delay(3000); digitalWrite(LEDG, LOW);

Serial.println("Wait 2"); delay(3000); digitalWrite(LEDG, HIGH);

Serial.println("Wait 1"); delay(3000); digitalWrite(LEDG, LOW);

// 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());

myPrintMask(); delay(3000); Serial.println("Now Disabling all channels and enable channel 1 only for Helium ");

modem.disableChannel(0); modem.enableChannel(1); // only one enabled for Helium modem.disableChannel(2); modem.disableChannel(3); modem.disableChannel(4); modem.disableChannel(5); modem.disableChannel(6); myPrintMask(); delay(3000); myPrintMask(); Serial.println("Now Joining the Helium Network ");

}

void loop() {

while (!connected) { Serial.println("trying to reconnect"); digitalWrite(LEDR, LOW); // new boards HIGH = off digitalWrite(LEDG, LOW); digitalWrite(LEDB, HIGH); connected = modem.joinOTAA(appEui, appKey); delay(5000); digitalWrite(LEDR, HIGH); // new boards HIGH = off digitalWrite(LEDG, LOW); digitalWrite(LEDB, HIGH); delay(1000); }

lpp.reset(); float x = rand() / 10000000.0; //analogRead(A0) lpp.addTemperature(1, x);

/* // Can do any of these lpp.reset(); lpp.addDigitalInput(1, 0); lpp.addDigitalOutput(2, 1); lpp.addAnalogInput(3, 1.23f); lpp.addAnalogOutput(4, 3.45f); lpp.addLuminosity(5, 20304); lpp.addPresence(6, 1); lpp.addTemperature(7, 26.5f); lpp.addRelativeHumidity(8, 86.6f); lpp.addAccelerometer(9, 1.234f, -1.234f, 0.567f); lpp.addBarometricPressure(10, 1023.4f); lpp.addGyrometer(1, -12.34f, 45.56f, 89.01f); lpp.addGPS(1, -12.34f, 45.56f, 9.01f);

lpp.addUnixTime(1, 135005160);

lpp.addGenericSensor(1, 4294967295); lpp.addVoltage(1, 3.35); lpp.addCurrent(1, 0.321); lpp.addFrequency(1, 50); lpp.addPercentage(1, 100); lpp.addAltitude(1 , 50); lpp.addPower(1 , 50000); lpp.addDistance(1 , 10.555); lpp.addEnergy(1 , 19.055); lpp.addDirection(1 , 90); lpp.addSwitch(1 , 0);

lpp.addConcentration(1 , 512); lpp.addColour(1 , 64, 128, 255);

*/

Serial.println(); Serial.println("Sending:" + String(x, 1));

Serial.println();

int err; modem.beginPacket(); modem.write(lpp.getBuffer(), lpp.getSize()); err = modem.endPacket(true); if (err > 0) { Serial.println("Message sent correctly!"); digitalWrite(LEDR, HIGH); // new boards HIGH = off digitalWrite(LEDG, HIGH); digitalWrite(LEDB, HIGH); } 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)"); digitalWrite(LEDR, LOW); // new boards HIGH = off digitalWrite(LEDG, HIGH); digitalWrite(LEDB, LOW); } 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(); digitalWrite(LEDR, HIGH); // new boards HIGH = off digitalWrite(LEDG, HIGH); digitalWrite(LEDB, LOW); delay(30000); // delay 30 seconds for testing }

void myPrintMask(){

delay(30); Serial.println("Your module version is: " + String(modem.version()) ); delay(30); Serial.println("getDataRate: " + String(modem.getDataRate()) ); delay(30); Serial.println("getADR: " + String(modem.getADR()) ); Serial.println("getRX2Freq: " + String(modem.getRX2Freq()) ); Serial.println("getRX2DR(): " + String(modem.getRX2DR()) );

Serial.println("getFCU: " + String(modem.getFCU()) ); Serial.println("getFCD: " + String(modem.getFCD()) ); delay(30); Serial.println("getChannelMask: " + String(modem.getChannelMask())); delay(30);

Serial.println("isChannelEnabled(0): " + String(modem.isChannelEnabled(0))); delay(30); Serial.println("isChannelEnabled(1): " + String(modem.isChannelEnabled(1))); delay(30); Serial.println("isChannelEnabled(2): " + String(modem.isChannelEnabled(2))); delay(30); Serial.println("isChannelEnabled(3): " + String(modem.isChannelEnabled(3))); delay(30); Serial.println("isChannelEnabled(4): " + String(modem.isChannelEnabled(4))); delay(30); Serial.println("isChannelEnabled(5): " + String(modem.isChannelEnabled(5))); delay(30); Serial.println("isChannelEnabled(6): " + String(modem.isChannelEnabled(6))); delay(30); Serial.println("-------------------------------"); }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/arduino-libraries/MKRWAN/issues/100#issuecomment-908047060, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDJWN6TDZQ2DZYJA7JAE23T7MLFVANCNFSM5CXW6NDA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

hpssjellis commented 2 years ago

@MichaelBla Glad I could help,