LoRaWAN P2P 01: Configure
This example shows how to configure the module for P2P mode and the corresponding parameters. The user must keep in mind that every time the module is switched on, the radio settings MUST be set again.
Required Materials
1 x Waspmote 1 x Battery 1 x LoRaWAN module 1 x 868 MHz antenna
Notes
- This example can be executed in Waspmote v12 and Waspmote v15
Code
/*
* ------ P2P Code Example --------
*
* Explanation: This example shows how to configure the module
* for P2P mode and the corresponding parameters. The user must
* keep in mind that every time the module is switched on,
* the radio settings MUST be set again
*
* 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.2
* Design: David Gascon
* Implementation: Luismi Marti
*/
#include <WaspLoRaWAN.h>
//////////////////////////////////////////////
uint8_t socket = SOCKET0;
//////////////////////////////////////////////
// define radio settings
//////////////////////////////////////////////
uint8_t power = 15;
uint32_t frequency;
char spreading_factor[] = "sf10";
char coding_rate[] = "4/5";
uint16_t bandwidth = 125;
char crc_mode[] = "on";
//////////////////////////////////////////////
// variable
uint8_t error;
void setup()
{
USB.ON();
USB.println(F("Radio P2P example - Module configuration\n"));
//////////////////////////////////////////////
// 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);
}
USB.println(F("-------------------------------------------------------"));
if (LoRaWAN._version == RN2483_MODULE || LoRaWAN._version == RN2903_IN_MODULE)
{
frequency = 868100000;
}
else if(LoRaWAN._version == RN2903_MODULE)
{
frequency = 902300000;
}
//////////////////////////////////////////////
// 2. Enable P2P mode
//////////////////////////////////////////////
error = LoRaWAN.macPause();
// Check status
if (error == 0)
{
USB.println(F("2. P2P mode enabled OK"));
}
else
{
USB.print(F("2. Enable P2P mode error = "));
USB.println(error, DEC);
}
USB.println(F("-------------------------------------------------------"));
//////////////////////////////////////////////
// 3. Set/Get Radio Power
//////////////////////////////////////////////
// Set power
error = LoRaWAN.setRadioPower(power);
// Check status
if (error == 0)
{
USB.println(F("3.1. Set Radio Power OK"));
}
else
{
USB.print(F("3.1. Set Radio Power error = "));
USB.println(error, DEC);
}
// Get power
error = LoRaWAN.getRadioPower();
// Check status
if (error == 0)
{
USB.print(F("3.2. Get Radio Power OK. "));
USB.print(F("Power: "));
USB.println(LoRaWAN._radioPower);
}
else
{
USB.print(F("3.2. Get Radio Power error = "));
USB.println(error, DEC);
}
USB.println(F("-------------------------------------------------------"));
//////////////////////////////////////////////
// 4. Set/Get Radio Frequency
//////////////////////////////////////////////
// Set frequency
error = LoRaWAN.setRadioFreq(frequency);
// Check status
if (error == 0)
{
USB.println(F("4.1. Set Radio Frequency OK"));
}
else
{
USB.print(F("4.1. Set Radio Frequency error = "));
USB.println(error, DEC);
}
// Get frequency
error = LoRaWAN.getRadioFreq();
// Check status
if (error == 0)
{
USB.print(F("4.2. Get Radio Frequency OK. "));
USB.print(F("Frequency: "));
USB.println(LoRaWAN._radioFreq);
}
else
{
USB.print(F("4.2. Get Radio Frequency error = "));
USB.println(error, DEC);
}
USB.println(F("-------------------------------------------------------"));
//////////////////////////////////////////////
// 5. Set/Get Radio Spreading Factor (SF)
//////////////////////////////////////////////
// Set SF
error = LoRaWAN.setRadioSF(spreading_factor);
// Check status
if (error == 0)
{
USB.println(F("5.1. Set Radio SF OK"));
}
else
{
USB.print(F("5.1. Set Radio SF error = "));
USB.println(error, DEC);
}
// Get SF
error = LoRaWAN.getRadioSF();
// Check status
if (error == 0)
{
USB.print(F("5.2. Get Radio SF OK. "));
USB.print(F("Spreading Factor: "));
USB.println(LoRaWAN._radioSF);
}
else
{
USB.print(F("5.2. Get Radio SF error = "));
USB.println(error, DEC);
}
USB.println(F("-------------------------------------------------------"));
//////////////////////////////////////////////
// 6. Set/Get Radio Coding Rate (CR)
//////////////////////////////////////////////
// Set CR
error = LoRaWAN.setRadioCR(coding_rate);
// Check status
if (error == 0)
{
USB.println(F("6.1. Set Radio CR OK"));
}
else
{
USB.print(F("6.1. Set Radio CR error = "));
USB.println(error, DEC);
}
// Get CR
error = LoRaWAN.getRadioCR();
// Check status
if (error == 0)
{
USB.print(F("6.2. Get Radio CR OK. "));
USB.print(F("Coding Rate: "));
USB.println(LoRaWAN._radioCR);
}
else
{
USB.print(F("6.2. Get Radio CR error = "));
USB.println(error, DEC);
}
USB.println(F("-------------------------------------------------------"));
//////////////////////////////////////////////
// 7. Set/Get Radio Bandwidth (BW)
//////////////////////////////////////////////
// Set BW
error = LoRaWAN.setRadioBW(bandwidth);
// Check status
if (error == 0)
{
USB.println(F("7.1. Set Radio BW OK"));
}
else
{
USB.print(F("7.1. Set Radio BW error = "));
USB.println(error, DEC);
}
// Get BW
error = LoRaWAN.getRadioBW();
// Check status
if (error == 0)
{
USB.print(F("7.2. Get Radio BW OK. "));
USB.print(F("Bandwidth: "));
USB.println(LoRaWAN._radioBW);
}
else
{
USB.print(F("7.2. Get Radio BW error = "));
USB.println(error, DEC);
}
USB.println(F("-------------------------------------------------------"));
//////////////////////////////////////////////
// 8. Set/Get Radio CRC mode
//////////////////////////////////////////////
// Set CRC
error = LoRaWAN.setRadioCRC(crc_mode);
// Check status
if (error == 0)
{
USB.println(F("8.1. Set Radio CRC mode OK"));
}
else
{
USB.print(F("8.1. Set Radio CRC mode error = "));
USB.println(error, DEC);
}
// Get CRC
error = LoRaWAN.getRadioCRC();
// Check status
if (error == 0)
{
USB.print(F("8.2. Get Radio CRC mode OK. "));
USB.print(F("CRC status: "));
USB.println(LoRaWAN._crcStatus);
}
else
{
USB.print(F("8.2. Get Radio CRC mode error = "));
USB.println(error, DEC);
}
USB.println(F("-------------------------------------------------------"));
USB.println(F("-------------------------------------------------------"));
USB.println(F("Now the LoRaWAN module is ready for P2P communications."));
USB.println(F("The user must keep in mind that every time the module is"));
USB.println(F("switched on, the radio settings MUST be set again."));
USB.println(F("Please check the next examples..."));
USB.println(F("-------------------------------------------------------\n"));
}
void loop()
{
}
Output
H#
Radio P2P example - Module configuration
1. Switch ON OK
-------------------------------------------------------
2. P2P mode enabled OK
-------------------------------------------------------
3.1. Set Radio Power OK
3.2. Get Radio Power OK. Power: 15
-------------------------------------------------------
4.1. Set Radio Frequency OK
4.2. Get Radio Frequency OK. Frequency: 868100000
-------------------------------------------------------
5.1. Set Radio SF OK
5.2. Get Radio SF OK. Spreading Factor: sf12
-------------------------------------------------------
6.1. Set Radio CR OK
6.2. Get Radio CR OK. Coding Rate: 4/5
-------------------------------------------------------
7.1. Set Radio BW OK
7.2. Get Radio BW OK. Bandwidth: 125
-------------------------------------------------------
8.1. Set Radio CRC mode OK
8.2. Get Radio CRC mode OK. CRC status: 1
-------------------------------------------------------
-------------------------------------------------------
Now the LoRaWAN module is ready for P2P communications.
The user must keep in mind that every time the module is
switched on, the radio settings MUST be set again.
Please check the next examples...
-------------------------------------------------------
Last updated