Skip to content

Commit

Permalink
Cleaned up ABP code. Removed setting all 72 channels. Added frequenci…
Browse files Browse the repository at this point in the history
…es, max power, and data rates for all TTN-supported country codes. Updated README.md.

Signed-off-by: Brady <brady.aiello@gmail.com>
  • Loading branch information
brady-aiello committed Nov 8, 2017
1 parent 47c7e9e commit 7382bb0
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Seeeduino/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Seeeduino-LoRaWAN-example



These examples are meant for connecting a Seeeduino-LoRaWAN (with or without GPS) to a LoRaWAN gateway running the "The Things Network" packet forwarder (the new one using TCP and written in Go, here: https://github.com/TheThingsNetwork/packet_forwarder).

This project assumes that you are using a "hybrid" LoRaWAN gateway. A full gateway uses a Chirp Spread Spectrum (CSS) modulation on 64 channels, and costs a lot of money. In a hybrid gateway, only a few of the channels are used. Though the Seeeduino LoRaWAN can broadcast in full LoRa style (all 64 channels), most of us don't have enough money for a gateway that can afford to listen on 64 channels. If you're tried sample code from Seeeduino and are wondering why it didn't work reliably, it is because of this Seeeduino transmitting / gateway listening assymetry.

It has only been tested with the US plan running on a RisingHF + Raspberry Pi gateway, which can listen on 8 channels. I have also included additional frequency plans for other countries, referring both to TTN's gateway configuration files (here: https://github.com/TheThingsNetwork/gateway-conf) as well as the latest AT Command Specification for RisingHF's RHF76-052 chip, which I've uploaded on TTN's forum, here: (https://www.thethingsnetwork.org/forum/uploads/default/original/2X/3/3995d6855260b7c36ff9ae19748aa527701c59a6.pdf).

If you live outside the US, and are able to get your Seeeduino to work reliably on The Things Network, please let me know, so we can document that it works, or pull in your working code, to reflect your experiments.
126 changes: 126 additions & 0 deletions Seeeduino/Seeeduino_LoRaWAN_ABP/Seeeduino_LoRaWAN_ABP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include "LoRaWan.h"
#include "keys.h"

#define US_FREQ_RX_WNDW_SCND 923.3
//#define EU_FREQ_RX_WNDW_SCND 869.525
//#define AU_FREQ_RX_WNDW_SCND 923.3
//#define CN_FREQ_RX_WNDW_SCND 505.3
//#define KR_FREQ_RX_WNDW_SCND 923.3
//#define IN_FREQ_RX_WNDW_SCND 866.55
//#define AS1_FREQ_RX_WNDW_SCND 923.3
//#define AS2_FREQ_RX_WNDW_SCND 923.3

const float US_hybrid_channels[8] = {903.9, 904.1, 904.3, 904.5, 904.7, 904.9, 905.1, 905.3}; //rx 923.3
//const float EU_hybrid_channels[8] = {868.1, 868.3, 868.5, 867.1, 867.3, 867.5, 867.7, 867.9}; //rx 869.525
//const float AU_hybrid_channels[8] = {916.8, 917.0, 917.2, 917.4, 917.6, 917.8, 918.0, 918.2}; //rx 923.3
//const float CN_hybrid_channels[8] = {487.1, 487.3, 487.5, 487.7, 486.3, 486.5, 486.7, 486.9}; //rx 505.3
//const float KR_hybrid_channels[8] = {922.1, 922.3, 922.5, 922.7, 922.9, 923.1, 923.3, 0}; //rx 921.9
//
//const float IN_hybrid_channels[8] = {865.0625, 865.4025, 865.9850, 0, 0, 0, 0, 0}; //rx 866.55
//
//const float AS1_hybrid_channels[8] = {923.2, 923.4, 922.2, 922.4, 922.6, 922.8, 923.0, 922.1}; //rx 923.2
//const float AS2_hybrid_channels[8] = {923.2, 923.4, 923.6, 923.8, 924.0, 924.2, 924.4, 924.6}; //rx 923.2

//United States Receive Window Data Rate = DR8
#define US_RX_DR DR8
//#define EU_RX_DR DR8
//#define AU_RX_DR DR8
//#define CN_RX_DR DR0
//#define KR_RX_DR DR0
//#define IN_RX_DR DR2
//#define AS1_RX_DR DR2
//#define AS2_RX_DR DR2

#define US_MAX_EIRP_NDX 13
//#define EU_MAX_EIRP_NDX 2
//#define AU_MAX_EIRP_NDX 13
//#define CN_MAX_EIRP_NDX 7
//#define KR_MAX_EIRP_NDX 4
//#define IN_MAX_EIRP_NDX 13
//#define AS1_MAX_EIRP_NDX 5
//#define AS2_MAX_EIRP_NDX 5

unsigned char frame_counter = 1;
char buffer[256];


void setup(void)
{
SerialUSB.begin(115200);
while(!SerialUSB);

lora.init();
lora.setDeviceDefault();

memset(buffer, 0, 256);
lora.getVersion(buffer, 256, 1);
SerialUSB.print(buffer);

memset(buffer, 0, 256);
lora.getId(buffer, 256, 1);
SerialUSB.print(buffer);

//void setId(char *DevAddr, char *DevEUI, char *AppEUI);
//void setKey(char *NwkSKey, char *AppSKey, char *AppKey);

lora.setId(DEV_ADDR, DEV_EUI, APP_EUI);
lora.setKey(NWK_S_KEY, APP_S_KEY, APP_KEY);

lora.setDeciveMode(LWABP);
lora.setDataRate(DR0, US915HYBRID);
lora.setPower(US_MAX_EIRP_NDX);

//for(uint8_t i = 8; i < 72; i ++)lora.setChannel(i, 0);
setHybridForTTN(US_hybrid_channels);

lora.setReceiceWindowFirst(1);
lora.setReceiceWindowSecond(923.3, US_RX_DR);

//lora.setPower(14);
//lora.setPower(US_MAX_EIRP_NDX);
}

void setHybridForTTN(const float* channels){

for(int i = 0; i < 8; i++){
// DR0 is the min data rate
// US_RX_DR = DR3 is the max data rate for the US
if(channels[i] != 0){
lora.setChannel(i, channels[0], DR0, DR3);
}
}
}
void loop(void)
{
bool result = lora.transferPacket(&frame_counter, 1, 5);

if(result)
{
delay(50);
frame_counter++;
short length;
short rssi;

memset(buffer, 0, 256);
length = lora.receivePacket(buffer, 256, &rssi);

if(length)
{
SerialUSB.print("Length is: ");
SerialUSB.println(length);
SerialUSB.print("RSSI is: ");
SerialUSB.println(rssi);
SerialUSB.print("Data is: ");
for(unsigned char i = 0; i < length; i ++)
{
SerialUSB.print("0x");
SerialUSB.print(buffer[i], HEX);
SerialUSB.print(" ");
}
SerialUSB.println();
}
}

lora.loraDebug();
delay(1000);
}
7 changes: 7 additions & 0 deletions Seeeduino/Seeeduino_LoRaWAN_ABP/keys_generic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define DEV_ADDR "Your Device Address"
#define DEV_EUI "Your Device EUI"
#define APP_EUI "Your App EUI"

#define NWK_S_KEY "Your Network Session Key"
#define APP_S_KEY "Your App Session Key"
#define APP_KEY "Your App Key"

0 comments on commit 7382bb0

Please sign in to comment.