Skip to content

Commit db73e3c

Browse files
committed
switched to low-power library
1 parent 26138b7 commit db73e3c

File tree

7 files changed

+1713
-29
lines changed

7 files changed

+1713
-29
lines changed

libraries/MySensors/MyConfig.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
*/
77

88
// pick ONE of these - other board layouts can be easily added this way
9-
#define MYSENSORS_SENSOR
10-
//#define MYSENSORS_SERIAL_GATEWAY
9+
// #define MYSENSORS_SENSOR
10+
#define MYSENSORS_SERIAL_GATEWAY
1111
//#define MYSENSORS_ETHERNET_MQTT_GATEWAY
1212

1313
// Choose radio type by enabling one of the following
14-
#define MYSENSORS_RF_NRF24
14+
//#define MYSENSORS_RF_NRF24
1515
#define MYSENSORS_RF_RF69
1616

1717

libraries/MySensors/MyDriverRF69.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
#include <RHReliableDatagram.h>
12
#include "MyDriver.h"
23
#include "MyDriverRF69.h"
34

45
MyDriverRF69::MyDriverRF69() : MyDriver() {
5-
driver = new RH_RF69(RF69_CS_PIN, RF69_INTERRUPT_PIN);
6+
radio = new RFM69();
67
}
78

89
void MyDriverRF69::init() {
910
// Start up the radio library
10-
manager = new RHReliableDatagram(*driver, _address);
11-
driver->setFrequency(RF69_FREQUENCY);
12-
driver->setTxPower(RF69_TRANSMIT_POWER)
11+
radio->initialize(FREQUENCY,_address,NETWORKID);
12+
#ifdef IS_RFM69HW
13+
radio->setHighPower(); //uncomment only for RFM69HW!
14+
#endif
15+
// radio->encrypt(ENCRYPTKEY);
1316

1417
}
1518

1619
void MyDriverRF69::setAddress(uint8_t address) {
1720
_address = address;
18-
manager->setThisAddress(_address);
21+
radio->setAddress(address);
1922
}
2023

2124
uint8_t MyDriverRF69::getAddress() {
@@ -24,24 +27,24 @@ uint8_t MyDriverRF69::getAddress() {
2427

2528
bool MyDriverRF69::send(uint8_t to, const void* data, uint8_t len) {
2629
// Make sure radio has powered up
27-
uint8_t status = manager->sendtoWait((uint8_t *) data, len, to);
28-
if(status==RH_ROUTER_ERROR_NONE) {
29-
return true;
30-
} else {
31-
return false;
32-
}
30+
return radio->sendWithRetry(to,data,len);
3331
}
3432

3533
bool MyDriverRF69::available(uint8_t *to) {
36-
return manager->available();
34+
return radio->receiveDone();
3735
}
3836

3937
uint8_t MyDriverRF69::receive(void* data) {
40-
uint8_t len = 256;
41-
uint8_t from;
42-
manager->recvfromAck((uint8_t *) data, &len, &from);
43-
}
38+
// for (byte i = 0; i < radio->DATALEN; i++){
39+
// data[i]= (void)radio->DATA[i];
40+
// }
41+
memcpy(data,(const void *)radio->DATA, radio->DATALEN);
42+
if (radio->ACKRequested())
43+
{
44+
radio->sendACK();
45+
}
46+
}
4447

4548
void MyDriverRF69::powerDown() {
46-
driver->sleep();
49+
radio->sleep();
4750
}

libraries/MySensors/MyDriverRF69.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44
#include "MyConfig.h"
55
#include "MyDriver.h"
66
#include <stdint.h>
7-
#include <RH_RF69.h>
8-
#include <RHReliableDatagram.h>
7+
#include "RFM69.h"
8+
#include <SPI.h>
99

10-
#define RF69_FREQUENCY 868;
11-
#define RF69_TRANSMIT_POWER 14;
12-
#define RF69_MODEM_CONFIG RH_RF69::GFSK_Rb250Fd250;
13-
#define RF69_INTERRUPT_PIN 2;
14-
#define RF69_CS_PIN 10;
10+
#define NODEID 2 //unique for each node on same network
11+
#define NETWORKID 100 //the same on all nodes that talk to each other
12+
#define GATEWAYID 1
13+
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
14+
// #define FREQUENCY RF69_433MHZ
15+
#define FREQUENCY RF69_868MHZ
16+
//#define FREQUENCY RF69_915MHZ
17+
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
18+
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
19+
#define ACK_TIME 30 // max # of ms to wait for an ack
20+
#ifdef __AVR_ATmega1284P__
21+
#define LED 15 // Moteino MEGAs have LEDs on D15
22+
#define FLASH_SS 23 // and FLASH SS on D23
23+
#else
24+
#define LED 9 // Moteinos have LEDs on D9
25+
#define FLASH_SS 8 // and FLASH SS on D8
26+
#endif
1527

1628
class MyDriverRF69 : public MyDriver
1729
{
@@ -25,8 +37,7 @@ class MyDriverRF69 : public MyDriver
2537
uint8_t receive(void* data);
2638
void powerDown();
2739
private:
28-
RH_RF69 *driver = NULL;
29-
RHReliableDatagram *manager = NULL;
40+
RFM69 *radio = NULL;
3041
uint8_t _address;
3142
};
3243

libraries/MySensors/MySensor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ boolean MySensor::process() {
275275
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), msg.getString(convBuf));
276276

277277
if(!(mGetVersion(msg) == PROTOCOL_VERSION)) {
278+
debug(PSTR("version: %d\n"),mGetVersion(msg));
278279
debug(PSTR("version mismatch\n"));
279280
return false;
280281
}

0 commit comments

Comments
 (0)