Created
October 28, 2021 16:56
-
-
Save bshambaugh/f9bf79b9fd2d9e2ef6c8efcbb8ecb90d to your computer and use it in GitHub Desktop.
CubeCell Receiving from ESP32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Heltec Automation Receive communication test example | |
* | |
* Function: | |
* 1. Receive the same frequency band lora signal program | |
* | |
* | |
* 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 915000000 // Hz | |
#define TX_OUTPUT_POWER 14 // 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 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 200 // Define the payload size here | |
char txpacket[BUFFER_SIZE]; | |
char rxpacket[BUFFER_SIZE]; | |
static RadioEvents_t RadioEvents; | |
int16_t txNumber; | |
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 ); | |
turnOnRGB(COLOR_SEND,0); //change rgb color | |
Serial.println("into RX mode"); | |
} | |
void loop() | |
{ | |
Radio.Rx( 0 ); | |
delay(500); | |
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); | |
} |
void loop()
{
Radio.Rx( 0 );
delay(500);
Radio.IrqProcess( );
printf("\r\n dummy packet "%s" \r\n",rxpacket);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
printf("\r\n dummy packet "%s" \r\n",dummypacket); in void loop().