Skip to content

Commit b0057cc

Browse files
committed
Merge branch 'tosa' of https://github.com/ToSa27/Arduino into
ToSa27-tosa Conflicts: libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino
2 parents 3012963 + 2647345 commit b0057cc

File tree

17 files changed

+463
-323
lines changed

17 files changed

+463
-323
lines changed

Bootloader/MyOtaBootloader.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ static uint8_t sendAndWait(uint8_t reqType, uint8_t resType) {
5656
msg.type = reqType;
5757
for (uint8_t i = 0; i < 10; i++) {
5858
sendWrite(msg);
59-
for (uint16_t j = 0; j < 20; j++) {
59+
for (uint8_t j = 0; j < 20; j++) {
6060
wdt_reset();
61-
for (uint16_t j = 0; j < 100; j++) {
61+
for (uint8_t j = 0; j < 100; j++) {
6262
wdt_reset();
6363
uint8_t pipe;
6464
boolean avail = available(&pipe);

Bootloader/MyOtaBootloader.hex

Lines changed: 200 additions & 204 deletions
Large diffs are not rendered by default.

Bootloader/MyOtaBootloaderHW.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ static void delayu() {
3232
asm("nop");
3333
}
3434

35-
static void delaym(uint16_t t) {
36-
uint16_t d, a;
35+
static void delaym(uint8_t t) {
36+
uint8_t d;
37+
uint16_t a;
3738
for (d = 0; d < t; d++)
3839
for (a = 0; a < DELAY_M; a++)
3940
asm("nop");

NodeJsController/NodeJsController.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,5 +706,8 @@ dbc.connect('mongodb://' + dbAddress + ':' + dbPort + '/' + dbName, function(err
706706
} else {
707707
throw new Error('unknown Gateway type');
708708
}
709+
setInterval(function() {
710+
sendTime(BROADCAST_ADDRESS, NODE_SENSOR_ID, gw);
711+
}, 5*60*1000);
709712
});
710713

libraries/MySensors/MyConfig.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
/***
55
* Configure Sensor Network
66
*/
7-
#define RF24_CHANNEL 76 //RF channel for the sensor net, 0-127
8-
#define RF24_DATARATE RF24_250KBPS //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
9-
#define RF24_PA_LEVEL RF24_PA_MAX //Sensor PA Level == RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBM, and RF24_PA_MAX=0dBm
10-
#define RF24_PA_LEVEL_GW RF24_PA_LOW //Gateway PA Level, defaults to Sensor net PA Level. Tune here if using an amplified nRF2401+ in your gateway.
11-
#define 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.
7+
8+
// pick ONE of these - other board layouts can be easily added this way
9+
#define MYSENSORS_SENSOR
10+
//#define MYSENSORS_SERIAL_GATEWAY
11+
//#define MYSENSORS_ETHERNET_MQTT_GATEWAY
1212

13-
// MySensors online examples defaults
14-
#define DEFAULT_CE_PIN 9
15-
#define DEFAULT_CS_PIN 10
13+
// Choose radio type by enabling one of the following
14+
#define MYSENSORS_RF_NRF24
1615

1716

17+
18+
#ifdef MYSENSORS_RF_NRF24
19+
#include "MyDriverNRF24.h"
20+
typedef class MyDriverNRF24 MyDriverClass;
21+
#endif
22+
1823
/***
1924
* Enable/Disable debug logging
2025
*/

libraries/MySensors/MyDriver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "MyDriver.h"
2+
3+
MyDriver::MyDriver() {
4+
}

libraries/MySensors/MyDriver.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef MyDriver_h
2+
#define MyDriver_h
3+
4+
#include <stdint.h>
5+
6+
#ifdef DEBUG
7+
#define debug(x,...) debugPrint(x, ##__VA_ARGS__)
8+
#else
9+
#define debug(x,...)
10+
#endif
11+
12+
#define AUTO 0xFF // 0-254. Id 255 is reserved for auto initialization of nodeId.
13+
#define NODE_SENSOR_ID 0xFF // Node child id is always created for when a node
14+
15+
// This is the nodeId for sensor net gateway receiver sketch (where all sensors should send their data).
16+
#define GATEWAY_ADDRESS ((uint8_t)0)
17+
#define BROADCAST_ADDRESS ((uint8_t)0xFF)
18+
19+
class MyDriver
20+
{
21+
public:
22+
// MyDriver constructor
23+
// different parameters would be needed depending on radio module (e.g. pins connected etc.)
24+
// keeping these parameters as #define's in MyConfig to streamline the driver interface
25+
MyDriver();
26+
// init()
27+
// different parameters would be needed depending on radio module (e.g. channel, power, crc, etc.)
28+
// keeping these parameters as #define's in MyConfig to streamline the driver interface
29+
virtual void init() = 0;
30+
// setAddress(address)
31+
// set the node address and start listening to that address (and the broadcast address)
32+
virtual void setAddress(uint8_t address) = 0;
33+
// getAddress()
34+
// returns the current address from the radio driver
35+
virtual uint8_t getAddress() = 0;
36+
// send(to, data, len)
37+
// reliable transmission of the data with given length (in bytes) to the destination address
38+
// returns true if successfully submitted
39+
virtual bool send(uint8_t to, const void* data, uint8_t len) = 0;
40+
// available(to)
41+
// returns true if a new packet arrived in the rx buffer
42+
// populates "to" parameter with the address the packet was sent to (either own address or broadcast)
43+
virtual bool available(uint8_t *to) = 0;
44+
// receive(data)
45+
// returns length of received packet
46+
// populates "data" parameter with received data
47+
virtual uint8_t receive(void* data) = 0;
48+
// powers down the radio
49+
virtual void powerDown() = 0;
50+
};
51+
52+
#endif

libraries/MySensors/MyDriverNRF24.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "MyDriver.h"
2+
#include "MyDriverNRF24.h"
3+
4+
MyDriverNRF24::MyDriverNRF24() : MyDriver() {
5+
rf24 = new RF24(RF24_CE_PIN, RF24_CS_PIN);
6+
}
7+
8+
void MyDriverNRF24::init() {
9+
// Start up the radio library
10+
rf24->begin();
11+
12+
if (!rf24->isPVariant()) {
13+
debug(PSTR("check wires\n"));
14+
while(1);
15+
}
16+
rf24->setAutoAck(1);
17+
rf24->setAutoAck(BROADCAST_PIPE,false); // Turn off auto ack for broadcast
18+
rf24->enableAckPayload();
19+
rf24->setChannel(RF24_CHANNEL);
20+
rf24->setPALevel(RF24_PA_LEVEL);
21+
rf24->setDataRate(RF24_DATARATE);
22+
rf24->setRetries(5,15);
23+
rf24->setCRCLength(RF24_CRC_16);
24+
rf24->enableDynamicPayloads();
25+
26+
// All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages)
27+
rf24->openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS));
28+
}
29+
30+
void MyDriverNRF24::setAddress(uint8_t address) {
31+
_address = address;
32+
rf24->openReadingPipe(WRITE_PIPE, TO_ADDR(address));
33+
rf24->openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(address));
34+
rf24->startListening();
35+
}
36+
37+
uint8_t MyDriverNRF24::getAddress() {
38+
return _address;
39+
}
40+
41+
bool MyDriverNRF24::send(uint8_t to, const void* data, uint8_t len) {
42+
// Make sure radio has powered up
43+
rf24->powerUp();
44+
rf24->stopListening();
45+
rf24->openWritingPipe(TO_ADDR(to));
46+
bool ok = rf24->write(data, len, to == BROADCAST_ADDRESS);
47+
rf24->startListening();
48+
return ok;
49+
}
50+
51+
bool MyDriverNRF24::available(uint8_t *to) {
52+
uint8_t pipe = 255;
53+
boolean avail = rf24->available(&pipe);
54+
if (pipe == CURRENT_NODE_PIPE)
55+
*to = _address;
56+
else if (pipe == BROADCAST_PIPE)
57+
*to = BROADCAST_ADDRESS;
58+
return (rf24->available() && pipe < 6);
59+
}
60+
61+
uint8_t MyDriverNRF24::receive(void* data) {
62+
uint8_t len = rf24->getDynamicPayloadSize();
63+
rf24->read(data, len);
64+
}
65+
66+
void MyDriverNRF24::powerDown() {
67+
rf24->powerDown();
68+
}

libraries/MySensors/MyDriverNRF24.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef MyCommDriver_h
2+
#define MyCommDriver_h
3+
4+
#include "MyConfig.h"
5+
#include "MyDriver.h"
6+
#include <stdint.h>
7+
#include "utility/RF24.h"
8+
#include "utility/RF24_config.h"
9+
10+
11+
12+
#ifdef MYSENSORS_SENSOR
13+
#define RF24_CE_PIN 9
14+
#define RF24_CS_PIN 10
15+
#define RF24_PA_LEVEL RF24_PA_MAX
16+
#endif
17+
18+
#ifdef MYSENSORS_SERIAL_GATEWAY
19+
#define RF24_CE_PIN 9
20+
#define RF24_CS_PIN 10
21+
#define RF24_PA_LEVEL RF24_PA_LOW
22+
#endif
23+
24+
#ifdef MYSENSORS_ETHERNET_MQTT_GATEWAY
25+
#define RF24_CE_PIN 5
26+
#define RF24_CS_PIN 6
27+
#define RF24_PA_LEVEL RF24_PA_LOW
28+
#endif
29+
30+
#define RF24_CHANNEL 76 //RF channel for the sensor net, 0-127
31+
#define RF24_DATARATE RF24_250KBPS //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
32+
#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.
33+
34+
#define TO_ADDR(x) (RF24_BASE_RADIO_ID + x)
35+
36+
#define WRITE_PIPE ((uint8_t)0)
37+
#define CURRENT_NODE_PIPE ((uint8_t)1)
38+
#define BROADCAST_PIPE ((uint8_t)2)
39+
40+
class MyDriverNRF24 : public MyDriver
41+
{
42+
public:
43+
MyDriverNRF24();
44+
void init();
45+
void setAddress(uint8_t address);
46+
uint8_t getAddress();
47+
bool send(uint8_t to, const void* data, uint8_t len);
48+
bool available(uint8_t *to);
49+
uint8_t receive(void* data);
50+
void powerDown();
51+
private:
52+
RF24 *rf24;
53+
uint8_t _address;
54+
};
55+
56+
#endif

0 commit comments

Comments
 (0)