diff --git a/libraries/MySensors/MyConfig.h b/libraries/MySensors/MyConfig.h index d4a0633..d274fe0 100644 --- a/libraries/MySensors/MyConfig.h +++ b/libraries/MySensors/MyConfig.h @@ -65,11 +65,14 @@ #define RF24_CS_PIN 10 #define RF24_PA_LEVEL RF24_PA_MAX #define RF24_PA_LEVEL_GW RF24_PA_LOW -#define RF24_CHANNEL 76 //RF channel for the sensor net, 0-127 -#define RF24_DATARATE RF24_250KBPS //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps -#define RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL) // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network. +// RF channel for the sensor net, 0-127 +#define RF24_CHANNEL 76 +//RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps +#define RF24_DATARATE RF24_250KBPS +// This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network. +#define RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL) -// Enable SOFTSPI for the W5100 Ethernet module +// Enable SOFTSPI for NRF24L01 when using the W5100 Ethernet module //#define SOFTSPI #ifdef SOFTSPI // Define the soft SPI pins used for NRF radio @@ -79,4 +82,22 @@ #endif +/********************************** +* RFM69 Driver Defaults +***********************************/ +// Default network id. Use the same for all nodes that will talk to each other +#define RFM69_NETWORKID 100 + +// Default frequency to use. This must match the hardware version of the RFM69 radio (uncomment one): +// #define RFM69_FREQUENCY RF69_433MHZ +#define RFM69_FREQUENCY RF69_868MHZ +//#define FREQUENCY RF69_915MHZ + +// Enable this for encryption of packets +//#define RFM69_ENABLE_ENCRYPTION +#define RFM69_ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes! + + + + #endif diff --git a/libraries/MySensors/MyTransportRF69.cpp b/libraries/MySensors/MyTransportRF69.cpp deleted file mode 100644 index b55ce14..0000000 --- a/libraries/MySensors/MyTransportRF69.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "MyTransport.h" -#include "MyTransportRF69.h" - -MyTransportRF69::MyTransportRF69() - : - MyTransport(), - radio() -{ -} - -void MyTransportRF69::init() { - // Start up the radio library - radio->initialize(FREQUENCY,_address,NETWORKID); -#ifdef IS_RFM69HW - radio->setHighPower(); //uncomment only for RFM69HW! -#endif - // radio->encrypt(ENCRYPTKEY); - -} - -void MyTransportRF69::setAddress(uint8_t address) { - _address = address; - radio->setAddress(address); -} - -uint8_t MyTransportRF69::getAddress() { - return _address; -} - -bool MyTransportRF69::send(uint8_t to, const void* data, uint8_t len) { - // Make sure radio has powered up - return radio->sendWithRetry(to,data,len); -} - -bool MyTransportRF69::available(uint8_t *to) { - if (radio->TARGETID == BROADCAST_ADDRESS) - *to = BROADCAST_ADDRESS; - else - *to = _address; - return radio->receiveDone(); -} - -uint8_t MyTransportRF69::receive(void* data) { - // for (byte i = 0; i < radio->DATALEN; i++){ - // data[i]= (void)radio->DATA[i]; - // } - memcpy(data,(const void *)radio->DATA, radio->DATALEN); - if (radio->ACKRequested()) - { - radio->sendACK(); - } - return radio->DATALEN; -} - -void MyTransportRF69::powerDown() { - radio->sleep(); -} diff --git a/libraries/MySensors/MyTransportRF69.h b/libraries/MySensors/MyTransportRF69.h deleted file mode 100644 index 687259d..0000000 --- a/libraries/MySensors/MyTransportRF69.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef MyTransportRF69_h -#define MyTransportRF69_h - -#include "MyConfig.h" -#include "MyTransport.h" -#include -#include "utility/RFM69.h" -#include - -#define NODEID 2 //unique for each node on same network -#define NETWORKID 100 //the same on all nodes that talk to each other -#define GATEWAYID 1 -//Match frequency to the hardware version of the radio on your Moteino (uncomment one): -// #define FREQUENCY RF69_433MHZ -#define FREQUENCY RF69_868MHZ -//#define FREQUENCY RF69_915MHZ -#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes! -//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W! -#define ACK_TIME 30 // max # of ms to wait for an ack -#ifdef __AVR_ATmega1284P__ - #define LED 15 // Moteino MEGAs have LEDs on D15 - #define FLASH_SS 23 // and FLASH SS on D23 -#else - #define LED 9 // Moteinos have LEDs on D9 - #define FLASH_SS 8 // and FLASH SS on D8 -#endif - -class MyTransportRF69 : public MyTransport -{ -public: - MyTransportRF69(); - void init(); - void setAddress(uint8_t address); - uint8_t getAddress(); - bool send(uint8_t to, const void* data, uint8_t len); - bool available(uint8_t *to); - uint8_t receive(void* data); - void powerDown(); -private: - RFM69 *radio; - uint8_t _address; -}; - -#endif diff --git a/libraries/MySensors/MyTransportRFM69.cpp b/libraries/MySensors/MyTransportRFM69.cpp new file mode 100644 index 0000000..c387816 --- /dev/null +++ b/libraries/MySensors/MyTransportRFM69.cpp @@ -0,0 +1,54 @@ +#include "MyTransport.h" +#include "MyTransportRFM69.h" + +MyTransportRFM69::MyTransportRFM69(uint8_t freqBand, uint8_t networkId, uint8_t slaveSelectPin, uint8_t interruptPin, bool isRFM69HW, uint8_t interruptNum) + : + MyTransport(), + radio(slaveSelectPin, interruptPin, isRFM69HW, interruptNum), + _freqBand(freqBand), + _networkId(networkId) +{ +} + +void MyTransportRFM69::init() { + // Start up the radio library (_address will be set later by the MySensors library) + radio.initialize(_freqBand, _address, _networkId); +#ifdef RFM69_ENABLE_ENCRYPTION + radio.encrypt(ENCRYPTKEY); +#endif + +} + +void MyTransportRFM69::setAddress(uint8_t address) { + _address = address; + radio.setAddress(address); +} + +uint8_t MyTransportRFM69::getAddress() { + return _address; +} + +bool MyTransportRFM69::send(uint8_t to, const void* data, uint8_t len) { + return radio.sendWithRetry(to,data,len); +} + +bool MyTransportRFM69::available(uint8_t *to) { + if (radio.TARGETID == BROADCAST_ADDRESS) + *to = BROADCAST_ADDRESS; + else + *to = _address; + return radio.receiveDone(); +} + +uint8_t MyTransportRFM69::receive(void* data) { + memcpy(data,(const void *)radio.DATA, radio.DATALEN); + // Send ack back if this message wasn't a broadcast + if (radio.TARGETID != RF69_BROADCAST_ADDR) + radio.ACKRequested(); + radio.sendACK(); + return radio.DATALEN; +} + +void MyTransportRFM69::powerDown() { + radio.sleep(); +} diff --git a/libraries/MySensors/MyTransportRFM69.h b/libraries/MySensors/MyTransportRFM69.h new file mode 100644 index 0000000..7b3821a --- /dev/null +++ b/libraries/MySensors/MyTransportRFM69.h @@ -0,0 +1,29 @@ +#ifndef MyTransportRF69_h +#define MyTransportRF69_h + +#include "MyConfig.h" +#include "MyTransport.h" +#include +#include "utility/RFM69.h" +#include + + +class MyTransportRFM69 : public MyTransport +{ +public: + MyTransportRFM69(uint8_t freqBand=RFM69_FREQUENCY, uint8_t networkId=RFM69_NETWORKID, uint8_t slaveSelectPin=RF69_SPI_CS, uint8_t interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false, uint8_t interruptNum=RF69_IRQ_NUM); + void init(); + void setAddress(uint8_t address); + uint8_t getAddress(); + bool send(uint8_t to, const void* data, uint8_t len); + bool available(uint8_t *to); + uint8_t receive(void* data); + void powerDown(); +private: + RFM69 radio; + uint8_t _address; + uint8_t _freqBand; + uint8_t _networkId; +}; + +#endif diff --git a/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino b/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino index 81f65f6..c653ab4 100644 --- a/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino +++ b/libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include #include @@ -78,7 +78,7 @@ // NRFRF24L01 radio driver (set low transmit power by default) MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW); -//MyTransportRF69 transport; +//MyTransportRFM69 transport; // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h) //MySigningNone signer; diff --git a/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino b/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino index 4742331..006a785 100644 --- a/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino +++ b/libraries/MySensors/examples/MQTTGateway/MQTTGateway.ino @@ -60,7 +60,7 @@ http://forum.mysensors.org/topic/303/mqtt-broker-gateway #include #include -#include +#include #include #include #include @@ -100,7 +100,7 @@ uint8_t TCP_MAC[] = { 0x02, 0xDE, 0xAD, 0x00, 0x00, 0x42 }; // Mac-address - You // NRFRF24L01 radio driver (set low transmit power by default) MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW); -//MyTransportRF69 transport; +//MyTransportRFM69 transport; // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h) //MySigningNone signer; diff --git a/libraries/MySensors/examples/RelayActuator/RelayActuator.ino b/libraries/MySensors/examples/RelayActuator/RelayActuator.ino index 615049d..93e93c2 100644 --- a/libraries/MySensors/examples/RelayActuator/RelayActuator.ino +++ b/libraries/MySensors/examples/RelayActuator/RelayActuator.ino @@ -3,7 +3,7 @@ #include #include -//#include +#include #include #include #include @@ -15,7 +15,7 @@ // NRFRF24L01 radio driver (set low transmit power by default) MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW); -//MyTransportRF69 radio; +//MyTransportRFM69 radio; // Message signing driver (none default) //MySigningNone signer; // Select AtMega328 hardware profile diff --git a/libraries/MySensors/examples/SerialGateway/SerialGateway.ino b/libraries/MySensors/examples/SerialGateway/SerialGateway.ino index a1b01e4..266fdb7 100644 --- a/libraries/MySensors/examples/SerialGateway/SerialGateway.ino +++ b/libraries/MySensors/examples/SerialGateway/SerialGateway.ino @@ -24,7 +24,7 @@ #define NO_PORTB_PINCHANGES #include -#include +#include #include #include #include @@ -46,7 +46,7 @@ // NRFRF24L01 radio driver (set low transmit power by default) MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW); -//MyTransportRF69 transport; +//MyTransportRFM69 transport; // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h) //MySigningNone signer;