LoRaWAN 02a: Channels EU or IN or ASIA-PAC / LATAM

This example shows how to configure the channels settings. There are 16 channels. The first three of them are always preconfigured and cannot be changed: 868.1 MHz, 868.3 MHz and 868.5 MHz. Besides other parameters can be changed in all channels: Duty Cycle, Data rate range and channel status

Required Materials

1 x Waspmote 1 x Battery 1 x LoRaWAN EU or LoRaWAN IN or LoRaWAN ASIA-PAC / LATAM module 1 x 868 MHz Antenna (for EU and IN modules) or 900 MHz Antenna (for ASIA-PAC / LATAM module)

Notes

- This example can be executed in Waspmote v12 and Waspmote v15

Code

/*  
 *  ------ LoRaWAN Code Example -------- 
 *  
 *  Explanation: This example shows how to configure the channels settings.
 *  There are 16 channels. The first three of them are always preconfigured 
 *  and cannot be changed: 868.1 MHz, 868.3 MHz and 868.5 MHz. Besides other
 *  parameters can be changed in all channels: Duty Cycle, Data rate range
 *  and channel status
 *  
 *  Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify  
 *  it under the terms of the GNU General Public License as published by  
 *  the Free Software Foundation, either version 3 of the License, or  
 *  (at your option) any later version.  
 *   
 *  This program is distributed in the hope that it will be useful,  
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of  
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 *  GNU General Public License for more details.  
 *   
 *  You should have received a copy of the GNU General Public License  
 *  along with this program.  If not, see .  
 *  
 *  Version:           3.4
 *  Design:            David Gascon 
 *  Implementation:    Luismi Marti
 */

#include <WaspLoRaWAN.h>

//////////////////////////////////////////////
uint8_t socket = SOCKET0;
//////////////////////////////////////////////

// variable
uint8_t error;


void setup() 
{
  USB.ON();
  USB.println(F("LoRaWAN example - LoRaWAN EU Channel configuration"));

  //////////////////////////////////////////////
  // 1. switch on
  //////////////////////////////////////////////

  error = LoRaWAN.ON(socket);

  // Check status
  if( error == 0 ) 
  {
    USB.println(F("1. Switch ON OK"));     
  }
  else 
  {
    USB.print(F("1. Switch ON error = ")); 
    USB.println(error, DEC);
  }


  //////////////////////////////////////////////
  // 2. Set frequency for specific channel
  //////////////////////////////////////////////

  error = LoRaWAN.setChannelFreq(3, 865000000);

  // Check status
  if( error == 0 ) 
  {
    USB.print(F("2. Frequency set OK. "));    
    USB.print(F("Frequency:"));
    USB.println(LoRaWAN._freq[3]);
  }
  else 
  {
    USB.print(F("2. Frequency set error = ")); 
    USB.println(error, DEC);
  }


  //////////////////////////////////////////////
  // 3. Set Duty Cycle for specific channel
  //////////////////////////////////////////////

  error = LoRaWAN.setChannelDutyCycle(3, 999);

  // Check status
  if( error == 0 ) 
  {
    USB.print(F("3. Adaptive Data Rate disabled OK. "));    
    USB.print(F("Duty Cycle:"));
    USB.println(LoRaWAN._dCycle[3], DEC);
  }
  else 
  {
    USB.print(F("3. Duty cycle set error = ")); 
    USB.println(error, DEC);
  }


  //////////////////////////////////////////////
  // 4. Set Data rate range for specific channel
  //////////////////////////////////////////////

  error = LoRaWAN.setChannelDRRange(3, 0, 2);

  // Check status
  if( error == 0 ) 
  {
    USB.print(F("4. Data Rate range set OK. "));    
    USB.print(F("Data Rate min:"));
    USB.print(LoRaWAN._drrMin[3], DEC); 
    USB.print(F(". Data Rate max:"));
    USB.println(LoRaWAN._drrMax[3], DEC);
  }
  else 
  {
    USB.print(F("4. Data rate range set error = ")); 
    USB.println(error, DEC);
  }


  //////////////////////////////////////////////
  // 5. Set Data rate range for specific channel
  //////////////////////////////////////////////

  error = LoRaWAN.setChannelStatus(3, "on");

  // Check status
  if( error == 0 ) 
  {
    USB.print(F("5. Channel status set OK: "));
    USB.println(LoRaWAN._status[3], DEC);
  }
  else 
  {
    USB.print(F("5. Channel status set error = ")); 
    USB.println(error, DEC);
  }


  //////////////////////////////////////////////
  // 6. Save configuration
  //////////////////////////////////////////////

  error = LoRaWAN.saveConfig();

  // Check status
  if( error == 0 ) 
  {
    USB.println(F("4. Save configuration OK"));     
  }
  else 
  {
    USB.print(F("4. Save configuration error = ")); 
    USB.println(error, DEC);
  }


  ///////////////////////////////////////////////////////////
  // show configuration for all channels available
  ///////////////////////////////////////////////////////////

  USB.println(F("\n----------------------------"));

  for( int i=0; i<16; i++)
  {
    LoRaWAN.getChannelFreq(i);
    LoRaWAN.getChannelDutyCycle(i);
    LoRaWAN.getChannelDRRange(i);
    LoRaWAN.getChannelStatus(i);

    USB.print(F("Channel: "));
    USB.println(i);
    USB.print(F("  Freq: "));
    USB.println(LoRaWAN._freq[i]);
    USB.print(F("  Duty cycle: "));
    USB.println(LoRaWAN._dCycle[i]);
    USB.print(F("  DR min: "));
    USB.println(LoRaWAN._drrMin[i], DEC);
    USB.print(F("  DR max: "));
    USB.println(LoRaWAN._drrMax[i], DEC);
    USB.print(F("  Status: "));
    if (LoRaWAN._status[i] == 1)
    {
      USB.println(F("on"));
    }
    else
    {
      USB.println(F("off"));
    }
    USB.println(F("----------------------------"));
  } 
  

}


void loop() 
{


}

Output

H#
LoRaWAN example - Channels configuration
1. Switch ON OK
2. Frequency set OK. Frequency:865000000
3. Adaptive Data Rate disabled OK. Duty Cycle:999
4. Data Rate range set OK. Data Rate min:0. Data Rate max:2
5. Channel status set OK: 1
4. Save configuration OK

----------------------------
Channel: 0
Freq: 868100000
Duty cycle: 302
DR min: 0
DR max: 5
Status: 1
----------------------------
Channel: 1
Freq: 868300000
Duty cycle: 302
DR min: 0
DR max: 5
Status: 1
----------------------------
Channel: 2
Freq: 868500000
Duty cycle: 302
DR min: 0
DR max: 5
Status: 1
----------------------------
Channel: 3
Freq: 865000000
Duty cycle: 999
DR min: 0
DR max: 2
Status: 1
----------------------------
Channel: 4
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 5
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 6
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 7
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 8
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 9
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 10
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 11
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 12
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 13
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 14
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------
Channel: 15
Freq: 0
Duty cycle: 65535
DR min: 15
DR max: 15
Status: 0
----------------------------

Last updated