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
@@ -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);
}
}