Problem sent frame SX1272- Meshlium

Wireless communications in Waspmote, topologies, node types...
Post Reply
pablo_chumacero
Posts: 18
Joined: Sat Mar 19, 2016 12:58 am

Problem sent frame SX1272- Meshlium

Post by pablo_chumacero » Sat Oct 15, 2016 2:11 am

Hi,

I want to send a frame that is a string of characters, this string contain data about humidity, for several Waspmote with SX1272 module 868 to a Meshlium Lora. But when I tried to send the data to Meshlium this do not, however, the UART port tells me that the frame has been sent. I do not know if it's the type of frame that I am sending (STR) or because the frame is too long.

This is my code.

Code: Select all

#include <WaspSX1272.h>
#include <WaspFrame.h>
#include <WaspLoRaWAN.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;

//////////////////////////////////////////////
uint8_t socket = SOCKET1;
//////////////////////////////////////////////

// define radio settings (P2P interface)
//////////////////////////////////////////////
uint8_t power = 15;
uint32_t frequency = 868100000;
char spreading_factor[] = "sf12";
char coding_rate[] = "4/5";
uint16_t bandwidth = 125;
char crc_mode[] = "on";
//////////////////////////////////////////////

// define
char packet[512];
uint8_t data[512];

// variable
uint8_t error;

// status variable
int e;


void setup()
{
  // Init USB port
  USB.ON();
  USB.println(F("SX_05c example"));
  USB.println(F("Semtech SX1272 module. TX in LoRa to MESHLIUM"));
  
  // module setup
  error = radioModuleSetup();

  // Check status
  if (error == 0)
  {
    USB.println(F("Radio interface LoRaWAN configured OK"));     
  }
  else 
  {
    USB.println(F("Radio interface LoRaWAN configured ERROR"));     
  }
  USB.println();

  // 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 SX1272:")); 
  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();

  delay(1000);

}


