Hi, I am trying to send a packet through Serial monitor i.e. UART which is of length 366 character from one esp32(acting as trnasmitter) to another esp32(acting as receiver) . But at the receiver end i am only receiving a packet of lenth 110 characters. Any suggestions? Please find the code below:
Transmitter:
#include <ArduinoJson.h>
#include <ESP32_LoRaWAN.h>
#include “Arduino.h”
#define RF_FREQUENCY 915000000 // Hz
#define TX_OUTPUT_POWER 20 // dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7…SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 1000 // 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 1000// Define the payload size here
char txpacket[BUFFER_SIZE];
String receive_buffer;
static RadioEvents_t RadioEvents;
void OnTxDone( void );
void OnTxTimeout( void );
typedef enum
{
STATUS_LOWPOWER,
STATUS_TX
}States_t;
int16_t txNumber;
States_t state;
bool sleepMode = false;
int16_t Rssi,rxSize;
uint32_t license[4] = {0x7233B70B, 0x0353AFAA, 0x90FDB660, 0x8F4B092C};
// Add your initialization code here
void setup()
{
Serial.begin(115200);
while (!Serial);
SPI.begin(SCK,MISO,MOSI,SS);
Mcu.init(SS,RST_LoRa,DIO0,DIO1,license);
txNumber=0;
Rssi=0;
RadioEvents.TxDone = OnTxDone;
RadioEvents.TxTimeout = OnTxTimeout;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
LORA_SPREADING_FACTOR, LORA_CODINGRATE,
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );
state=STATUS_TX;
}
void loop()
{
if(Serial.available()>0)
{
receive_buffer = Serial.readString();
receive_buffer.toCharArray(txpacket,1000);
Serial.println("Arduino received following string: ");
Serial.println(receive_buffer);
}
switch(state)
{
case STATUS_TX:
delay(1000);
txNumber++;
/sprintf(txpacket,"%s",“hello-COM3”);
sprintf(txpacket+strlen(txpacket),"%d",txNumber);
sprintf(txpacket+strlen(txpacket),"%s"," Rssi : “);
sprintf(txpacket+strlen(txpacket),”%d",Rssi);/
Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket));
Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );
state=STATUS_LOWPOWER;
break;
case STATUS_LOWPOWER:
LoRaWAN.sleep(CLASS_C,0);
break;
default:
break;
}
}
void OnTxDone( void )
{
// Serial.print(“TX done…”);
state=STATUS_TX;
}
void OnTxTimeout( void )
{
Radio.Sleep( );
// Serial.print(“TX Timeout…”);
state=STATUS_TX;
}
Receiver:
#include <ArduinoJson.h>
#include <ESP32_LoRaWAN.h>
#include “Arduino.h”
#include <LoRa.h>
#define RF_FREQUENCY 915000000 // Hz
#define TX_OUTPUT_POWER 20 // dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7…SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 1000 // 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 500 // Define the payload size here
char rxpacket[BUFFER_SIZE];
static RadioEvents_t RadioEvents;
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
typedef enum
{
STATUS_LOWPOWER,
STATUS_RX
}States_t;
int16_t txNumber;
States_t state;
bool sleepMode = false;
int16_t Rssi,rxSize;
uint32_t license[4] = {0x2354A73D, 0x73764032, 0x3E2BAA46, 0xC26155CE};
// Add your initialization code here
void setup()
{
Serial.begin(115200);
while (!Serial);
SPI.begin(SCK,MISO,MOSI,SS);
Mcu.init(SS,RST_LoRa,DIO0,DIO1,license);
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=STATUS_RX;
}
void loop()
{
switch(state)
{
case STATUS_RX:
Serial.println(“into RX mode”);
Radio.Rx( 0 );
state=STATUS_LOWPOWER;
break;
case STATUS_LOWPOWER:
LoRaWAN.sleep(CLASS_C,0);
break;
default:
break;
}
}
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
// int packetSize = LoRa.parsePacket();
Rssi=rssi;
rxSize=size;
memcpy(rxpacket, payload, rxSize );
rxpacket[size]=’\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=STATUS_RX;
}
Data I am trying to send:
{‘timestamp’: 2022-04-15 16:57:09’,‘sensors’: {‘id’: ‘CAMERA_ID’,‘type’: ‘Camera’,‘description’: ‘‘XYZ lab’’,‘location’: {‘lat’:39.25,‘lon’: -76.71,‘alt’: 48.15},‘networkdetails’:{‘status’: ‘up’},‘objects’: [{‘id’: ‘0’,‘description’:’+word[0]+’,‘type’: ‘static’,‘confidence’:’+word[x]+’,‘location’: {‘lat’: 0,‘lon’: 0,‘alt’: 0},‘videoPath’: ‘’,‘image’: ‘’}]}}