Commit ee67b5ae871b13882222fc829ff0f6db3c57ac0b
1 parent
73408d11
Support for SX1276/RFM95W
Showing
2 changed files
with
57 additions
and
26 deletions
Show diff stats
README.md
@@ -4,7 +4,7 @@ This repository contains a proof-of-concept implementation of a single | @@ -4,7 +4,7 @@ This repository contains a proof-of-concept implementation of a single | ||
4 | channel LoRaWAN gateway. | 4 | channel LoRaWAN gateway. |
5 | 5 | ||
6 | It has been tested on the Raspberry Pi platform, using a Semtech SX1272 | 6 | It has been tested on the Raspberry Pi platform, using a Semtech SX1272 |
7 | -transceiver (HopeRF RFM92W). | 7 | +transceiver (HopeRF RFM92W), and SX1276 (HopeRF RFM95W). |
8 | 8 | ||
9 | The code is for testing and development purposes only, and is not meant | 9 | The code is for testing and development purposes only, and is not meant |
10 | for production usage. | 10 | for production usage. |
@@ -23,7 +23,6 @@ Features | @@ -23,7 +23,6 @@ Features | ||
23 | 23 | ||
24 | Not (yet) supported: | 24 | Not (yet) supported: |
25 | - PACKET_PUSH_ACK processing | 25 | - PACKET_PUSH_ACK processing |
26 | -- SX1276 | ||
27 | - SF7BW250 modulation | 26 | - SF7BW250 modulation |
28 | - FSK modulation | 27 | - FSK modulation |
29 | - downstream messages (tx) | 28 | - downstream messages (tx) |
@@ -48,7 +47,7 @@ MOSI - MOSI (pin #19) | @@ -48,7 +47,7 @@ MOSI - MOSI (pin #19) | ||
48 | SCK - CLK (pin #23) | 47 | SCK - CLK (pin #23) |
49 | NSS - GPIO6 (pin #22) | 48 | NSS - GPIO6 (pin #22) |
50 | DIO0 - GPIO7 (pin #7) | 49 | DIO0 - GPIO7 (pin #7) |
51 | -RST - GPIO0 (in #11) | 50 | +RST - GPIO0 (pin #11) |
52 | 51 | ||
53 | Configuration | 52 | Configuration |
54 | ------------- | 53 | ------------- |
main.cpp
@@ -40,6 +40,8 @@ byte currentMode = 0x81; | @@ -40,6 +40,8 @@ byte currentMode = 0x81; | ||
40 | char message[256]; | 40 | char message[256]; |
41 | char b64[256]; | 41 | char b64[256]; |
42 | 42 | ||
43 | +bool sx1272 = true; | ||
44 | + | ||
43 | byte receivedbytes; | 45 | byte receivedbytes; |
44 | 46 | ||
45 | struct sockaddr_in si_other; | 47 | struct sockaddr_in si_other; |
@@ -77,9 +79,9 @@ float lon=0.0; | @@ -77,9 +79,9 @@ float lon=0.0; | ||
77 | int alt=0; | 79 | int alt=0; |
78 | 80 | ||
79 | /* Informal status fields */ | 81 | /* Informal status fields */ |
80 | -static char platform[24] = "SX1272"; /* platform definition */ | ||
81 | -static char email[40] = ""; /* used for contact email */ | ||
82 | -static char description[64] = ""; /* used for free form description */ | 82 | +static char platform[24] = "Single Channel Gateway"; /* platform definition */ |
83 | +static char email[40] = ""; /* used for contact email */ | ||
84 | +static char description[64] = ""; /* used for free form description */ | ||
83 | 85 | ||
84 | // define servers | 86 | // define servers |
85 | // TODO: use host names and dns | 87 | // TODO: use host names and dns |
@@ -102,6 +104,7 @@ static char description[64] = ""; /* used for free form description */ | @@ -102,6 +104,7 @@ static char description[64] = ""; /* used for free form description */ | ||
102 | #define REG_DIO_MAPPING_2 0x41 | 104 | #define REG_DIO_MAPPING_2 0x41 |
103 | #define REG_MODEM_CONFIG 0x1D | 105 | #define REG_MODEM_CONFIG 0x1D |
104 | #define REG_MODEM_CONFIG2 0x1E | 106 | #define REG_MODEM_CONFIG2 0x1E |
107 | +#define REG_MODEM_CONFIG3 0x26 | ||
105 | #define REG_SYMB_TIMEOUT_LSB 0x1F | 108 | #define REG_SYMB_TIMEOUT_LSB 0x1F |
106 | #define REG_PKT_SNR_VALUE 0x19 | 109 | #define REG_PKT_SNR_VALUE 0x19 |
107 | #define REG_PAYLOAD_LENGTH 0x22 | 110 | #define REG_PAYLOAD_LENGTH 0x22 |
@@ -237,18 +240,34 @@ boolean receivePkt(char *payload) | @@ -237,18 +240,34 @@ boolean receivePkt(char *payload) | ||
237 | 240 | ||
238 | void SetupLoRa() | 241 | void SetupLoRa() |
239 | { | 242 | { |
243 | + | ||
244 | + digitalWrite(RST, HIGH); | ||
245 | + delay(100); | ||
246 | + digitalWrite(RST, LOW); | ||
247 | + delay(100); | ||
240 | 248 | ||
241 | byte version = readRegister(REG_VERSION); | 249 | byte version = readRegister(REG_VERSION); |
242 | - if (version == 0x12) { | ||
243 | - // sx1276 | ||
244 | - printf("SX1276 transceiver not yet supported.\n"); | ||
245 | - exit(1); | ||
246 | - } else if (version == 0x22) { | 250 | + |
251 | + if (version == 0x22) { | ||
247 | // sx1272 | 252 | // sx1272 |
248 | printf("SX1272 detected, starting.\n"); | 253 | printf("SX1272 detected, starting.\n"); |
254 | + sx1272 = true; | ||
249 | } else { | 255 | } else { |
250 | - printf("Unrecognized transceiver.\n"); | ||
251 | - exit(1); | 256 | + // sx1276? |
257 | + digitalWrite(RST, LOW); | ||
258 | + delay(100); | ||
259 | + digitalWrite(RST, HIGH); | ||
260 | + delay(100); | ||
261 | + version = readRegister(REG_VERSION); | ||
262 | + if (version == 0x12) { | ||
263 | + // sx1276 | ||
264 | + printf("SX1276 detected, starting.\n"); | ||
265 | + sx1272 = false; | ||
266 | + } else { | ||
267 | + printf("Unrecognized transceiver.\n"); | ||
268 | + //printf("Version: 0x%x\n",version); | ||
269 | + exit(1); | ||
270 | + } | ||
252 | } | 271 | } |
253 | 272 | ||
254 | writeRegister(REG_OPMODE, SX72_MODE_SLEEP); | 273 | writeRegister(REG_OPMODE, SX72_MODE_SLEEP); |
@@ -261,12 +280,22 @@ void SetupLoRa() | @@ -261,12 +280,22 @@ void SetupLoRa() | ||
261 | 280 | ||
262 | writeRegister(REG_SYNC_WORD, 0x34); // LoRaWAN public sync word | 281 | writeRegister(REG_SYNC_WORD, 0x34); // LoRaWAN public sync word |
263 | 282 | ||
264 | - if (sf == SF11 || sf == SF12) { | ||
265 | - writeRegister(REG_MODEM_CONFIG,0x0B); | 283 | + if (sx1272) { |
284 | + if (sf == SF11 || sf == SF12) { | ||
285 | + writeRegister(REG_MODEM_CONFIG,0x0B); | ||
286 | + } else { | ||
287 | + writeRegister(REG_MODEM_CONFIG,0x0A); | ||
288 | + } | ||
289 | + writeRegister(REG_MODEM_CONFIG2,(sf<<4) | 0x04); | ||
266 | } else { | 290 | } else { |
267 | - writeRegister(REG_MODEM_CONFIG,0x0A); | 291 | + if (sf == SF11 || sf == SF12) { |
292 | + writeRegister(REG_MODEM_CONFIG3,0x0C); | ||
293 | + } else { | ||
294 | + writeRegister(REG_MODEM_CONFIG3,0x04); | ||
295 | + } | ||
296 | + writeRegister(REG_MODEM_CONFIG,0x072); | ||
297 | + writeRegister(REG_MODEM_CONFIG2,(sf<<4) | 0x04); | ||
268 | } | 298 | } |
269 | - writeRegister(REG_MODEM_CONFIG2,(sf<<4) | 0x04); | ||
270 | 299 | ||
271 | if (sf == SF10 || sf == SF11 || sf == SF12) { | 300 | if (sf == SF10 || sf == SF11 || sf == SF12) { |
272 | writeRegister(REG_SYMB_TIMEOUT_LSB,0x05); | 301 | writeRegister(REG_SYMB_TIMEOUT_LSB,0x05); |
@@ -350,6 +379,7 @@ void sendstat() { | @@ -350,6 +379,7 @@ void sendstat() { | ||
350 | void receivepacket() { | 379 | void receivepacket() { |
351 | 380 | ||
352 | long int SNR; | 381 | long int SNR; |
382 | + int rssicorr; | ||
353 | 383 | ||
354 | if(digitalRead(dio0) == 1) | 384 | if(digitalRead(dio0) == 1) |
355 | { | 385 | { |
@@ -366,8 +396,15 @@ void receivepacket() { | @@ -366,8 +396,15 @@ void receivepacket() { | ||
366 | // Divide by 4 | 396 | // Divide by 4 |
367 | SNR = ( value & 0xFF ) >> 2; | 397 | SNR = ( value & 0xFF ) >> 2; |
368 | } | 398 | } |
369 | - printf("Packet RSSI: %d, ",readRegister(0x1A)-139); | ||
370 | - printf("RSSI: %d, ",readRegister(0x1B)-139); | 399 | + |
400 | + if (sx1272) { | ||
401 | + rssicorr = 139; | ||
402 | + } else { | ||
403 | + rssicorr = 157; | ||
404 | + } | ||
405 | + | ||
406 | + printf("Packet RSSI: %d, ",readRegister(0x1A)-rssicorr); | ||
407 | + printf("RSSI: %d, ",readRegister(0x1B)-rssicorr); | ||
371 | printf("SNR: %li, ",SNR); | 408 | printf("SNR: %li, ",SNR); |
372 | printf("Length: %i",(int)receivedbytes); | 409 | printf("Length: %i",(int)receivedbytes); |
373 | printf("\n"); | 410 | printf("\n"); |
@@ -463,7 +500,7 @@ void receivepacket() { | @@ -463,7 +500,7 @@ void receivepacket() { | ||
463 | buff_index += 13; | 500 | buff_index += 13; |
464 | j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"lsnr\":%li", SNR); | 501 | j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"lsnr\":%li", SNR); |
465 | buff_index += j; | 502 | buff_index += j; |
466 | - j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"rssi\":%d,\"size\":%u", readRegister(0x1A)-139, receivedbytes); | 503 | + j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"rssi\":%d,\"size\":%u", readRegister(0x1A)-rssicorr, receivedbytes); |
467 | buff_index += j; | 504 | buff_index += j; |
468 | memcpy((void *)(buff_up + buff_index), (void *)",\"data\":\"", 9); | 505 | memcpy((void *)(buff_up + buff_index), (void *)",\"data\":\"", 9); |
469 | buff_index += 9; | 506 | buff_index += 9; |
@@ -504,12 +541,7 @@ int main () { | @@ -504,12 +541,7 @@ int main () { | ||
504 | pinMode(dio0, INPUT); | 541 | pinMode(dio0, INPUT); |
505 | pinMode(RST, OUTPUT); | 542 | pinMode(RST, OUTPUT); |
506 | 543 | ||
507 | - digitalWrite(RST, HIGH); | ||
508 | - delay(100); | ||
509 | - digitalWrite(RST, LOW); | ||
510 | - delay(200); | ||
511 | - | ||
512 | - //int fd = ; | 544 | + //int fd = |
513 | wiringPiSPISetup(CHANNEL, 500000); | 545 | wiringPiSPISetup(CHANNEL, 500000); |
514 | //cout << "Init result: " << fd << endl; | 546 | //cout << "Init result: " << fd << endl; |
515 | 547 |