This example shows how to configure the semtech module in LoRa mode and then receive packets from any node. When a packet is received, an ACK is sent back to the sender. This code works as a network sniffer because independently the packet is sent to, this module gets it and shows it.
Required Materials
1 x Waspmote PRO
1 x Battery
1 x MiniUSB wire
1 x SX1272 module (LoRa)
1 x At least one sender to check this receiving code
Notes
- The SX1272 module is provided with a special 4.5 dBi antenna, which enables maximum range. The only exception is Smart Parking; in this case the antenna is smaller, 0 dBi, to fit inside the enclosure.
- It is not recommended to work without an antenna screwed to the module. The module could be damaged due to RF reflections.
- The SX1272 module can only be used in special Waspmote units which have been modified to drive the SPI pins to SOCKET0. (only SOCKET0 is available for SX1272)
- This module does not save the configuration. So, the network settings as the mode or the channel MUST be configured every time it is switched on.
- This example can be executed in Waspmote v12 and Waspmote v15
Code
/*
* ------ [SX_10] - RX LoRa from all Nodes with ACK --------
*
* Explanation: This example shows how to configure the semtech
* module in LoRa mode and then receive packets from any node. When a
* packet is received, an ACK is sent back to the sender. This
* code works as a network sniffer because independently the packet is
* sent to, this module gets it and shows it.
*
* Copyright (C) 2014 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 .
*/
// Put your libraries here (#include ...)
#include <WaspSX1272.h>
// status variable
int8_t e;
void setup()
{
// init USB port
USB.ON();
USB.println(F("Semtech SX1272 module RX in LoRa, complete example"));
// init SX1272 module
sx1272.ON();
// select frequency channel
e = sx1272.setChannel(CH_14_868);
USB.print(F("Setting Channel CH_14_868.\t state "));
USB.println(e);
// select implicit or explicit header mode
e = sx1272.setHeaderON();
USB.print(F("Setting Header ON.\t\t state "));
USB.println(e);
// Select mode: from 1 to 10
e = sx1272.setMode(10);
USB.print(F("Setting Mode '10'.\t\t state "));
USB.println(e);
// Select CRC on or off
e = sx1272.setCRC_ON();
USB.print(F("Setting CRC ON.\t\t\t state "));
USB.println(e);
// Select output power (Max, High or Low)
e = sx1272.setPower('H');
USB.print(F("Setting Power to 'H'.\t\t state "));
USB.println(e);
// select the node address value: from 2 to 255
e = sx1272.setNodeAddress(53);
USB.print(F("Setting Node Address to '53'.\t state "));
USB.println(e);
USB.println();
delay(1000);
USB.println(F("--------------------------------------------------"));
USB.println(F("Receiving from All Nodes (with ACK response):"));
USB.println(F("--------------------------------------------------"));
}
void loop()
{
// Receive from all Nodes
e = sx1272.receiveAll(10000);
// check RX status
if( e == 0 )
{
// if packet received then send ACK
e = sx1272.setACK();
if( e == 0 )
{
e = sx1272.sendWithTimeout();
USB.print(F("ACK sent, state "));
USB.println(e, DEC);
}
else
{
USB.println(F("There has been any error while setting ACK"));
}
}
else
{
USB.println(F("There has been any error while receiving packet"));
}
}
Output
H#
Semtech SX1272 module RX in LoRa, complete example
Setting Channel CH_14_868. state 0
Setting Header ON. state 0
Setting Mode '10'. state 0
Setting CRC ON. state 0
Setting Power to 'H'. state 0
Setting Node Address to '53'. state 0
--------------------------------------------------
Receiving from All Nodes (with ACK response):
--------------------------------------------------
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
ACK sent, state 0
...