diff --git a/README.md b/README.md index 51341ff..423d7c2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # Arduino LoRa -[![Build Status](https://travis-ci.org/sandeepmistry/arduino-LoRa.svg?branch=master)](https://travis-ci.org/sandeepmistry/arduino-LoRa) +[![Build Status](https://travis-ci.org/WereCatf/arduino-LoRa.svg?branch=master)](https://travis-ci.org/github/WereCatf/arduino-LoRa) An [Arduino](https://arduino.cc/) library for sending and receiving data using [LoRa](https://www.lora-alliance.org/) radios. +**This is a fork of [Sandeep Mistry's awesome library](https://github.com/sandeepmistry/arduino-LoRa) with the only meaningful change being a more useful and easier-to-use random() - function.** + ## Compatible Hardware * [Semtech SX1276/77/78/79](https://www.semtech.com/apps/product.php?pn=SX1276) based boards including: @@ -12,7 +14,7 @@ An [Arduino](https://arduino.cc/) library for sending and receiving data using [ * [Modtronix](http://modtronix.com/) [inAir4](http://modtronix.com/inair4.html), [inAir9](http://modtronix.com/inair9.html), and [inAir9B](http://modtronix.com/inair9b.html) * [Arduino MKR WAN 1300](https://store.arduino.cc/usa/mkr-wan-1300) * **NOTE:** Requires firmware v1.1.6 or later on the on-board Murata module. Please use the [MKRWANFWUpdate_standalone example](https://github.com/arduino-libraries/MKRWAN/blob/master/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino) from latest [MKRWAN library](https://github.com/arduino-libraries/MKRWAN) release to update the firmware. - * **WARNING**: [LoRa.onReceive(...)](https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md#register-callback) and [LoRa.recieve()](https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md#receive-mode) is not compatible with this board! + * **WARNING**: [LoRa.onReceive(...)](https://github.com/WereCatf/arduino-LoRa/blob/master/API.md#register-callback) and [LoRa.recieve()](https://github.com/WereCatf/arduino-LoRa/blob/master/API.md#receive-mode) is not compatible with this board! ### Semtech SX1276/77/78/79 wiring @@ -47,7 +49,7 @@ An [Arduino](https://arduino.cc/) library for sending and receiving data using [ ```sh cd ~/Documents/Arduino/libraries/ -git clone https://github.com/sandeepmistry/arduino-LoRa LoRa +git clone https://github.com/WereCatf/arduino-LoRa LoRa ``` ## API diff --git a/library.properties b/library.properties index e869420..d3964eb 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=LoRa version=0.8.0 -author=Sandeep Mistry -maintainer=Sandeep Mistry +author=WereCatf +maintainer=WereCatf sentence=An Arduino library for sending and receiving data using LoRa radios. paragraph=Supports Semtech SX1276/77/78/79 based boards/shields. category=Communication -url=https://github.com/sandeepmistry/arduino-LoRa +url=https://github.com/WereCatf/arduino-LoRa architectures=* includes=LoRa.h diff --git a/src/LoRa.cpp b/src/LoRa.cpp index 210a589..a298658 100644 --- a/src/LoRa.cpp +++ b/src/LoRa.cpp @@ -645,7 +645,43 @@ void LoRaClass::setGain(uint8_t gain) byte LoRaClass::random() { - return readRegister(REG_RSSI_WIDEBAND); + uint8_t currMode = readRegister(REG_OP_MODE); + uint8_t retVal = 0, bits=7; + void (*_prevOnReceive)(int) = NULL; + + while(isTransmitting()) yield(); + + //We need to be listening to radio-traffic in order to generate random numbers + if(currMode != (MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS)){ +#ifndef ARDUINO_SAMD_MKRWAN1300 + _prevOnReceive = _onReceive; + onReceive(NULL); + receive(); +#else + explicitHeaderMode(); + writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS); +#endif + delay(1); + } + retVal = readRegister(REG_RSSI_WIDEBAND); + while(bits--) { + retVal<<=1; + while(1){ + // implement a basic von Neumann Extractor + uint8_t a=(readRegister(REG_RSSI_WIDEBAND) & 1); + if(a != (readRegister(REG_RSSI_WIDEBAND) & 1)){ + // put random, whitened bit in n + retVal |= a; + break; + } + } + } + //Put the radio in the same mode as it was + if(currMode != (MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS)) writeRegister(REG_OP_MODE, currMode); +#ifndef ARDUINO_SAMD_MKRWAN1300 + if(_prevOnReceive) onReceive(_prevOnReceive); +#endif + return retVal; } void LoRaClass::setPins(int ss, int reset, int dio0)