SX 07b: RX Frame ACK wRetries

This example shows how to receive a Waspmote Frame via SX1272 module. Steps performed: - Configure the LoRa mode - Receive a packet sending an ACK in that case

Required Materials

1 x Waspmote PRO 1 x Battery 1 x MiniUSB wire 1 x SX1272 module (LoRa) 1 x Sender module with SX_07a example

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_07b] - RX LoRa with ACKs and Retries -------- 
 *  
 *  Explanation: This example shows how to receive a Waspmote Frame
 *  via SX1272 module. Steps performed:
 *    - Configurate the LoRa mode
 *    - Receive a packet sending an ACK in that case
 *  
 *  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 .  
 *  
 *  Version:           0.1
 *  Design:            David Gascón
 *  Implementation:    Covadonga Albiñana, Yuri Carmona
 */

// Include these libraries to transmit frames with sx1272
#include <WaspSX1272.h>
#include <WaspFrame.h> 

// define status variable
int e;


void setup() 
{
  // Init USB port
  USB.ON();
  USB.println(F("SX_07b example"));
  USB.println(F("Semtech SX1272 module. RX LoRa with Waspmote Frame, ACKs and Retries"));


  USB.println(F("----------------------------------------"));
  USB.println(F("Setting configuration:")); 
  USB.println(F("----------------------------------------"));

  // Init sx1272 module
  sx1272.ON();

  //// Options to configure: ////

  // Select frequency channel
  e = sx1272.setChannel(CH_11_868);
  USB.print(F("Setting Channel CH_11_868.\t state ")); 
  USB.println(e);

  // Select implicit (off) or explicit (on) 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(1);  
  USB.print(F("Setting Mode '1'.\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(2);
  USB.print(F("Setting Node Address to '2'.\t state "));
  USB.println(e);
  USB.println();

  delay(1000);  

  USB.println(F("----------------------------------------"));
  USB.println(F("Receiving:")); 
  USB.println(F("----------------------------------------"));
}


void loop()
{
  // Receiving packet and sending an ACK response
  e = sx1272.receivePacketTimeoutACK(10000);

  // check rx status
  if( e==0 )
  {
    USB.println(F("Show packet received: "));

    // show packet received
    sx1272.showReceivedPacket();

  }
  else
  {
    USB.print(F("Receiving packet TIMEOUT, state "));
    USB.println(e, DEC);  
  }
  
  USB.println();


}

Output

H#
SX_07b example
Semtech SX1272 module. RX LoRa with Waspmote Frame, ACKs and Retries
----------------------------------------
Setting configuration:
----------------------------------------
Setting Channel CH_11_868. state 0
Setting Header ON. state 0
Setting Mode '1'. state 0
Setting CRC ON. state 0
Setting Power to 'H'. state 0
Setting Node Address to '2'. state 0

----------------------------------------
Receiving:
----------------------------------------
Show packet received:
==============================
dest: 2
src: 3
packnum: 0
length: 53
retry: 0
payload (HEX): 3C3D3E800223333837323536303030236E6F64655F3030312330234241543A3938234143433A33373B363B3130333123
payload (string): <=>€#387256000#node_001#0#BAT:98#ACC:37;6;1031#
==============================

Show packet received:
==============================
dest: 2
src: 3
packnum: 1
length: 53
retry: 0
payload (HEX): 3C3D3E800223333837323536303030236E6F64655F3030312331234241543A3939234143433A33363B363B3130333623
payload (string): <=>€#387256000#node_001#1#BAT:99#ACC:36;6;1036#
==============================

Show packet received:
==============================
dest: 2
src: 3
packnum: 2
length: 53
retry: 0
payload (HEX): 3C3D3E800223333837323536303030236E6F64655F3030312332234241543A3939234143433A33343B393B3130323923
payload (string): <=>€#387256000#node_001#2#BAT:99#ACC:34;9;1029#
==============================

...

Last updated