Coder Social home page Coder Social logo

tinylora's Introduction

Adafruit TinyLoRa Library Build StatusDocumentation

Library for communicating with The Things Network using a Hope RF RFM95/96/97/98(W) LoRa Transceiver Module.

Documentation/Links

The Doxygen documentation is automatically generated from the source files in this repository, and documents the API exposed by this driver. For practical details on how to connect and use this sensor, consult the Learning Guide.

License

This library was written by ClemensRiederer. We've modified it to support channel/datarate selections and made small changes so it works with the Adafruit Feather 32u4 LoRa and the Adafruit Feather M0 LoRa. We've added examples for using this library to transmit sensor data over a single channel or multiple channels to The Things Network.

This open source code is licensed under the LGPL license (see LICENSE for details).

tinylora's People

Contributors

arjanmels avatar brentru avatar chocotov1 avatar clavisound avatar clemensriederer avatar evaherrada avatar greensladenz avatar ladyada avatar nerdyscout avatar tyeth avatar wero1414 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinylora's Issues

TinyLora with Feather Mo LoRa - Starting LoRa...Failed

I am trying to get the tinylora_dht22 example to work with a Feather M0 LoRa but get

"Starting LoRa...Failed"
"Check your radio"

I used this line of code for pinouts

// Pinout for Adafruit Feather M0 LoRa
TinyLoRa lora = TinyLoRa(3, 8);

I do have a jumper between IO1 and pin 6. Nothing else is connected currently.

Not sure what else to try - this same unit does successfully connect to TTN using the LMIC OTAA DHT22 example.

power off/standby api before putting arduino to sleep?

I looked but didn't see a "power off/sleep" api to use before putting an arduino in deep sleep?
After looking at code, it seems like the device is put to standby after every message, but was hoping there was something that puts RFM95 in minimal power usage. I looked at the RFM95 specs, but it wasn't clear at all.

DEEPSLEEP Arduino Pro mini

Thank you for this great library.
I use it on a 328p.
How can I add commands after sending.
that he goes into deep sleep for me?
Thank you

Lose packets LoRa 32u4 ll

Hello everyone, I am working with the Lora 32u4ll of BsFrance and a gateway kernel, it works, transmits to Yeap (a lora provider) but the RSSI is very low, around -117 and my lora 32u4ll is very close of the antenna of Gateway Someone knows what happens?

I would greatly appreciate your help.

information on disabling Frame Counter Check

This is not really an issue, but something that was puzzling me so I wanted to look into it a bit.
Feel free to close this at any time.

In setting up the devices on The Things Network (TTN) it was recommended that Frame Counter Checks be disabled to avoid some cases where data reception stopped.

Looking into this a bit, that makes sense.
See
https://www.thethingsnetwork.org/docs/lorawan/security.html#frame-counters

For simple examples, I suspect the security impact is not all that important, but I think this needs to be understood by users.

If I read this correctly, in order to use the Frame Counter Check, one would have to re-register the device every time it is reset or if the frame counter overflows. It's not quite that bad, you could reset the frame counter to a value larger than the last transmission and it whorl be be OK to restart. Certainly not something to do during development! I think it is OK to disable it but some explanation should be included in the guide. When you disable it TTN gives a cryptic warning about how this should only be done during development and greatly diminishes security. Unfortunately, TTN does not explain what at that time.

modify examples to avoid corrupting fixed message

In the examples, a fixed string is created to send the message "Hello LoRa"
but when the message to be transmitted is processed, the contents of the data array passed to senData are destroyed during the encryption process.

If the message is only initialized at declaration then it is sent properly the first time, then garbled every time after that as the array is repeatedly encrypted.

It should be made clear that sendData destroys the data array.
The example can be easily fixed with a few simple changes:

replace the declaration

unsigned char loraData[11] = {"hello LoRa"};

with

char loraData[11];

in the loop
replace

lora.sendData(loraData, sizeof(loraData), lora.frameCounter);

with

strcpy(loraData,"Hello Lora");
lora.sendData((unsigned char *)loraData, sizeof(loraData), lora.frameCounter);

There are many ways to deal with this. We could have sendData make a local copy of the message, but that is a potential waste of up to 252 bytes.

In general, this will not be in issue if users are sending changing data with every transmission so I really don't think anything needs to be "fixed" other than the way the example feeds the message to sendData.

another option is to modify the example to send values instead of text. For example I have one sending the frame counter as the message:
I declare:
unsigned char loraData[2] = {0,0};

then when ready to send:

  loraData[0]=lora.frameCounter & 0xff;
  loraData[1]=(lora.frameCounter>>8) & 0xff;

The message can be created in a variety of ways - the argument passed to sendData must be cast to an (unsigned char *) when it is sent if it is not to begin with.

problems compiling for feather M0 Express

@brentru I have gotten this to work with a Feather M0 Express, but i have had to make a few changes.
Theseare due to compiler differences between the AVR and ARM compilers
In TinyLoRa.cpp
Replace "static const" with "const" -- I'm not sure this was the only way to make it work, but it would not compile with "static const"

In TinyLora.h:
remove include for delay -- it is not needed and /util/delay does not exist - delay is available without this include

select SF12BW125 for the datarate

Here are the "diffs"

diff --git a/TinyLoRa.cpp b/TinyLoRa.cpp
index 4647985..79b90ac 100644
--- a/TinyLoRa.cpp
+++ b/TinyLoRa.cpp
@@ -30,7 +30,7 @@ static SPISettings RFM_spisettings = SPISettings(4000000, MSBFIRST, SPI_MODE0);
 */
 
 #ifdef AU915
-static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
+const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
        { 0xE5, 0x33, 0x5A },   //Channel 0 916.800 MHz / 61.035 Hz = 15020890 = 0xE5335A
        { 0xE5, 0x40, 0x26 },   //Channel 2 917.000 MHz / 61.035 Hz = 15024166 = 0xE54026
        { 0xE5, 0x4C, 0xF3 },   //Channel 3 917.200 MHz / 61.035 Hz = 15027443 = 0xE54CF3
@@ -43,7 +43,7 @@ static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
 #endif
 
 #ifdef EU863
-static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
+const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
        { 0xD9, 0x06, 0x8B },   //Channel 0 868.100 MHz / 61.035 Hz = 14222987 = 0xD9068B
        { 0xD9, 0x13, 0x58 },   //Channel 1 868.300 MHz / 61.035 Hz = 14226264 = 0xD91358
        { 0xD9, 0x20, 0x24 },   //Channel 2 868.500 MHz / 61.035 Hz = 14229540 = 0xD92024
@@ -57,7 +57,7 @@ static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
 #endif
 
 #ifdef US902
-static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
+const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
        { 0xE1, 0xF9, 0xC0 },           //Channel 0 903.900 MHz / 61.035 Hz = 14809536 = 0xE1F9C0
        { 0xE2, 0x06, 0x8C },           //Channel 1 904.100 MHz / 61.035 Hz = 14812812 = 0xE2068C
        { 0xE2, 0x13, 0x59},            //Channel 2 904.300 MHz / 61.035 Hz = 14816089 = 0xE21359
@@ -70,7 +70,7 @@ static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
 #endif
 
 #ifdef AS920
-static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
+const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
        { 0xE6, 0xCC, 0xF4 },           //Channel 0 868.100 MHz / 61.035 Hz = 15125748 = 0xE6CCF4
        { 0xE6, 0xD9, 0xC0 },           //Channel 1 868.300 MHz / 61.035 Hz = 15129024 = 0xE6D9C0
        { 0xE6, 0x8C, 0xF3 },           //Channel 2 868.500 MHz / 61.035 Hz = 15109363 = 0xE68CF3
@@ -89,7 +89,7 @@ static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
 *****************************************************************************************
 */
 
