Development

Communication / LoRa:

» SX 07c: TX Frame ACK wRetries Meshlium

This example shows how to send a Waspmote Frame via SX1272 module to MESHLIUM. Steps performed: - Configurate the LoRa mode - Create a new Waspmote Frame - Send a packet to Meshlium

Required Materials

1 x Waspmote PRO
1 x Battery
1 x MiniUSB wire
1 x SX1272 module (LoRa)
1 x Meshlium receiver with the same settings as this sender

Notes

* This is part of a two-code example. A Meshlium receiver must be set up with the same settings as this sender
* 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.

Code

/*  
 *  ----- [SX_07c] - TX to Meshlium (with ACKs and Retries) ----- 
 *  
 *  Explanation: This example shows how to send a Waspmote Frame
 *  via SX1272 module to MESHLIUM. Steps performed:
 *    - Configurate the LoRa mode
 *    - Create a new Waspmote Frame
 *    - Send a packet to Meshlium
 *  
 *  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 <http://www.gnu.org/licenses/>.  
 *  
 *  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 the Waspmote ID 
//////////////////////////////////////////
char nodeID[] = "node_01";
//////////////////////////////////////////

// Define the Meshlium address to send packets
// The default Meshlium address is '1'
uint8_t meshlium_address = 1;

// status variable
int e;


void setup()
{
  // Init USB port
  USB.ON();
  USB.println(F("SX_07c example"));
  USB.println(F("Semtech SX1272 module. TX in LoRa to MESHLIUM (with ACKs and Retries)"));

  // Switch ON RTC
  RTC.ON();

  // Switch ON ACC
  ACC.ON();

  // set the Waspmote ID
  frame.setID(nodeID);  

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

  // Init sx1272 module
  sx1272.ON();

  // Select frequency channel
  e = sx1272.setChannel(CH_12_868);
  USB.print(F("Setting Channel CH_12_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 (mode 1)
  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(5);
  USB.print(F("Setting Node Address to '5'.\t state "));
  USB.println(e);
  USB.println();

  // Select the maximum number of retries: from '0' to '5'
  e = sx1272.setRetries(3);
  USB.print(F("Setting Retries to '3'.\t state "));
  USB.println(e);
  USB.println();

  delay(1000);

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

void loop()
{

  // get Time from RTC
  RTC.getTime();

  ///////////////////////////////////////////
  // 1. Create ASCII frame
  ///////////////////////////////////////////  

  USB.println(F("Create a new Frame:"));

  // create new frame
  frame.createFrame(ASCII);  

  // add frame fields
  frame.addSensor(SENSOR_DATE, RTC.date, RTC.month, RTC.year);
  frame.addSensor(SENSOR_TIME, RTC.hour, RTC.minute, RTC.second);
  frame.addSensor(SENSOR_ACC, ACC.getX(), ACC.getY(), ACC.getZ());
  frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel()); 

  // Prints frame
  frame.showFrame();


  ///////////////////////////////////////////
  // 2. Send packet
  ///////////////////////////////////////////   
  // Sending packet, with retries if failure, and waiting an ACK response
  e = sx1272.sendPacketTimeoutACKRetries( meshlium_address, frame.buffer, frame.length);
  
  // if ACK was received check signal strength
  if( e == 0 )
  {   
    USB.println(F("Packet sent OK"));     
    
    e = sx1272.getSNR();
    USB.print(F("-> SNR: "));
    USB.println(sx1272._SNR); 
    
    e = sx1272.getRSSI();
    USB.print(F("-> RSSI: "));
    USB.println(sx1272._RSSI);   
    
    e = sx1272.getRSSIpacket();
    USB.print(F("-> Last packet RSSI value is: "));    
    USB.println(sx1272._RSSIpacket); 
  }
  else 
  {
    USB.println(F("Error sending the packet"));  
    USB.print(F("state: "));
    USB.println(e, DEC);
  } 

  USB.println();
  delay(2500);
}

Output

E#
SX_07c example
Semtech SX1272 module. TX in LoRa to MESHLIUM (with ACKs and Retries)
----------------------------------------
Setting configuration:
----------------------------------------
Setting Channel CH_12_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 '5'. state 0

Setting Retries to '3'. state 0

----------------------------------------
Sending:
----------------------------------------
Create a new Frame:
===============================
Current ASCII Frame:
Length: 76
Frame Type: 128
frame (HEX): 3C3D3E800423333837323536303030236E6F64655F3031233023444154453A31382D31312D31342354494D453A31332D35362D3234234143433A33323B31373B31303331234241543A393823
frame (STR): <=>€#387256000#node_01#0#DATE:18-11-14#TIME:13-56-24#ACC:32;17;1031#BAT:98#
===============================
Packet sent OK
-> SNR: 1
-> RSSI: -108
-> Last packet RSSI value is: -74

Create a new Frame:
===============================
Current ASCII Frame:
Length: 75
Frame Type: 128
frame (HEX): 3C3D3E800423333837323536303030236E6F64655F3031233123444154453A31382D31312D31342354494D453A31332D35362D3332234143433A34323B363B31303336234241543A393923
frame (STR): <=>€#387256000#node_01#1#DATE:18-11-14#TIME:13-56-32#ACC:42;6;1036#BAT:99#
===============================
Packet sent OK
-> SNR: 5
-> RSSI: -108
-> Last packet RSSI value is: -73

Create a new Frame:
===============================
Current ASCII Frame:
Length: 76
Frame Type: 128
frame (HEX): 3C3D3E800423333837323536303030236E6F64655F3031233223444154453A31382D31312D31342354494D453A31332D35362D3430234143433A34303B31333B31303330234241543A393923
frame (STR): <=>€#387256000#node_01#2#DATE:18-11-14#TIME:13-56-40#ACC:40;13;1030#BAT:99#
===============================
Packet sent OK
-> SNR: 4
-> RSSI: -104
-> Last packet RSSI value is: -74

...

Quick Publish: