From 206ee3431bb92c646924aced8b21726a866efb8e Mon Sep 17 00:00:00 2001 From: capboyaryan <96912152+capboyaryan@users.noreply.github.com> Date: Fri, 21 Jul 2023 18:29:19 +0530 Subject: [PATCH 1/2] Added support for IN_865 --- src/arduino-rfm/Config.h | 3 +- src/arduino-rfm/LoRaMAC.cpp | 11 +++++++ src/arduino-rfm/RFM95.cpp | 39 +++++++++++++++++++++++-- src/arduino-rfm/Struct.h | 11 +++++++ src/arduino-rfm/lorawan-arduino-rfm.cpp | 7 +++++ 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/src/arduino-rfm/Config.h b/src/arduino-rfm/Config.h index c7b2041..0b3ea6a 100644 --- a/src/arduino-rfm/Config.h +++ b/src/arduino-rfm/Config.h @@ -7,12 +7,13 @@ //#define EU_868 //#define US_915 //#define AU_915 +#define IN_865 // Define max payload size used for this node #define MAX_UPLINK_PAYLOAD_SIZE 220 #define MAX_DOWNLINK_PAYLOAD_SIZE 220 -#if !defined(AS_923) && !defined(AS_923_2) && !defined(EU_868) && !defined(US_915) && !defined(AU_915) +#if !defined(AS_923) && !defined(AS_923_2) && !defined(EU_868) && !defined(US_915) && !defined(AU_915) &&!defined(IN_865) #define US_915 // Define default Region #endif diff --git a/src/arduino-rfm/LoRaMAC.cpp b/src/arduino-rfm/LoRaMAC.cpp index b0e9e4c..b9ad12f 100644 --- a/src/arduino-rfm/LoRaMAC.cpp +++ b/src/arduino-rfm/LoRaMAC.cpp @@ -77,6 +77,8 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command, unsigned char rx1_dr = LoRa_Settings->Datarate_Tx+10; #elif defined(EU_868) unsigned char rx1_dr = LoRa_Settings->Datarate_Tx; + #elif defined(IN_865) + unsigned char rx1_dr = LoRa_Settings->Datarate_Tx; #else // AS_923 and AS_923_2 unsigned char rx1_dr = LoRa_Settings->Datarate_Tx; #endif @@ -103,6 +105,9 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command, #elif defined(EU_868) LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 923.3 MHZ LoRa_Settings->Datarate_Rx = SF12BW125; //set RX2 datarate 12 + #elif defined(IN_865) + LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 866.550 MHZ + LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10 #elif defined(AS_923) || defined(AS_923_2) LoRa_Settings->Channel_Rx = 0x00; // set Rx2 channel 923.2 (AS_923) or 921.4 (AS_923_2) LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10 @@ -141,6 +146,9 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command, #elif defined(EU_868) LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 923.3 MHZ LoRa_Settings->Datarate_Rx = SF12BW125; //set RX2 datarate 12 + #elif defined(IN_865) + LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 866.550 MHZ + LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10 #elif defined(AS_923) || defined(AS_923_2) LoRa_Settings->Channel_Rx = 0x00; // set Rx2 channel 923.2 (AS_923) or 921.4 (AS_923_2) LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10 @@ -166,6 +174,9 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command, #elif defined(EU_868) LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 923.3 MHZ LoRa_Settings->Datarate_Rx = SF12BW125; //set RX2 datarate 12 + #elif defined(IN_865) + LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 866.550 MHZ + LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10 #elif defined(AS_923) || defined(AS_923_2) LoRa_Settings->Channel_Rx = 0x00; // set Rx2 channel 923.2 (AS_923) or 921.4 (AS_923_2) LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10 diff --git a/src/arduino-rfm/RFM95.cpp b/src/arduino-rfm/RFM95.cpp index e0193eb..6204ae7 100644 --- a/src/arduino-rfm/RFM95.cpp +++ b/src/arduino-rfm/RFM95.cpp @@ -270,6 +270,13 @@ { 0xD8, 0xF9, 0xBE }, //Channel [7], 867.9 MHz / 61.035 Hz = 14219710 = 0xD8F9BE { 0xD9, 0x61, 0xBE }, // RX2 Receive channel 869.525 MHz / 61.035 Hz = 14246334 = 0xD961BE }; +#elif defined(IN_865) + static const PROGMEM unsigned char LoRa_Frequency[4][3] = { + { 0xD8, 0x44, 0x24 }, //Channel [0], 865.0625 MHz / 61.035 Hz = 14173220 = 0xD84424 + { 0xD8, 0x59, 0xE7 }, //Channel [1], 865.4025 MHz / 61.035 Hz = 14178791 = 0xD859E7 + { 0xD8, 0x7F, 0x2F }, //Channel [2], 865.9850 MHz / 61.035 Hz = 14188335 = 0xD87F2F + { 0xD8, 0xA3, 0x58 }, // RX2 Receive channel 866.550 MHz / 61.035 Hz = 14197592 = 0xD8A358 + }; #endif /* @@ -326,7 +333,7 @@ static void RFM_change_SF_BW(unsigned char _SF, unsigned char _BW) RFM_Write(RFM_REG_MODEM_CONFIG2, (_SF << 4) | 0b0100); //SFx CRC On RFM_Write(RFM_REG_MODEM_CONFIG1,(_BW << 4) | 0x02); //x kHz 4/5 coding rate explicit header mode - #ifdef EU_868 + #if defined(EU_868) || defined(IN_865) if(_SF>10) RFM_Write(RFM_REG_MODEM_CONFIG3, 0b1100); //Low datarate optimization on AGC auto on else @@ -418,6 +425,27 @@ static void RFM_Change_Datarate(unsigned char Datarate) RFM_change_SF_BW(7,0x09); break; } +#elif defined(IN_865) + switch (Datarate) { + case 0x00: // SF12BW125 + RFM_change_SF_BW(12,0x07); + break; + case 0x01: // SF11BW125 + RFM_change_SF_BW(11,0x07); + break; + case 0x02: // SF10BW125 + RFM_change_SF_BW(10,0x07); + break; + case 0x03: // SF9BW125 + RFM_change_SF_BW(9,0x07); + break; + case 0x04: // SF8BW125 + RFM_change_SF_BW(8,0x07); + break; + case 0x05: // SF7BW125 + RFM_change_SF_BW(7,0x07); + break; + } #else //EU_868 or AS_923 or AS_923_2 switch (Datarate) { case 0x00: // SF12BW125 @@ -466,6 +494,10 @@ static void RFM_Change_Channel(unsigned char Channel) if (Channel <= 0x08) for(unsigned char i = 0 ; i < 3 ; ++i) RFM_Write(RFM_REG_FR_MSB + i, pgm_read_byte(&(LoRa_Frequency[Channel][i]))); +#elif defined(IN_865) + if( Channel <= 0x03) + for(unsigned char i = 0 ; i < 3 ; ++i) + RFM_Write(RFM_REG_FR_MSB + i, pgm_read_byte(&(LoRa_Frequency[Channel][i]))); #else //US915 or AU_915 if (Channel <= 0x07) for(unsigned char i = 0 ; i < 3 ; ++i) @@ -711,9 +743,12 @@ void RFM_Continuous_Receive(sSettings *LoRa_Settings) //Change Datarate and channel. // This depends on regional parameters -#ifdef EU_868 +#if defined(EU_868) RFM_Change_Datarate(SF12BW125); RFM_Change_Channel(CHRX2); +#elif defined(IN_865) + RFM_Change_Datarate(SF10BW125); + RFM_Change_Channel(CHRX2); #else //Datarate for downlink should be 8 but testing on 10 //LoRa_Settings->Datarate_Rx=10; diff --git a/src/arduino-rfm/Struct.h b/src/arduino-rfm/Struct.h index f9a02fa..f59cec5 100644 --- a/src/arduino-rfm/Struct.h +++ b/src/arduino-rfm/Struct.h @@ -100,13 +100,17 @@ typedef enum { CH0 = 0, CH1 = 1, CH2 = 2, +#ifndef IN_865 //IN_865 only supports 3 channels CH3 = 3, CH4 = 4, CH5 = 5, CH6 = 6, CH7 = 7, +#endif #ifdef EU_868 CHRX2 = 8, +#elif defined(IN_865) + CHRX2 = 3, #else CH8 = 8, #endif @@ -158,6 +162,13 @@ typedef enum { SF8BW125 = 0x04, SF7BW125 = 0x05, SF7BW250 = 0x06 +#elif defined(IN_865) + SF12BW125 = 0x00, + SF11BW125 = 0x01, + SF10BW125 = 0x02, + SF9BW125 = 0x03, + SF8BW125 = 0x04, + SF7BW125 = 0x05 #endif } dataRates_t; diff --git a/src/arduino-rfm/lorawan-arduino-rfm.cpp b/src/arduino-rfm/lorawan-arduino-rfm.cpp index 3be6f0b..551511d 100644 --- a/src/arduino-rfm/lorawan-arduino-rfm.cpp +++ b/src/arduino-rfm/lorawan-arduino-rfm.cpp @@ -88,6 +88,8 @@ bool LoRaWANClass::init(void) LoRa_Settings.Datarate_Rx = 0x02; //set to SF10 BW 125 kHz #elif defined(EU_868) LoRa_Settings.Datarate_Rx = 0x03; //set to SF9 BW 125 kHz +#elif defined(IN_865) + LoRa_Settings.Datarate_Rx = 0x02; //set to SF10 BW 125 kHz #else //US_915 or AU_915 LoRa_Settings.Datarate_Rx = 0x0C; //set to SF8 BW 500 kHz #endif @@ -347,6 +349,8 @@ void LoRaWANClass::setChannel(unsigned char channel) LoRa_Settings.Channel_Rx = channel + 0x08; #elif defined(EU_868) LoRa_Settings.Channel_Rx = channel; +#elif defined(IN_865) + LoRa_Settings.Channel_Rx = channel; #elif defined(AS_923) || defined(AS_923_2) LoRa_Settings.Channel_Rx = channel; #endif @@ -468,6 +472,9 @@ void LoRaWANClass::randomChannel() #elif defined(EU_868) freq_idx = random(0,8); LoRa_Settings.Channel_Rx=freq_idx; // same rx and tx channel +#elif defined(IN_865) + freq_idx = random(0,4); + LoRa_Settings.Channel_Rx=freq_idx; // same rx and tx channel #else // US_915 or AU_915 freq_idx = random(0, 8); LoRa_Settings.Channel_Rx = freq_idx + 0x08; From 77536c9f1f63592ea299aa93730964f9d826db5f Mon Sep 17 00:00:00 2001 From: capboyaryan <96912152+capboyaryan@users.noreply.github.com> Date: Sun, 23 Jul 2023 23:43:56 +0530 Subject: [PATCH 2/2] Corrected range of channels used --- src/arduino-rfm/lorawan-arduino-rfm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arduino-rfm/lorawan-arduino-rfm.cpp b/src/arduino-rfm/lorawan-arduino-rfm.cpp index 551511d..8db56b6 100644 --- a/src/arduino-rfm/lorawan-arduino-rfm.cpp +++ b/src/arduino-rfm/lorawan-arduino-rfm.cpp @@ -473,7 +473,7 @@ void LoRaWANClass::randomChannel() freq_idx = random(0,8); LoRa_Settings.Channel_Rx=freq_idx; // same rx and tx channel #elif defined(IN_865) - freq_idx = random(0,4); + freq_idx = random(0,3); LoRa_Settings.Channel_Rx=freq_idx; // same rx and tx channel #else // US_915 or AU_915 freq_idx = random(0, 8);