void loop()
{
  
  USB.println(F("\n-------------------------------------------------------"));
  USB.println(F("Listening to packets:"));
  USB.println(F("-------------------------------------------------------"));

  // Set receive mode 
  error = LoRaWAN.receiveRadio(10000);

  // Check status
  if (error == 0)
  {
    USB.println(F("--> Packet received"));
    
    USB.print(F("data: "));
    USB.println((char*) LoRaWAN._buffer);
    
    USB.print(F("length: "));
    USB.println(LoRaWAN._length);
        
    // copy packet contents into a global buffer
    strncpy( packet, (char*) LoRaWAN._buffer, sizeof(frame.buffer));
  }  
  else 
  {
     // error code
     //  1: error
     //  2: no incoming packet
     USB.print(F("Error waiting for packets. error = "));  
     USB.println(error, DEC);   
   }      
    
  // get Time from RTC
  RTC.getTime();

  ///////////////////////////////////////////
  // 1. Create ASCII frame
  /////////////////////////////////////////// 
  
  Utils.str2hex(packet,data);
  USB.println((char*)data);
  delay(1000);
 
  //Utils.hex2str(packet,data);

  USB.println(F("Create a new Frame:"));
  
  // create new frame
  frame.createFrame(ASCII);
  //frame.addSensor(SENSOR_BAT,);   

  // add frame fields
  // set frame fields (String - char*)
  frame.addSensor(SENSOR_STR, (char*) data);
  // Prints frame
  frame.showFrame();


  ///////////////////////////////////////////
  // 2. Send packet
  ///////////////////////////////////////////  

  // Sending packet before ending a timeout
  e = sx1272.sendPacketTimeout( meshlium_address,frame.buffer, frame.length );
  
  // if ACK was received check signal strength
  if( e == 0 )
  {   
    USB.println(F("Packet sent OK"));     
  }
  else 
  {
    USB.println(F("Error sending the packet"));  
    USB.print(F("state: "));
    USB.println(e, DEC);
  } 

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


/***********************************************************************************
 *
 * radioModuleSetup()
 *
 *   This function includes all functions related to the module setup and configuration
 *   The user must keep in mind that each time the module powers on, all settings are set
 *   to default values. So it is better to develop a specific function including all steps
 *   for setup and call it everytime the module powers on.
 *
 *
 ***********************************************************************************/
uint8_t radioModuleSetup()
{ 

  uint8_t status = 0;
  uint8_t e = 0;

  USB.println(F("\n-------------------------------------------------------"));
  USB.println(F("P2P mode configuration:"));
  USB.println(F("-------------------------------------------------------"));

  //////////////////////////////////////////////
  // 1. switch on
  //////////////////////////////////////////////

  e = LoRaWAN.ON(socket);

  // Check status
  if (e == 0)
  {
    USB.println(F("1. Switch ON OK"));     
  }
  else 
  {
    USB.print(F("1. Switch ON error = ")); 
    USB.println(e, DEC);
    status = 1;
  }


  //////////////////////////////////////////////
  // 2. Enable P2P mode
  //////////////////////////////////////////////

  e = LoRaWAN.macPause();

  // Check status
  if (e == 0)
  {
    USB.println(F("2. P2P mode enabled OK"));
  }
  else 
  {
    USB.print(F("2. Enable P2P mode error = "));
    USB.println(e, DEC);
    status = 1;
  }



  //////////////////////////////////////////////
  // 3. Set/Get Radio Power
  //////////////////////////////////////////////

  // Set power
  e = LoRaWAN.setRadioPower(power);

  // Check status
  if (e == 0)
  {
    USB.println(F("3.1. Set Radio Power OK"));
  }
  else 
  {
    USB.print(F("3.1. Set Radio Power error = "));
    USB.println(e, DEC);
    status = 1;
  }

  // Get power
  e = LoRaWAN.getRadioPower();

  // Check status
  if (e == 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(e, DEC);
    status = 1;
  }



  //////////////////////////////////////////////
  // 4. Set/Get Radio Frequency
  //////////////////////////////////////////////

  // Set frequency
  e = LoRaWAN.setRadioFreq(frequency);

  // Check status
  if (e == 0)
  {
    USB.println(F("4.1. Set Radio Frequency OK"));
  }
  else 
  {
    USB.print(F("4.1. Set Radio Frequency error = "));
    USB.println(e, DEC);
    status = 1;
  }

  // Get frequency
  e = LoRaWAN.getRadioFreq();

  // Check status
  if (e == 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(e, DEC);
    status = 1;
  }


  //////////////////////////////////////////////
  // 5. Set/Get Radio Spreading Factor (SF)
  //////////////////////////////////////////////

  // Set SF
  e = LoRaWAN.setRadioSF(spreading_factor);

  // Check status
  if (e == 0)
  {
    USB.println(F("5.1. Set Radio SF OK"));
  }
  else 
  {
    USB.print(F("5.1. Set Radio SF error = "));
    USB.println(e, DEC);
    status = 1;
  }

  // Get SF
  e = LoRaWAN.getRadioSF();

  // Check status
  if (e == 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(e, DEC);
    status = 1;
  }



  //////////////////////////////////////////////
  // 6. Set/Get Radio Coding Rate (CR)
  //////////////////////////////////////////////

  // Set CR
  e = LoRaWAN.setRadioCR(coding_rate);

  // Check status
  if (e == 0)
  {
    USB.println(F("6.1. Set Radio CR OK"));
  }
  else 
  {
    USB.print(F("6.1. Set Radio CR error = "));
    USB.println(e, DEC);
    status = 1;
  }

  // Get CR
  e = LoRaWAN.getRadioCR();

  // Check status
  if (e == 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(e, DEC);
    status = 1;
  }


  //////////////////////////////////////////////
  // 7. Set/Get Radio Bandwidth (BW)
  //////////////////////////////////////////////

  // Set BW
  e = LoRaWAN.setRadioBW(bandwidth);

  // Check status
  if (e == 0)
  {
    USB.println(F("7.1. Set Radio BW OK"));
  }
  else 
  {
    USB.print(F("7.1. Set Radio BW error = "));
    USB.println(e, DEC);
  }

  // Get BW
  e = LoRaWAN.getRadioBW();

  // Check status
  if (e == 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(e, DEC);
    status = 1;
  }


  //////////////////////////////////////////////
  // 8. Set/Get Radio CRC mode
  //////////////////////////////////////////////

  // Set CRC
  e = LoRaWAN.setRadioCRC(crc_mode);

  // Check status
  if (e == 0)
  {
    USB.println(F("8.1. Set Radio CRC mode OK"));
  }
  else 
  {
    USB.print(F("8.1. Set Radio CRC mode error = "));
    USB.println(e, DEC);
    status = 1;
  }

  // Get CRC
  e = LoRaWAN.getRadioCRC();

  // Check status
  if (e == 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(e, DEC);
    status = 1;
  }
  USB.println(F("-------------------------------------------------------"));


  return status;
}
and this is my output:

Code: Select all

E#
SX_05c example
Semtech SX1272 module. TX in LoRa to MESHLIUM

-------------------------------------------------------
P2P mode 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
-------------------------------------------------------
Radio interface LoRaWAN configured OK

----------------------------------------
Setting configuration SX1272:
----------------------------------------
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


-------------------------------------------------------
Listening to packets:
-------------------------------------------------------
--> Packet received
data: 3C3D3E800123343033333539363438236E6F64655F30312336235354523A48333D2D302E30352C48343D2D302E3034200A23
length: 100
<=>€#403359648#node_01#6#STR:H3=-0.05,H4=-0.04 
#
Create a new Frame:
===============================
Current ASCII Frame:
Length: 81
Frame Type:  128
frame (HEX): 3C3D3E800123343038353230323438236E6F64655F30312330235354523A3C3D3E80015F3430333335393634385F6E6F64655F30315F365F5354523A48333D2D302E30352C48343D2D302E3034200A5F23
frame (STR): <=>€#408520248#node_01#0#STR:<=>€_403359648_node_01_6_STR:H3=-0.05,H4=-0.04 
_#
===============================
Packet sent OK


-------------------------------------------------------
Listening to packets:
-------------------------------------------------------
--> Packet received
data: 3C3D3E800123343038343231303932236E6F64655F303123313439235354523A48756D6564616420313D2D302E303420262048756D65646164323D2D302E3034200A23
length: 134
<=>€#408421092#node_01#149#STR:Humedad 1=-0.04 & Humedad2=-0.04 
#
Create a new Frame:
===============================
Current ASCII Frame:
Length: 98
Frame Type:  128
frame (HEX): 3C3D3E800123343038353230323438236E6F64655F30312331235354523A3C3D3E80015F3430383432313039325F6E6F64655F30315F3134395F5354523A48756D6564616420313D2D302E303420262048756D65646164323D2D302E3034200A5F23
frame (STR): <=>€#408520248#node_01#1#STR:<=>€_408421092_node_01_149_STR:Humedad 1=-0.04 & Humedad2=-0.04 
_#
===============================
Packet sent OK

Then, in the menu: Sensors Network in Meshlium Lora. don't appear the data.

Help me please.

Regards

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Problem sent frame SX1272- Meshlium

Post by libelium-dev » Mon Oct 17, 2016 11:37 am

Hi,

Could you test the basic example code to send data to meshlium with lora? Is Meshlium showing the data received?

Regards.

pablo_chumacero
Posts: 18
Joined: Sat Mar 19, 2016 12:58 am

Re: Problem sent frame SX1272- Meshlium

Post by pablo_chumacero » Tue Oct 18, 2016 2:44 am

libelium-dev wrote:Hi,

Could you test the basic example code to send data to meshlium with lora? Is Meshlium showing the data received?

Regards.
Hi,

I did the basic example code and the meshlium showed the data for example battery level.

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Problem sent frame SX1272- Meshlium

Post by libelium-dev » Tue Oct 18, 2016 10:07 am

Hi,

You attempt that the frame doesn't have line break
<=>€#408421092#node_01#149#STR:Humedad 1=-0.04 & Humedad2=-0.04
#
Hope this solve the issue.
Regards.

pablo_chumacero
Posts: 18
Joined: Sat Mar 19, 2016 12:58 am

Re: Problem sent frame SX1272- Meshlium

Post by pablo_chumacero » Wed Oct 19, 2016 7:09 am

libelium-dev wrote:Hi,

You attempt that the frame doesn't have line break
<=>€#408421092#node_01#149#STR:Humedad 1=-0.04 & Humedad2=-0.04
#
Hope this solve the issue.
Regards.
Ok, but how do I make a line break?

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Problem sent frame SX1272- Meshlium

Post by libelium-dev » Wed Oct 19, 2016 9:32 am

Hi,

It looks like the lorawan module recives the frame with a line break. You try that the frame sent by the other lorawan module doesn't include the line break.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest