Hi,
i am trying to receive plain LoRa packets from a soil moisture sensor.
I minimized the pingpong sketch to just receive the packets to this:
/* Heltec Automation Ping Pong communication test example
*
- Function:
-
- Ping Pong communication in two CubeCell device.
- Description:
-
- Only hardware layer communicate, no LoRaWAN protocol support;
-
- Download the same code into two CubeCell devices, then they will begin Ping Pong test each other;
-
- This example is for CubeCell hardware basic test.
- HelTec AutoMation, Chengdu, China
- 成都惠利特自动化科技有限公司
- www.heltec.org
- this project also realess in GitHub:
- https://github.com/HelTecAutomation/ASR650x-Arduino
- */
#include “LoRaWan_APP.h”
#include “Arduino.h”
/*
- set LoraWan_RGB to 1,the RGB active in loraWan
- RGB red means sending;
- RGB green means received done;
*/
#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif
#define RF_FREQUENCY 868000000 // Hz
#define TX_OUTPUT_POWER 5 // dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 9 // [SF7…SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 30 // Define the payload size here
char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];
static RadioEvents_t RadioEvents;
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
typedef enum
{
LOWPOWER,
RX,
TX
}States_t;
int16_t txNumber;
States_t state;
bool sleepMode = false;
int16_t Rssi,rxSize;
void setup() {
Serial.begin(115200);
txNumber=0;
Rssi=0;
RadioEvents.RxDone = OnRxDone;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
0, true, 0, 0, LORA_IQ_INVERSION_ON, true );
state=RX;
}
void loop()
{
Serial.print("State: ");
Serial.println(state);
switch(state)
{
case TX:
Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );
break;
case RX:
Serial.println(“into RX mode”);
Radio.Rx( 0 );
state=LOWPOWER;
break;
case LOWPOWER:
lowPowerHandler();
break;
default:
break;
}
Radio.IrqProcess( );
}
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
Rssi=rssi;
rxSize=size;
memcpy(rxpacket, payload, size );
rxpacket[size]=’\0’;
turnOnRGB(COLOR_RECEIVED,0);
Radio.Sleep( );
Serial.printf("\r\nreceived packet \"%s\" with Rssi %d , length %d\r\n",rxpacket,Rssi,rxSize);
Serial.println("wait to send next packet");
state=RX;
}
It works fine and i get the packages:
13:46:32.334 -> into RX mode
13:47:27.063 ->
13:47:27.063 -> received packet “ID010132 REPLY : SOIL INEDX:0 H:43.72 T:23.85 ADC:877 BAT:892” with Rssi -31 , length 61
13:47:27.100 -> wait to send next packet
13:47:27.100 -> State: 1
13:47:27.100 -> into RX mode
But now comes the part which i don’t understand.
When i comment out this line like this it doesn’t work anymore:
case TX:
// Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );
break;
What kind of magic is this? The TX state should never been reached?
Greetings
Olaf