Code Monkey home page Code Monkey logo

Comments (5)

hpssjellis avatar hpssjellis commented on September 22, 2024 1

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("-------------------------------");
}

from mkrwan.

terryzar avatar terryzar commented on September 22, 2024

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.

from mkrwan.

MichaelBla avatar MichaelBla commented on September 22, 2024

from mkrwan.

MichaelBla avatar MichaelBla commented on September 22, 2024

from mkrwan.

hpssjellis avatar hpssjellis commented on September 22, 2024

@MichaelBla Glad I could help,

from mkrwan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.