-static const unsigned char PROGMEM TinyLoRa::S_Table[16][16] = {
+const unsigned char PROGMEM TinyLoRa::S_Table[16][16] = {
          {0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5,0x30,0x01,0x67,0x2B,0xFE,0xD7,0xAB,0x76},
          {0xCA,0x82,0xC9,0x7D,0xFA,0x59,0x47,0xF0,0xAD,0xD4,0xA2,0xAF,0x9C,0xA4,0x72,0xC0},
          {0xB7,0xFD,0x93,0x26,0x36,0x3F,0xF7,0xCC,0x34,0xA5,0xE5,0xF1,0x71,0xD8,0x31,0x15},
:...skipping...
diff --git a/TinyLoRa.cpp b/TinyLoRa.cpp
index 4647985..79b90ac 100644
--- a/TinyLoRa.cpp
+++ b/TinyLoRa.cpp
@@ -30,7 +30,7 @@ static SPISettings RFM_spisettings = SPISettings(4000000, MSBFIRST, SPI_MODE0);
 */
 
 #ifdef AU915
-static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
+const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
        { 0xE5, 0x33, 0x5A },   //Channel 0 916.800 MHz / 61.035 Hz = 15020890 = 0xE5335A
        { 0xE5, 0x40, 0x26 },   //Channel 2 917.000 MHz / 61.035 Hz = 15024166 = 0xE54026
        { 0xE5, 0x4C, 0xF3 },   //Channel 3 917.200 MHz / 61.035 Hz = 15027443 = 0xE54CF3
@@ -43,7 +43,7 @@ static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
 #endif
 
 #ifdef EU863
-static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
+const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
        { 0xD9, 0x06, 0x8B },   //Channel 0 868.100 MHz / 61.035 Hz = 14222987 = 0xD9068B
        { 0xD9, 0x13, 0x58 },   //Channel 1 868.300 MHz / 61.035 Hz = 14226264 = 0xD91358
        { 0xD9, 0x20, 0x24 },   //Channel 2 868.500 MHz / 61.035 Hz = 14229540 = 0xD92024
@@ -57,7 +57,7 @@ static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
 #endif
 
 #ifdef US902
-static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
+const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
        { 0xE1, 0xF9, 0xC0 },           //Channel 0 903.900 MHz / 61.035 Hz = 14809536 = 0xE1F9C0
        { 0xE2, 0x06, 0x8C },           //Channel 1 904.100 MHz / 61.035 Hz = 14812812 = 0xE2068C
        { 0xE2, 0x13, 0x59},            //Channel 2 904.300 MHz / 61.035 Hz = 14816089 = 0xE21359
@@ -70,7 +70,7 @@ static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
 #endif
 
 #ifdef AS920
-static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
+const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
        { 0xE6, 0xCC, 0xF4 },           //Channel 0 868.100 MHz / 61.035 Hz = 15125748 = 0xE6CCF4
        { 0xE6, 0xD9, 0xC0 },           //Channel 1 868.300 MHz / 61.035 Hz = 15129024 = 0xE6D9C0
        { 0xE6, 0x8C, 0xF3 },           //Channel 2 868.500 MHz / 61.035 Hz = 15109363 = 0xE68CF3
@@ -89,7 +89,7 @@ static const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
 *****************************************************************************************
 */
 
-static const unsigned char PROGMEM TinyLoRa::S_Table[16][16] = {
+const unsigned char PROGMEM TinyLoRa::S_Table[16][16] = {
          {0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5,0x30,0x01,0x67,0x2B,0xFE,0xD7,0xAB,0x76},
          {0xCA,0x82,0xC9,0x7D,0xFA,0x59,0x47,0xF0,0xAD,0xD4,0xA2,0xAF,0x9C,0xA4,0x72,0xC0},
          {0xB7,0xFD,0x93,0x26,0x36,0x3F,0xF7,0xCC,0x34,0xA5,0xE5,0xF1,0x71,0xD8,0x31,0x15},
@@ -972,4 +972,4 @@ void TinyLoRa::AES_Calculate_Round_Key(unsigned char Round, unsigned char *Round
       Temp[j]                   = Round_Key[j + (i << 2)];
     }
   }
-}
\ No newline at end of file
+}
diff --git a/TinyLoRa.h b/TinyLoRa.h
index 4250aae..5519f6b 100644
--- a/TinyLoRa.h
+++ b/TinyLoRa.h
@@ -2,7 +2,7 @@
 #define TINY_LORA_H
 
 #include <Arduino.h>
-#include <util/delay.h>
+//#include <util/delay.h>
 #include <avr/pgmspace.h>
 
 // debugging, unset if you don't need this.
@@ -19,12 +19,12 @@
 //#define AS920
 // Define fixed datarate
 //#define SF7BW125
-//#define SF12BW125
+#define SF12BW125
 //#define SF11BW125
 //#define SF10BW125
 //#define SF9BW125
 //#define SF8BW125
-#define SF7BW250
+//#define SF7BW250
 
 /* RFM Modes */
 #define MODE_SLEEP  0x00
(END)

another issue I ran into was that, in the function senddata
https://github.com/adafruit/TinyLoRa/blob/master/TinyLoRa.cpp#L342
the call to EncryptPayload overwrites the contents of Data with the encrypted version.
Since the example program only initializes the Data array at the start, it is encrypted and sent properly the first time it is called, but then it encrypts the encrypted data .... the messages sent after the first one are not readable when received.
In normal use, I don't think this matters since the data array will usually be repopulated with each message.

To verify this, made these changes to the example:
instead of a string use array of bytes initialized to {0,1,2,3,4,5,6,7,8,9,10) althought this is never sent
reconstruct the array Data just before sending it -- I populate it with {40,41,42,43,44,45,46,47,48,49,50} since they are printable ASCII characters.
By repopulating the array each time it works for me.


jerryneedell@Ubuntu-Macmini:~/Arduino/hello_LoRa_gjn$ diff hello_LoRa_gjn.ino ../libraries/TinyLora/examples/hello_LoRa/hello_LoRa.ino 

< unsigned char loraData[11] = {0,1,2,3,4,5,6,7,8,9,10};
---
> unsigned char loraData[11] = {"hello LoRa"};
32c32
< TinyLoRa lora = TinyLoRa(11, 12);
---
> TinyLoRa lora = TinyLoRa(7, 8);
37,38c37,38
< //  while (! Serial);
<   Serial.begin(115200);
---
>   while (! Serial);
>   Serial.begin(9600);
45d44
<   SPI.begin();
51d49
<   uint16_t i;
53,56d50
<   for(i=0;i<11;i++)
<   {
<     loraData[i]=64+i;
<   }

Let me know if you need any more information or clarification.

Wrong australian frequencies

There is a problem in the comment and in the order of the frequencies for AS920

The comment is not right for the calculation and so, the order neither.

The fix could be this one:

#ifdef AS920
const unsigned char PROGMEM TinyLoRa::LoRa_Frequency[8][3] = {
    {0xE6, 0x80,
     0x27} // Channel 0 922.000 MHz / 61.035 Hz = 15106087 = 0xE68027
    {0xE6, 0x8C,
     0xF3}, // Channel 1 922.200 MHz / 61.035 Hz = 15109363 = 0xE68CF3
    {0xE6, 0x99,
     0xC0}, // Channel 2 922.400 MHz / 61.035 Hz = 15112640 = 0xE699C0
    {0xE6, 0xA6,
     0x8D}, // Channel 3 922.600 MHz / 61.035 Hz = 15115917 = 0xE6A68D
    {0xE6, 0xB3,
     0x5A}, // Channel 4 922.800 MHz / 61.035 Hz = 15119194 = 0xE6B35A
    {0xE6, 0xC0,
     0x27}, // Channel 5 923.000 MHz / 61.035 Hz = 15122471 = 0xE6C027
    {0xE6, 0xCC,
     0xF4}, // Channel 6 923.200 MHz / 61.035 Hz = 15125748 = 0xE6CCF4
    {0xE6, 0xD9,
     0xC0}, // Channel 7 923.400 MHz / 61.035 Hz = 15129024 = 0xE6D9C0
};
#endif

"Starting LoRa...", "Failed"

Basically the same problem as this when running hello_LoRa.ino
#23

I'm using RFM95 on a M0 arduino (however non adafruit), and I know it worked twice (coming out of power cycle),
but if I run more than once it fails, maybe the device is in slightly different state after power cycle
versus just pulling RESET low ? (I did hook up reset)

So fix is to remove the version check:
uint8_t ver = RFM_Read(REG_VER); if (ver != RFM9x_VER) return 0;

Once the check has been removed, it sends data to TTN as expected, so the code works, but why it fails is curious.
When it fails, the RFM_Read returns 0 (or maybe its just the first SPI read after reset that is flaky?)

Starting LoRa...Failed

I have bought a Adafruit Feather M0 Lora.

When I now try to send data via the hello_lora example sketch it will always Fail.
I have commentet out the right board in the configuration.

`
// Data Packet to Send to TTN
unsigned char loraData[11] = {"hello LoRa"};

// How many times data transfer should occur, in seconds
const unsigned int sendInterval = 5;

// Pinout for Feather 32u4 LoRa
//TinyLoRa lora = TinyLoRa(7, 8);

// Pinout for Feather M0 LoRa
TinyLoRa lora = TinyLoRa(3, 8);
`

I have also connected Pin 6 and IO1 like mentiond here:
https://learn.adafruit.com/the-things-network-for-feather/using-a-feather-32u4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.