RF24 moved to utility folder of library. This results in one less include in sketches!

Serial flush in sleep method also means one less code in examples.
Removed set(bool) in message. Not needed. getBool just calls getInt
__attribute__((packed)) for RPI compability
Print more info in send/read debug prints.
Get internalTemp returns full degrees and uses longer Vref delay
Fix debug print gateway prepend (wrong command/type)
Fixed problem in RelayWithButton example. Now working with ack in both directions.
Serial protocol changed (incoming serial message have an new ack-parameter)
This commit is contained in:
Henrik Ekblad
2014-06-17 22:16:38 +02:00
parent 90f79c97cd
commit c332667a8d
30 changed files with 2691 additions and 121 deletions
-2
View File
@@ -22,8 +22,6 @@
*/
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <MsTimer2.h>
#include <PinChangeInt.h>
#include <MyGateway.h>
+8 -3
View File
@@ -114,10 +114,11 @@ void MyGateway::parseAndSend(char *commandBuffer) {
uint8_t sensor = 0;
uint8_t command = 0;
uint8_t type = 0;
uint8_t ack = 0;
// Extract command data coming on serial line
for (str = strtok_r(commandBuffer, ";", &p); // split using semicolon
str && i < 5; // loop while str is not null an max 5 times
str && i < 6; // loop while str is not null an max 5 times
str = strtok_r(NULL, ";", &p) // get subsequent tokens
) {
switch (i) {
@@ -130,10 +131,13 @@ void MyGateway::parseAndSend(char *commandBuffer) {
case 2: // Message type
command = atoi(str);
break;
case 3: // Data type
case 3: // Should we request ack from destination?
ack = atoi(str);
break;
case 4: // Data type
type = atoi(str);
break;
case 4: // Variable value
case 5: // Variable value
value = str;
break;
}
@@ -156,6 +160,7 @@ void MyGateway::parseAndSend(char *commandBuffer) {
msg.sensor = sensor;
msg.type = type;
mSetCommand(msg,command);
mSetAck(msg,ack==0?false:true);
msg.set(value);
ok = sendRoute(msg);
if (!ok) {
+2 -9
View File
@@ -32,8 +32,7 @@ char* MyMessage::getString(char *buffer) const {
uint8_t payloadType = miGetPayloadType();
if (payloadType == P_STRING) {
strncpy(buffer, data, miGetLength());
buffer[miGetLength()] = '\0';
strcpy(buffer, data);
return buffer;
} else if (buffer != NULL) {
switch(payloadType) {
@@ -77,7 +76,7 @@ uint8_t MyMessage::getByte() const {
}
bool MyMessage::getBool() const {
return !(data[0]-'0'==0);
return getInt();
}
double MyMessage::getDouble() const {
@@ -169,12 +168,6 @@ MyMessage& MyMessage::set(uint8_t value) {
return *this;
}
MyMessage& MyMessage::set(bool value) {
miSetLength(1);
miSetPayloadType(P_STRING);
data[0] = value?'1':'0';
return *this;
}
MyMessage& MyMessage::set(double value, uint8_t decimals) {
dtostrf(value,2,decimals,data);
+4 -5
View File
@@ -82,12 +82,14 @@ typedef enum {
// Getters/setters for special fields in header
#define mSetVersion(_msg,_version) BF_SET(_msg.version_length, _version, 0, 3)
#define mSetLength(_msg,_length) BF_SET(_msg.version_length, _length, 3, 5)
#define mSetCommand(_msg,_command) BF_SET(_msg.command_ack_payload, _command, 0, 3)
#define mSetAck(_msg,_command) BF_SET(_msg.command_ack_payload, _command, 3, 1)
#define mSetPayloadType(_msg, _pt) BF_SET(_msg.command_ack_payload, _pt, 4, 4)
#define mGetVersion(_msg) BF_GET(_msg.version_length, 0, 3)
#define mGetLength(_msg) BF_GET(_msg.version_length, 3, 5)
#define mGetCommand(_msg) BF_GET(_msg.command_ack_payload, 0, 3)
#define mGetAck(_msg) BF_GET(_msg.command_ack_payload, 3, 1)
#define mGetPayloadType(_msg) BF_GET(_msg.command_ack_payload, 4, 4)
@@ -134,7 +136,6 @@ public:
MyMessage& set(void* payload, uint8_t length);
MyMessage& set(const char* value);
MyMessage& set(uint8_t value);
MyMessage& set(bool value);
MyMessage& set(double value, uint8_t decimals);
MyMessage& set(unsigned long value);
MyMessage& set(long value);
@@ -164,9 +165,7 @@ public:
unsigned int uiValue;
int iValue;
char data[MAX_PAYLOAD + 1];
};
};
} __attribute__((packed));
} __attribute__((packed));
#endif
+20 -15
View File
@@ -10,7 +10,9 @@
*/
#include "MySensor.h"
#include "LowPower.h"
#include "utility/LowPower.h"
#include "utility/RF24.h"
#include "utility/RF24_config.h"
// Inline function and macros
@@ -205,8 +207,8 @@ boolean MySensor::sendWrite(uint8_t next, MyMessage &message, bool broadcast) {
bool ok = RF24::write(&message, min(MAX_MESSAGE_LENGTH, HEADER_SIZE + length), broadcast);
RF24::startListening();
debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d, st=%s:%s\n"),
message.sender,message.last, next, message.destination, message.sensor, mGetCommand(message), message.type, ok?"ok":"fail", message.getString(convBuf));
debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,st=%s:%s\n"),
message.sender,message.last, next, message.destination, message.sensor, mGetCommand(message), message.type, mGetPayloadType(message), mGetLength(message), ok?"ok":"fail", message.getString(convBuf));
return ok;
}
@@ -215,7 +217,7 @@ boolean MySensor::sendWrite(uint8_t next, MyMessage &message, bool broadcast) {
bool MySensor::send(MyMessage &message, bool enableAck) {
message.sender = nc.nodeId;
mSetCommand(message,C_SET);
mSetAck(message,enableAck);
mSetAck(message,enableAck);
return sendRoute(message);
}
@@ -260,10 +262,10 @@ boolean MySensor::process() {
uint8_t valid = validate(msg);
boolean ok = valid == VALIDATE_OK;
// Make sure string gets terminated ok for full string messages.
msg.data[len - HEADER_SIZE ] = '\0';
debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,cr=%s: %s\n"),
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, valid==0?"ok":valid==1?"ec":"ev", msg.getString(convBuf));
// Add termination, good for string messages.
msg.data[mGetLength(msg)] = '\0';
debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,cr=%s:%s\n"),
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), valid==0?"ok":valid==1?"ec":"ev", msg.getString(convBuf));
if (!ok)
return false;
@@ -497,19 +499,19 @@ uint8_t MySensor::getChildRoute(uint8_t childId) {
}
float MySensor::getInternalTemp(void)
int MySensor::getInternalTemp(void)
{
long result;
// Read internal temp sensor against 1.1V reference
ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);
delay(2); // Wait until Vref has settled
delay(20); // Wait until Vref has settled
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = (result - 125) * 1075;
result = (result - 125) * 1075 + 500; // add 500 to round to nearest full degree
return static_cast<float>(static_cast<int>(result/1000.)) / 10.;
return result/10000;
}
int continueTimer = true;
@@ -532,12 +534,16 @@ void MySensor::internalSleep(int ms) {
}
void MySensor::sleep(int ms) {
// Let serial prints finish (debug, log etc)
Serial.flush();
RF24::powerDown();
continueTimer = true;
internalSleep(ms);
}
void MySensor::sleep(int interrupt, int mode, int ms) {
// Let serial prints finish (debug, log etc)
Serial.flush();
RF24::powerDown();
attachInterrupt(interrupt, wakeUp, mode); //Interrupt on pin 3 for any change in solar power
if (ms>0) {
@@ -556,11 +562,11 @@ void MySensor::debugPrint(const char *fmt, ... ) {
char fmtBuffer[300];
if (isGateway) {
// prepend debug message to be handled correctly by gw (C_INTERNAL, I_LOG_MESSAGE)
Serial.write("0;0;4;8;");
snprintf_P(fmtBuffer, 299, PSTR("0;0;%d;%d;"), C_INTERNAL, I_LOG_MESSAGE);
Serial.print(fmtBuffer);
}
va_list args;
va_start (args, fmt );
vsnprintf_P(fmtBuffer, 300, fmt, args);
va_end (args);
if (isGateway) {
// Truncate message if this is gateway node
@@ -574,7 +580,6 @@ void MySensor::debugPrint(const char *fmt, ... ) {
Serial.print(fmtBuffer);
Serial.flush();
//Serial.write("0;0;4;11;Mem free:");
//Serial.write(freeRam());
}
#endif
+8 -7
View File
@@ -15,16 +15,15 @@
#include "Version.h" // Auto generated by bot
#include "MyConfig.h"
#include "MyMessage.h"
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <Arduino.h>
#include <stddef.h>
#include <SPI.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include <stdarg.h>
#include "LowPower.h"
#include "utility/LowPower.h"
#include "utility/RF24.h"
#include "utility/RF24_config.h"
#ifdef DEBUG
#define debug(x,...) debugPrint(x, ##__VA_ARGS__)
@@ -218,11 +217,13 @@ class MySensor : public RF24
/**
* getInternalTemp
*
* Read temp from internal (ATMEGA328 only) temperature sensor
* Read temp from internal (ATMEGA328 only) temperature sensor. This reading is very
* inaccurate so we round the result to full degrees celsius.
* http://playground.arduino.cc/Main/InternalTemperatureSensor
*
* @return Temperature in degrees Celsius (one decimal)
* @return Temperature in full degrees Celsius.
*/
float getInternalTemp(void);
int getInternalTemp(void);
@@ -3,7 +3,6 @@
// thread: http://forum.micasaverde.com/index.php/topic,20078.0.html
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
@@ -27,7 +26,7 @@ void loop()
// get the battery Voltage
int sensorValue = analogRead(BATTERY_SENSE_PIN);
Serial.println(sensorValue);
// 1M, 470K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
@@ -48,8 +47,5 @@ void loop()
gw.sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}
// delay to allow transmissions to gateway to be completed before sleep
delay(300);
gw.sleep(SLEEP_TIME);
}
@@ -4,8 +4,6 @@
#include <MySensor.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <Bounce2.h>
#define CHILD_ID 3
@@ -14,6 +12,7 @@
MySensor gw;
Bounce debouncer = Bounce();
int oldValue=-1;
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(CHILD_ID,V_TRIPPED);
@@ -32,7 +31,7 @@ void setup()
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in below.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
gw.present(CHILD_ID, S_DOOR);
}
@@ -3,11 +3,10 @@
#include <SPI.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <RF24.h>
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
#define MAX_ATTACHED_DS18B20 16
unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds)
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
MySensor gw;
@@ -61,9 +60,7 @@ void loop()
lastTemperature[i]=temperature;
}
}
// Power down the radio and sleep Arduino to save batteries.
delay(300);
gw.sleep(SLEEP_TIME * 1000);
gw.sleep(SLEEP_TIME);
}
@@ -1,6 +1,4 @@
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <MySensor.h>
#include <NewPing.h>
@@ -8,7 +6,7 @@
#define TRIGGER_PIN 6 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 5 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
unsigned long SLEEP_TIME = 5; // Sleep time between reads (in seconds)
unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
MySensor gw;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
@@ -31,19 +29,16 @@ void setup()
void loop()
{
int dist = metric?sonar.ping_cm():sonar.ping_in();
Serial.print("Ping: ");
Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
Serial.println(metric?" cm":" in");
if (dist != lastDist) {
gw.send(msg.set(dist));
lastDist = dist;
}
delay(300); //delay to allow serial to fully print before sleep
gw.sleep(SLEEP_TIME*1000);
gw.sleep(SLEEP_TIME);
}
@@ -8,8 +8,6 @@
// to calculate/report watt-number.
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <MySensor.h>
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!)
@@ -18,7 +16,7 @@
#define MAX_WATT 10000 // Max watt value to report. This filetrs outliers.
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define CHILD_ID 1 // Id of the sensor child
unsigned long SEND_FREQUENCY = 20; // Minimum time between send (in seconds). We don't wnat to spam the gateway.
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
MySensor gw;
double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
boolean pcReceived = false;
@@ -88,8 +86,7 @@ void loop()
}
if (SLEEP_MODE) {
delay(300); //delay to allow serial to fully print before sleep
gw.sleep(SEND_FREQUENCY * 1000);
gw.sleep(SEND_FREQUENCY);
}
}
@@ -1,12 +1,11 @@
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
#include <DHT.h>
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 3
unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds)
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
MySensor gw;
DHT dht;
@@ -59,9 +58,7 @@ void loop()
Serial.println(humidity);
}
delay(300); //delay to allow serial to fully print before sleep
gw.sleep(SLEEP_TIME * 1000); //sleep a bit
gw.sleep(SLEEP_TIME); //sleep a bit
}
@@ -7,8 +7,6 @@
#include <MySensor.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <IRLib.h>
int RECV_PIN = 8;
@@ -17,14 +17,13 @@
*/
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
#include <BH1750.h>
#include <Wire.h>
#define CHILD_ID_LIGHT 0
#define LIGHT_SENSOR_ANALOG_PIN 0
unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds)
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
BH1750 lightSensor;
MySensor gw;
@@ -53,6 +52,5 @@ void loop()
lastlux = lux;
}
delay(300); //delay to allow serial to fully print before sleep
gw.sleep(SLEEP_TIME * 1000);
gw.sleep(SLEEP_TIME);
}
@@ -1,11 +1,10 @@
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
#define CHILD_ID_LIGHT 0
#define LIGHT_SENSOR_ANALOG_PIN 0
unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds)
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
MySensor gw;
MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
@@ -30,9 +29,7 @@ void loop()
gw.send(msg.set(lightLevel));
lastLightLevel = lightLevel;
}
delay(300); //delay to allow serial to fully print before sleep
gw.sleep(SLEEP_TIME * 1000);
gw.sleep(SLEEP_TIME);
}
@@ -1,7 +1,7 @@
#include <MySensor.h>
#include <SPI.h>
#include <RF24.h>
unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define CHILD_ID 1 // Id of the sensor child
@@ -32,7 +32,7 @@ void loop()
gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
gw.sleep(INTERRUPT,CHANGE, 120000);
gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
}
@@ -1,5 +1,4 @@
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
@@ -8,7 +7,7 @@
#define TEMP_CHILD 1
#define LIGHT_SENSOR_ANALOG_PIN 0
unsigned long SLEEP_TIME = 60; // Sleep time between reads (in seconds)
unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in seconds)
Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor
MySensor gw;
@@ -28,8 +27,6 @@ MyMessage tempMsg(TEMP_CHILD, V_TEMP);
MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
void setup() {
gw.begin();
@@ -47,7 +44,6 @@ void setup() {
metric = gw.getConfig().isMetric;
}
void loop() {
float pressure = bmp.readPressure();
float temperature = bmp.readTemperature();
@@ -94,8 +90,7 @@ void loop() {
5 = "Unknown (More Time needed)
*/
delay(300); //delay to allow serial to fully print before sleep
gw.sleep(SLEEP_TIME * 1000);
gw.sleep(SLEEP_TIME);
}
int sample(float pressure) {
@@ -3,8 +3,6 @@
#include <MySensor.h>
#include <SPI.h>
#include <RF24.h>
#define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
@@ -27,7 +25,7 @@ void setup()
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(pin, gw.loadState(sensor));
digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
}
}
@@ -5,17 +5,16 @@
#include <MySensor.h>
#include <SPI.h>
#include <RF24.h>
#include <Bounce2.h>
#define RELAY_PIN 4 // Arduino Digital I/O pin number for relay
#define BUTTON_PIN 3 // Arduino Digital I/O pin number for button (with 10k pulldown)
#define BUTTON_PIN 3 // Arduino Digital I/O pin number for button
#define CHILD_ID 1 // Id of the sensor child
#define RELAY_ON 0
#define RELAY_OFF 1
#define RELAY_ON 1
#define RELAY_OFF 0
Bounce debouncer = Bounce();
int oldValue=-1;
int oldValue=0;
bool state;
MySensor gw;
MyMessage msg(CHILD_ID,V_LIGHT);
@@ -36,7 +35,6 @@ void setup()
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID, S_LIGHT);
@@ -45,10 +43,9 @@ void setup()
// Then set relay pins in output mode
pinMode(RELAY_PIN, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(RELAY_PIN, gw.loadState(CHILD_ID));
// Set relay to last known state (using eeprom storage)
state = gw.loadState(CHILD_ID);
digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
}
@@ -61,16 +58,12 @@ void loop()
debouncer.update();
// Get the update value
int value = debouncer.read();
if (value != oldValue && value!=0) {
gw.saveState(CHILD_ID, state);
gw.send(msg.set(state==1?0:1), true); // Send and request ack
oldValue = value;
}
if (value != oldValue && value==0) {
gw.send(msg.set(state?false:true), true); // Send new state and request ack back
}
oldValue = value;
}
void incomingMessage(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
@@ -5,7 +5,6 @@
#include <MySensor.h>
#include <SPI.h>
#include <RF24.h>
MySensor gw;
@@ -9,7 +9,6 @@
#include <MySensor.h>
#include <SPI.h>
#include <Servo.h>
#include <RF24.h>
#define SERVO_DIGITAL_OUT_PIN 3
#define SERVO_MIN 0 // Fine tune your servos min. 0-180
@@ -23,7 +22,6 @@ Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created Sensor gw(9,10);
unsigned long timeOfLastChange = 0;
bool attachedServo = false;
void setup()
{
@@ -1,5 +1,4 @@
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
#define DIGITAL_INPUT_SOIL_SENSOR 3 // Digital input did you attach your soil sensor.
@@ -2,7 +2,6 @@
// Example sketch showing how to request time from controller
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
#include <Time.h>
@@ -10,7 +10,6 @@
//
#include <SPI.h>
#include <RF24.h>
#include <MySensor.h>
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your sensor. (Only 2 and 3 generates interrupt!)
@@ -19,7 +18,7 @@
#define MAX_FLOW 40 // Max flow (l/min) value to report. This filetrs outliers.
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define CHILD_ID 5 // Id of the sensor child
unsigned long SEND_FREQUENCY = 20; // Minimum time between send (in seconds). We don't want to spam the gateway.
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
MySensor gw;
@@ -104,8 +103,7 @@ void loop()
}
if (SLEEP_MODE) {
delay(300); //delay to allow serial to fully print before sleep
gw.sleep(SEND_FREQUENCY * 1000);
gw.sleep(SEND_FREQUENCY);
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+129
View File
@@ -0,0 +1,129 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
Added Arduino Due support from https://github.com/mcrosson/
*/
#ifndef __RF24_CONFIG_H__
#define __RF24_CONFIG_H__
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#include <stddef.h>
//TMRh20:
//#define MINIMAL
// Define _BV for non-Arduino platforms and for Arduino DUE
#if defined (ARDUINO)
#include <SPI.h>
#else
#include <stdint.h>
#include <stdio.h>
#include <string.h>
extern HardwareSPI SPI;
#define _BV(x) (1<<(x))
#endif
#undef SERIAL_DEBUG
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({x;})
#else
#define IF_SERIAL_DEBUG(x)
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
#define printf_P(...)
#endif
#endif
// Avoid spurious warnings
// Arduino DUE is arm and uses traditional PROGMEM constructs
#if 1
#if ! defined( NATIVE ) && defined( ARDUINO ) && ! defined(__arm__)
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
#endif
#endif
// Progmem is Arduino-specific
// Arduino DUE is arm and does not include avr/pgmspace
#if defined(ARDUINO) && ! defined(__arm__)
#include <avr/pgmspace.h>
#define PRIPSTR "%S"
#else
#if ! defined(ARDUINO) // This doesn't work on Arduino DUE
typedef char const char;
#else // Fill in pgm_read_byte that is used, but missing from DUE
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#endif
typedef uint16_t prog_uint16_t;
#define PSTR(x) (x)
#define printf_P printf
#define strlen_P strlen
#define PROGMEM
#define pgm_read_word(p) (*(p))
#define PRIPSTR "%s"
#endif
// ATTiny support code is from https://github.com/jscrane/RF24
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
#include <stdio.h>
#include <Arduino.h>
#include <avr/pgmspace.h>
#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
//#define SPI_CLOCK_DIV64 0x07
#define SPI_MODE0 0x00
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C
#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
class SPIClass {
public:
static byte transfer(byte _data);
// SPI Configuration methods
inline static void attachInterrupt();
inline static void detachInterrupt(); // Default
static void begin(); // Default
static void end();
static void setBitOrder(uint8_t);
static void setDataMode(uint8_t);
static void setClockDivider(uint8_t);
};
extern SPIClass SPI;
#endif //ATTiny
#endif // __RF24_CONFIG_H__
+127
View File
@@ -0,0 +1,127 @@
/*
Copyright (c) 2007 Stefan Engelke <mbox@stefanengelke.de>
Portions Copyright (C) 2011 Greg Copeland
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/* Memory Map */
#define CONFIG 0x00
#define EN_AA 0x01
#define EN_RXADDR 0x02
#define SETUP_AW 0x03
#define SETUP_RETR 0x04
#define RF_CH 0x05
#define RF_SETUP 0x06
#define STATUS 0x07
#define OBSERVE_TX 0x08
#define CD 0x09
#define RX_ADDR_P0 0x0A
#define RX_ADDR_P1 0x0B
#define RX_ADDR_P2 0x0C
#define RX_ADDR_P3 0x0D
#define RX_ADDR_P4 0x0E
#define RX_ADDR_P5 0x0F
#define TX_ADDR 0x10
#define RX_PW_P0 0x11
#define RX_PW_P1 0x12
#define RX_PW_P2 0x13
#define RX_PW_P3 0x14
#define RX_PW_P4 0x15
#define RX_PW_P5 0x16
#define FIFO_STATUS 0x17
#define DYNPD 0x1C
#define FEATURE 0x1D
/* Bit Mnemonics */
#define MASK_RX_DR 6
#define MASK_TX_DS 5
#define MASK_MAX_RT 4
#define EN_CRC 3
#define CRCO 2
#define PWR_UP 1
#define PRIM_RX 0
#define ENAA_P5 5
#define ENAA_P4 4
#define ENAA_P3 3
#define ENAA_P2 2
#define ENAA_P1 1
#define ENAA_P0 0
#define ERX_P5 5
#define ERX_P4 4
#define ERX_P3 3
#define ERX_P2 2
#define ERX_P1 1
#define ERX_P0 0
#define AW 0
#define ARD 4
#define ARC 0
#define PLL_LOCK 4
#define RF_DR 3
#define RF_PWR 6
#define RX_DR 6
#define TX_DS 5
#define MAX_RT 4
#define RX_P_NO 1
#define TX_FULL 0
#define PLOS_CNT 4
#define ARC_CNT 0
#define TX_REUSE 6
#define FIFO_FULL 5
#define TX_EMPTY 4
#define RX_FULL 1
#define RX_EMPTY 0
#define DPL_P5 5
#define DPL_P4 4
#define DPL_P3 3
#define DPL_P2 2
#define DPL_P1 1
#define DPL_P0 0
#define EN_DPL 2
#define EN_ACK_PAY 1
#define EN_DYN_ACK 0
/* Instruction Mnemonics */
#define R_REGISTER 0x00
#define W_REGISTER 0x20
#define REGISTER_MASK 0x1F
#define ACTIVATE 0x50
#define R_RX_PL_WID 0x60
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xA0
#define W_ACK_PAYLOAD 0xA8
#define FLUSH_TX 0xE1
#define FLUSH_RX 0xE2
#define REUSE_TX_PL 0xE3
#define NOP 0xFF
/* Non-P omissions */
#define LNA_HCURR 0
/* P model memory Map */
#define RPD 0x09
#define W_TX_PAYLOAD_NO_ACK 0xB0
/* P model bit Mnemonics */
#define RF_DR_LOW 5
#define RF_DR_HIGH 3
#define RF_PWR_LOW 1
#define RF_PWR_HIGH 2