* ------ 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
* 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 .
* Implementation: Luismi Marti
//////////////////////////////////////////////
uint8_t socket = SOCKET0;
//////////////////////////////////////////////
USB.println(F("LoRaWAN example - LoRaWAN EU Channel configuration"));
//////////////////////////////////////////////
//////////////////////////////////////////////
error = LoRaWAN.ON(socket);
USB.println(F("1. Switch ON OK"));
USB.print(F("1. Switch ON error = "));
//////////////////////////////////////////////
// 2. Set frequency for specific channel
//////////////////////////////////////////////
error = LoRaWAN.setChannelFreq(3, 865000000);
USB.print(F("2. Frequency set OK. "));
USB.print(F("Frequency:"));
USB.println(LoRaWAN._freq[3]);
USB.print(F("2. Frequency set error = "));
//////////////////////////////////////////////
// 3. Set Duty Cycle for specific channel
//////////////////////////////////////////////
error = LoRaWAN.setChannelDutyCycle(3, 999);
USB.print(F("3. Adaptive Data Rate disabled OK. "));
USB.print(F("Duty Cycle:"));
USB.println(LoRaWAN._dCycle[3], DEC);
USB.print(F("3. Duty cycle set error = "));
//////////////////////////////////////////////
// 4. Set Data rate range for specific channel
//////////////////////////////////////////////
error = LoRaWAN.setChannelDRRange(3, 0, 2);
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);
USB.print(F("4. Data rate range set error = "));
//////////////////////////////////////////////
// 5. Set Data rate range for specific channel
//////////////////////////////////////////////
error = LoRaWAN.setChannelStatus(3, "on");
USB.print(F("5. Channel status set OK: "));
USB.println(LoRaWAN._status[3], DEC);
USB.print(F("5. Channel status set error = "));
//////////////////////////////////////////////
//////////////////////////////////////////////
error = LoRaWAN.saveConfig();
USB.println(F("4. Save configuration OK"));
USB.print(F("4. Save configuration error = "));
///////////////////////////////////////////////////////////
// show configuration for all channels available
///////////////////////////////////////////////////////////
USB.println(F("\n----------------------------"));
LoRaWAN.getChannelFreq(i);
LoRaWAN.getChannelDutyCycle(i);
LoRaWAN.getChannelDRRange(i);
LoRaWAN.getChannelStatus(i);
USB.print(F("Channel: "));
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("----------------------------"));