Merge master into development
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
// but now can be used in any sensor node. Also the LEDs can now be
|
||||
// disabled in the gateway.
|
||||
|
||||
//#define WITH_LEDS_BLINKING
|
||||
// #define WITH_LEDS_BLINKING
|
||||
|
||||
// The following setting allows you to inverse the blinking feature WITH_LEDS_BLINKING
|
||||
// When WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
|
||||
@@ -103,7 +103,6 @@
|
||||
// Key to use for HMAC calculation in MySigningAtsha204Soft (32 bytes)
|
||||
#define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
|
||||
|
||||
/**********************************
|
||||
* NRF24L01 Driver Defaults
|
||||
***********************************/
|
||||
|
||||
@@ -58,7 +58,7 @@ typedef enum {
|
||||
S_UV, // Uv sensor, V_UV
|
||||
S_WEIGHT, // Personal scale sensor, V_WEIGHT, V_IMPEDANCE
|
||||
S_POWER, // Power meter, V_WATT, V_KWH
|
||||
S_HEATER, // Header device, V_HVAC_SETPOINT_HEAT, V_HVAC_FLOW_STATE
|
||||
S_HEATER, // Header device, V_HVAC_SETPOINT_HEAT, V_HVAC_FLOW_STATE, V_TEMP
|
||||
S_DISTANCE, // Distance sensor, V_DISTANCE
|
||||
S_LIGHT_LEVEL, // Light level sensor, V_LIGHT_LEVEL (uncalibrated in percentage), V_LEVEL (light level in lux)
|
||||
S_ARDUINO_NODE, // Used (internally) for presenting a non-repeating Arduino node
|
||||
@@ -73,7 +73,7 @@ typedef enum {
|
||||
S_RGB_LIGHT, // RGB light. Send color component data using V_RGB. Also supports V_WATT
|
||||
S_RGBW_LIGHT, // RGB light with an additional White component. Send data using V_RGBW. Also supports V_WATT
|
||||
S_COLOR_SENSOR, // Color sensor, send color information using V_RGB
|
||||
S_HVAC, // Thermostat/HVAC device. V_HVAC_SETPOINT_HEAT, V_HVAC_SETPOINT_COLD, V_HVAC_FLOW_STATE, V_HVAC_FLOW_MODE
|
||||
S_HVAC, // Thermostat/HVAC device. V_HVAC_SETPOINT_HEAT, V_HVAC_SETPOINT_COLD, V_HVAC_FLOW_STATE, V_HVAC_FLOW_MODE, V_TEMP
|
||||
S_MULTIMETER, // Multimeter device, V_VOLTAGE, V_CURRENT, V_IMPEDANCE
|
||||
S_SPRINKLER, // Sprinkler, V_STATUS (turn on/off), V_TRIPPED (if fire detecting device)
|
||||
S_WATER_LEAK, // Water leak sensor, V_TRIPPED, V_ARMED
|
||||
@@ -84,42 +84,42 @@ typedef enum {
|
||||
|
||||
// Type of sensor data (for set/req/ack messages)
|
||||
typedef enum {
|
||||
V_TEMP, // S_TEMP
|
||||
V_HUM, // S_HUM
|
||||
V_STATUS, // S_LIGHT, S_DIMMER, S_SPRINKLER, S_HVAC, S_HEATER. Used for setting binary (on/off) status. 1=on, 0=off
|
||||
V_TEMP, // S_TEMP. Temperature S_TEMP, S_HEATER, S_HVAC
|
||||
V_HUM, // S_HUM. Humidity
|
||||
V_STATUS, // S_LIGHT, S_DIMMER, S_SPRINKLER, S_HVAC, S_HEATER. Used for setting/reporting binary (on/off) status. 1=on, 0=off
|
||||
V_LIGHT=2, // Same as V_STATUS
|
||||
V_PERCENTAGE, // S_DIMMER. Used for sending a percentage value (0-100).
|
||||
V_PERCENTAGE, // S_DIMMER. Used for sending a percentage value 0-100 (%).
|
||||
V_DIMMER=3, // S_DIMMER. Same as V_PERCENTAGE.
|
||||
V_PRESSURE, // S_BARO
|
||||
V_FORECAST, // S_BARO
|
||||
V_RAIN, // S_RAIN
|
||||
V_RAINRATE, // S_RAIN
|
||||
V_WIND, // S_WIND
|
||||
V_GUST, // S_WIND
|
||||
V_DIRECTION, // S_WIND
|
||||
V_UV, // S_UV
|
||||
V_WEIGHT, // S_WEIGHT
|
||||
V_DISTANCE, // S_DISTANCE
|
||||
V_IMPEDANCE, // S_MULTIMETER, S_WEIGHT
|
||||
V_ARMED, // S_DOOR, S_MOTION, S_SMOKE, S_SPRINKLER
|
||||
V_TRIPPED, // S_DOOR, S_MOTION, S_SMOKE, S_SPRINKLER (for sprinklers with fire detection)
|
||||
V_WATT, // S_POWER, S_LIGHT, S_DIMMER
|
||||
V_KWH, // S_POWER
|
||||
V_SCENE_ON, // S_SCENE_CONTROLLER
|
||||
V_SCENE_OFF, // S_SCENE_CONTROLLER
|
||||
V_PRESSURE, // S_BARO. Atmospheric Pressure
|
||||
V_FORECAST, // S_BARO. Whether forecast. string of "stable", "sunny", "cloudy", "unstable", "thunderstorm" or "unknown"
|
||||
V_RAIN, // S_RAIN. Amount of rain
|
||||
V_RAINRATE, // S_RAIN. Rate of rain
|
||||
V_WIND, // S_WIND. Wind speed
|
||||
V_GUST, // S_WIND. Gust
|
||||
V_DIRECTION, // S_WIND. Wind direction 0-360 (degrees)
|
||||
V_UV, // S_UV. UV light level
|
||||
V_WEIGHT, // S_WEIGHT. Weight(for scales etc)
|
||||
V_DISTANCE, // S_DISTANCE. Distance
|
||||
V_IMPEDANCE, // S_MULTIMETER, S_WEIGHT. Impedance value
|
||||
V_ARMED, // S_DOOR, S_MOTION, S_SMOKE, S_SPRINKLER. Armed status of a security sensor. 1 = Armed, 0 = Bypassed
|
||||
V_TRIPPED, // S_DOOR, S_MOTION, S_SMOKE, S_SPRINKLER, S_WATER_LEAK, S_SOUND, S_VIBRATION, S_MOISTURE. Tripped status of a security sensor. 1 = Tripped, 0
|
||||
V_WATT, // S_POWER, S_LIGHT, S_DIMMER, S_RGB, S_RGBW. Watt value for power meters
|
||||
V_KWH, // S_POWER. Accumulated number of KWH for a power meter
|
||||
V_SCENE_ON, // S_SCENE_CONTROLLER. Turn on a scene
|
||||
V_SCENE_OFF, // S_SCENE_CONTROLLER. Turn of a scene
|
||||
V_HEATER, // Deprecated. Use V_HVAC_FLOW_STATE instead.
|
||||
V_HVAC_FLOW_STATE=21, // HVAC flow state ("Off", "HeatOn", "CoolOn", or "AutoChangeOver"). S_HEATER, S_HVAC
|
||||
V_HVAC_SPEED, // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto")
|
||||
V_LIGHT_LEVEL, // Used for sending light level in uncalibrated percentage. See also V_LEVEL (light level in lux). S_LIGHT_LEVEL
|
||||
V_HVAC_FLOW_STATE=21, // S_HEATER, S_HVAC. HVAC flow state ("Off", "HeatOn", "CoolOn", or "AutoChangeOver")
|
||||
V_HVAC_SPEED, // S_HVAC, S_HEATER. HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto")
|
||||
V_LIGHT_LEVEL, // S_LIGHT_LEVEL. Uncalibrated light level. 0-100%. Use V_LEVEL for light level in lux
|
||||
V_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5,
|
||||
V_UP, // S_COVER
|
||||
V_DOWN, // S_COVER
|
||||
V_STOP, // S_COVER
|
||||
V_IR_SEND, // S_IR
|
||||
V_IR_RECEIVE, // S_IR
|
||||
V_FLOW, // S_WATER
|
||||
V_VOLUME, // S_WATER
|
||||
V_LOCK_STATUS, // S_LOCK
|
||||
V_UP, // S_COVER. Window covering. Up
|
||||
V_DOWN, // S_COVER. Window covering. Down
|
||||
V_STOP, // S_COVER. Window covering. Stop
|
||||
V_IR_SEND, // S_IR. Send out an IR-command
|
||||
V_IR_RECEIVE, // S_IR. This message contains a received IR-command
|
||||
V_FLOW, // S_WATER. Flow of water (in meter)
|
||||
V_VOLUME, // S_WATER. Water volume
|
||||
V_LOCK_STATUS, // S_LOCK. Set or get lock status. 1=Locked, 0=Unlocked
|
||||
V_LEVEL, // S_DUST, S_AIR_QUALITY, S_SOUND (dB), S_VIBRATION (hz), S_LIGHT_LEVEL (lux)
|
||||
V_VOLTAGE, // S_MULTIMETER
|
||||
V_CURRENT, // S_MULTIMETER
|
||||
@@ -128,15 +128,16 @@ typedef enum {
|
||||
// Sent as ASCII hex: RRGGBB (RR=red, GG=green, BB=blue component)
|
||||
V_RGBW, // S_RGBW_LIGHT
|
||||
// Used for sending color information to multi color LED lighting.
|
||||
// Sent as ASCII hex: RRGGBBWW (WW=while component)
|
||||
// Sent as ASCII hex: RRGGBBWW (WW=white component)
|
||||
V_ID, // S_TEMP
|
||||
// Used for sending in sensors hardware ids (i.e. OneWire DS1820b).
|
||||
V_UNIT_PREFIX, // Allows sensors to send in a string representing the
|
||||
// unit prefix to be displayed in GUI, not parsed by controller! E.g. cm, m, km, inch.
|
||||
// Can be used for S_DISTANCE or gas concentration (S_DUST, S_AIR_QUALITY)
|
||||
V_HVAC_SETPOINT_COOL, // HVAC cool setpoint (Integer between 0-100). S_HVAC
|
||||
V_HVAC_SETPOINT_HEAT, // HVAC/Heater setpoint (Integer between 0-100). S_HEATER, S_HVAC
|
||||
V_HVAC_FLOW_MODE, // Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn"). S_HVAC
|
||||
V_UNIT_PREFIX, // S_DUST, S_AIR_QUALITY
|
||||
// Allows sensors to send in a string representing the
|
||||
// unit prefix to be displayed in GUI, not parsed by controller! E.g. cm, m, km, inch.
|
||||
// Can be used for S_DISTANCE or gas concentration
|
||||
V_HVAC_SETPOINT_COOL, // S_HVAC. HVAC cool setpoint (Integer between 0-100)
|
||||
V_HVAC_SETPOINT_HEAT, // S_HEATER, S_HVAC. HVAC/Heater setpoint (Integer between 0-100)
|
||||
V_HVAC_FLOW_MODE, // S_HVAC. Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn")
|
||||
|
||||
} mysensor_data;
|
||||
|
||||
|
||||
@@ -555,6 +555,7 @@ boolean MySensor::process() {
|
||||
#endif
|
||||
|
||||
uint8_t len = radio.receive((uint8_t *)&msg);
|
||||
(void)len; //until somebody makes use of 'len'
|
||||
#ifdef WITH_LEDS_BLINKING
|
||||
rxBlink(1);
|
||||
#endif
|
||||
|
||||
@@ -349,11 +349,6 @@ class MySensor
|
||||
|
||||
MyMessage msg; // Buffer for incoming messages.
|
||||
MyMessage tmpMsg ; // Buffer for temporary messages (acks and nonces among others).
|
||||
#ifdef MY_SIGNING_FEATURE
|
||||
uint16_t doSign[16]; // Bitfield indicating which sensors require signed communication
|
||||
MyMessage msgSign; // Buffer for message to sign.
|
||||
MySigning& signer;
|
||||
#endif
|
||||
|
||||
#ifdef WITH_LEDS_BLINKING
|
||||
uint8_t pinRx; // Rx led pin
|
||||
@@ -370,6 +365,11 @@ class MySensor
|
||||
#endif
|
||||
|
||||
MyTransport& radio;
|
||||
#ifdef MY_SIGNING_FEATURE
|
||||
uint16_t doSign[16]; // Bitfield indicating which sensors require signed communication
|
||||
MyMessage msgSign; // Buffer for message to sign.
|
||||
MySigning& signer;
|
||||
#endif
|
||||
MyHw& hw;
|
||||
|
||||
boolean sendWrite(uint8_t dest, MyMessage &message);
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "MySigning.h"
|
||||
#include "MySigningAtsha204.h"
|
||||
|
||||
#define SIGNING_IDENTIFIER (1)
|
||||
|
||||
// Uncomment this to get some useful serial debug info (Serial.print and Serial.println expected)
|
||||
//#define DEBUG_SIGNING
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
#include "utility/ATSHA204.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define SIGNING_IDENTIFIER (1)
|
||||
|
||||
#ifdef MY_SECURE_NODE_WHITELISTING
|
||||
typedef struct {
|
||||
uint8_t nodeId;
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "MySigningAtsha204Soft.h"
|
||||
#include "utility/sha256.h"
|
||||
|
||||
#define SIGNING_IDENTIFIER (1)
|
||||
|
||||
// Uncomment this to get some useful serial debug info (Serial.print and Serial.println expected)
|
||||
//#define DEBUG_SIGNING
|
||||
|
||||
@@ -72,15 +74,14 @@ MySigningAtsha204Soft::MySigningAtsha204Soft(bool requestSignatures,
|
||||
uint8_t randomseedPin)
|
||||
:
|
||||
MySigning(requestSignatures),
|
||||
rndPin(randomseedPin),
|
||||
#ifdef MY_SECURE_NODE_WHITELISTING
|
||||
whitlist_sz(nof_whitelist_entries),
|
||||
whitelist(the_whitelist),
|
||||
node_serial_info(the_serial),
|
||||
#endif
|
||||
Sha256(),
|
||||
verification_ongoing(false),
|
||||
Sha256()
|
||||
|
||||
rndPin(randomseedPin)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
#include "utility/sha256.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define SIGNING_IDENTIFIER (1)
|
||||
|
||||
#ifdef MY_SECURE_NODE_WHITELISTING
|
||||
typedef struct {
|
||||
uint8_t nodeId;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "MySigning.h"
|
||||
#include "MySigningNone.h"
|
||||
|
||||
#define SIGNING_IDENTIFIER (0)
|
||||
|
||||
// Uncomment this to get some useful serial debug info (Serial.print and Serial.println expected)
|
||||
//#define DEBUG_SIGNING
|
||||
|
||||
@@ -61,6 +63,7 @@ MySigningNone::MySigningNone() : MySigning() {
|
||||
}
|
||||
|
||||
bool MySigningNone::getNonce(MyMessage &msg) {
|
||||
(void)msg;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,6 +72,7 @@ bool MySigningNone::checkTimer() {
|
||||
}
|
||||
|
||||
bool MySigningNone::putNonce(MyMessage &msg) {
|
||||
(void)msg;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,6 @@
|
||||
#include "MySigning.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define SIGNING_IDENTIFIER (0)
|
||||
|
||||
// The "none" signing driver that can be used for nodes
|
||||
// not requiring signing
|
||||
// It does check SIGNING_IDENTIFIER byte to avoid illegal mixing of signing back-ends in
|
||||
|
||||
@@ -74,6 +74,7 @@ bool MyTransportNRF24::send(uint8_t to, const void* data, uint8_t len) {
|
||||
bool MyTransportNRF24::available(uint8_t *to) {
|
||||
uint8_t pipe = 255;
|
||||
boolean avail = rf24.available(&pipe);
|
||||
(void)avail; //until somebody makes use of 'avail'
|
||||
if (pipe == CURRENT_NODE_PIPE)
|
||||
*to = _address;
|
||||
else if (pipe == BROADCAST_PIPE)
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
#include <SPI.h>
|
||||
#include <MySensor.h>
|
||||
|
||||
#define DEBUG 1 // Debug enables Serial.print 1 = Yes 0 = No
|
||||
|
||||
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
|
||||
|
||||
MySensor gw;
|
||||
@@ -41,7 +39,11 @@ int oldBatteryPcnt = 0;
|
||||
void setup()
|
||||
{
|
||||
// use the 1.1 V internal reference
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
analogReference(INTERNAL1V1);
|
||||
#else
|
||||
analogReference(INTERNAL);
|
||||
#endif
|
||||
gw.begin();
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
@@ -52,7 +54,7 @@ void loop()
|
||||
{
|
||||
// get the battery Voltage
|
||||
int sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
#if DEBUG > 0
|
||||
#ifdef DEBUG
|
||||
Serial.println(sensorValue);
|
||||
#endif
|
||||
|
||||
@@ -63,7 +65,7 @@ void loop()
|
||||
float batteryV = sensorValue * 0.003363075;
|
||||
int batteryPcnt = sensorValue / 10;
|
||||
|
||||
#if DEBUG > 0
|
||||
#ifdef DEBUG
|
||||
Serial.print("Battery Voltage: ");
|
||||
Serial.print(batteryV);
|
||||
Serial.println(" V");
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* MH-Z14 CO2 sensor
|
||||
*
|
||||
* Wiring:
|
||||
* Pad 1, Pad 5: Vin (Voltage input 4.5V-6V)
|
||||
* Pad 2, Pad 3, Pad 12: GND
|
||||
* Pad 6: PWM output ==> pin 6
|
||||
*
|
||||
* From: http://davidegironi.blogspot.fr/2014/01/co2-meter-using-ndir-infrared-mh-z14.html
|
||||
* MH-Z14 has a PWM output, with a sensitivity range of 0ppm to 2000ppm CO2, an accurancy of ±200ppm.
|
||||
* The cycle is 1004ms±5%, given the duty cicle Th (pulse high), Tl is 1004-Th, we can convert it to CO2 value using the formula:
|
||||
* CO2ppm = 2000 * (Th - 2ms) /(Th + Tl - 4ms)
|
||||
* From: http://airqualityegg.wikispaces.com/Sensor+Tests
|
||||
* - response time is less than 30 s
|
||||
* - 3 minute warm up time
|
||||
* datasheet: http://www.futurlec.com/Datasheet/Sensor/MH-Z14.pdf
|
||||
* Contributor: epierre
|
||||
**/
|
||||
|
||||
|
||||
#include <MySensor.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define CHILD_ID_AIQ 0
|
||||
#define AIQ_SENSOR_ANALOG_PIN 6
|
||||
|
||||
unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
|
||||
|
||||
float valAIQ =0.0;
|
||||
float lastAIQ =0.0;
|
||||
|
||||
MySensor gw;
|
||||
MyMessage msg(CHILD_ID_AIQ, V_LEVEL);
|
||||
MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX);
|
||||
|
||||
void setup()
|
||||
{
|
||||
gw.begin();
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
gw.sendSketchInfo("AIQ Sensor CO2 MH-Z14", "1.0");
|
||||
|
||||
// Register all sensors to gateway (they will be created as child devices)
|
||||
gw.present(CHILD_ID_AIQ, S_AIR_QUALITY);
|
||||
gw.send(msg2.set("ppm"));
|
||||
|
||||
gw.sleep(SLEEP_TIME);
|
||||
|
||||
pinMode(AIQ_SENSOR_ANALOG_PIN, INPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
//unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH);
|
||||
while(digitalRead(AIQ_SENSOR_ANALOG_PIN) == HIGH) {;}
|
||||
//wait for the pin to go HIGH and measure HIGH time
|
||||
unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH);
|
||||
|
||||
//Serial.print(duration/1000); Serial.println(" ms ");
|
||||
//from datasheet
|
||||
//CO2 ppm = 2000 * (Th - 2ms) / (Th + Tl - 4ms)
|
||||
// given Tl + Th = 1004
|
||||
// Tl = 1004 - Th
|
||||
// = 2000 * (Th - 2ms) / (Th + 1004 - Th -4ms)
|
||||
// = 2000 * (Th - 2ms) / 1000 = 2 * (Th - 2ms)
|
||||
long co2ppm = 2 * ((duration/1000) - 2);
|
||||
//Serial.print(co2ppm);
|
||||
if ((co2ppm != lastAIQ)&&(abs(co2ppm-lastAIQ)>=10)) {
|
||||
gw.send(msg.set((long)ceil(co2ppm)));
|
||||
lastAIQ = ceil(co2ppm);
|
||||
}
|
||||
|
||||
//Serial.println();
|
||||
|
||||
// Power down the radio. Note that the radio will get powered back up
|
||||
// on the next write() call.
|
||||
gw.sleep(SLEEP_TIME); //sleep for: sleepTime
|
||||
}
|
||||
+1
-1
@@ -133,7 +133,7 @@ void incomingMessage(const MyMessage &message)
|
||||
newLevel = loadLevelState(EEPROM_DIM_LEVEL_SAVE);
|
||||
}
|
||||
// Send dimmer level back to controller with ack enabled
|
||||
gw.send(dimmerMsg.set(0), true);
|
||||
gw.send(dimmerMsg.set(newLevel), true);
|
||||
// We do not change any levels here until ack comes back from gateway
|
||||
return;
|
||||
} else if (message.type == V_DIMMER) {
|
||||
|
||||
@@ -51,7 +51,7 @@ void setup()
|
||||
|
||||
// Register all sensors to gw (they will be created as child devices)
|
||||
gw.present(CHILD_ID, S_DISTANCE);
|
||||
boolean metric = gw.getConfig().isMetric;
|
||||
metric = gw.getConfig().isMetric;
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* Dust Sensor for SamYoung DSM501
|
||||
* connect the sensor as follows :
|
||||
* Pin 2 of dust sensor PM1 -> Digital 3 (PMW)
|
||||
* Pin 3 of dust sensor -> +5V
|
||||
* Pin 4 of dust sensor PM2.5 -> Digital 6 (PWM)
|
||||
* Pin 5 of dust sensor -> Ground
|
||||
* Datasheet: http://www.samyoungsnc.com/products/3-1%20Specification%20DSM501.pdf
|
||||
* Contributor: epierre
|
||||
**/
|
||||
|
||||
|
||||
#include <MySensor.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define CHILD_ID_DUST_PM10 0
|
||||
#define CHILD_ID_DUST_PM25 1
|
||||
#define DUST_SENSOR_DIGITAL_PIN_PM10 6
|
||||
#define DUST_SENSOR_DIGITAL_PIN_PM25 3
|
||||
|
||||
unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
|
||||
//VARIABLES
|
||||
int val = 0; // variable to store the value coming from the sensor
|
||||
float valDUSTPM25 =0.0;
|
||||
float lastDUSTPM25 =0.0;
|
||||
float valDUSTPM10 =0.0;
|
||||
float lastDUSTPM10 =0.0;
|
||||
unsigned long duration;
|
||||
unsigned long starttime;
|
||||
unsigned long endtime;
|
||||
unsigned long sampletime_ms = 30000;
|
||||
unsigned long lowpulseoccupancy = 0;
|
||||
float ratio = 0;
|
||||
long concentrationPM25 = 0;
|
||||
long concentrationPM10 = 0;
|
||||
|
||||
MySensor gw;
|
||||
MyMessage dustMsgPM10(CHILD_ID_DUST_PM10, V_LEVEL);
|
||||
MyMessage msgPM10(CHILD_ID_DUST_PM10, V_UNIT_PREFIX);
|
||||
MyMessage dustMsgPM25(CHILD_ID_DUST_PM25, V_LEVEL);
|
||||
MyMessage msgPM25(CHILD_ID_DUST_PM25, V_UNIT_PREFIX);
|
||||
|
||||
void setup()
|
||||
{
|
||||
gw.begin();
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
gw.sendSketchInfo("Dust Sensor DSM501", "1.4");
|
||||
|
||||
// Register all sensors to gateway (they will be created as child devices)
|
||||
gw.present(CHILD_ID_DUST_PM10, S_DUST);
|
||||
gw.send(msgPM10.set("ppm"));
|
||||
gw.present(CHILD_ID_DUST_PM25, S_DUST);
|
||||
gw.send(msgPM25.set("ppm"));
|
||||
|
||||
pinMode(DUST_SENSOR_DIGITAL_PIN_PM10,INPUT);
|
||||
pinMode(DUST_SENSOR_DIGITAL_PIN_PM25,INPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
//get PM 2.5 density of particles over 2.5 μm.
|
||||
concentrationPM25=(long)getPM(DUST_SENSOR_DIGITAL_PIN_PM25);
|
||||
Serial.print("PM25: ");
|
||||
Serial.println(concentrationPM25);
|
||||
Serial.print("\n");
|
||||
|
||||
if ((concentrationPM25 != lastDUSTPM25)&&(concentrationPM25>0)) {
|
||||
gw.send(dustMsgPM25.set((long)ceil(concentrationPM25)));
|
||||
lastDUSTPM25 = ceil(concentrationPM25);
|
||||
}
|
||||
//get PM 1.0 - density of particles over 1 μm.
|
||||
concentrationPM10=getPM(DUST_SENSOR_DIGITAL_PIN_PM10);
|
||||
Serial.print("PM10: ");
|
||||
Serial.println(concentrationPM10);
|
||||
Serial.print("\n");
|
||||
//ppmv=mg/m3 * (0.08205*Tmp)/Molecular_mass
|
||||
//0.08205 = Universal gas constant in atm·m3/(kmol·K)
|
||||
int temp=20; //external temperature, if you can replace this with a DHT11 or better
|
||||
long ppmv=(concentrationPM10*0.0283168/100/1000) * (0.08205*temp)/0.01;
|
||||
|
||||
if ((ceil(concentrationPM10) != lastDUSTPM10)&&((long)concentrationPM10>0)) {
|
||||
gw.send(dustMsgPM10.set((long)ppmv));
|
||||
lastDUSTPM10 = ceil(concentrationPM10);
|
||||
}
|
||||
|
||||
//sleep to save on radio
|
||||
gw.sleep(SLEEP_TIME);
|
||||
|
||||
}
|
||||
|
||||
|
||||
long getPM(int DUST_SENSOR_DIGITAL_PIN) {
|
||||
|
||||
starttime = millis();
|
||||
|
||||
while (1) {
|
||||
|
||||
duration = pulseIn(DUST_SENSOR_DIGITAL_PIN, LOW);
|
||||
lowpulseoccupancy += duration;
|
||||
endtime = millis();
|
||||
|
||||
if ((endtime-starttime) > sampletime_ms)
|
||||
{
|
||||
ratio = (lowpulseoccupancy-endtime+starttime)/(sampletime_ms*10.0); // Integer percentage 0=>100
|
||||
long concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
|
||||
//Serial.print("lowpulseoccupancy:");
|
||||
//Serial.print(lowpulseoccupancy);
|
||||
//Serial.print("\n");
|
||||
//Serial.print("ratio:");
|
||||
//Serial.print(ratio);
|
||||
//Serial.print("\n");
|
||||
//Serial.print("DSM501A:");
|
||||
//Serial.println(concentration);
|
||||
//Serial.print("\n");
|
||||
|
||||
lowpulseoccupancy = 0;
|
||||
return(concentration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ void setup()
|
||||
//check for saved date in EEPROM
|
||||
DEBUG_PRINTLN(F("Checking EEPROM for stored date:"));
|
||||
delay(500);
|
||||
if (gw.loadState(0) == 0xFF); // EEPROM flag
|
||||
if (gw.loadState(0) == 0xFF) // EEPROM flag
|
||||
{
|
||||
DEBUG_PRINTLN(F("Retreiving last run time from EEPROM..."));
|
||||
for (int i = 0; i < 4 ; i++)
|
||||
@@ -439,7 +439,7 @@ void loop()
|
||||
state = STAND_BY_ALL_OFF;
|
||||
}
|
||||
}
|
||||
else if (state = ZONE_SELECT_MENU)
|
||||
else if (state == ZONE_SELECT_MENU)
|
||||
{
|
||||
displayMenu();
|
||||
}
|
||||
@@ -771,6 +771,9 @@ void updateDisplay()
|
||||
lcd.print(totalTimeRan);
|
||||
lcd.print(" Minutes ");
|
||||
}
|
||||
default:
|
||||
// what of ZONE_SELECT_MENU?
|
||||
break;
|
||||
}
|
||||
lastUpdateTime = millis();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ void setup()
|
||||
// Register all sensors to gw (they will be created as child devices)
|
||||
gw.present(CHILD_ID_DISTANCE, S_DISTANCE);
|
||||
gw.present(CHILD_ID_INTENSITY, S_CUSTOM);
|
||||
boolean metric = gw.getConfig().isMetric;
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Playing With Fusion: AS3935 Lightning Sensor, SEN-39001");
|
||||
@@ -118,4 +117,4 @@ void loop()
|
||||
void AS3935_ISR()
|
||||
{
|
||||
AS3935_ISR_Trig = 1;
|
||||
}␍
|
||||
}
|
||||
|
||||
@@ -279,6 +279,7 @@ void processMQTTMessage(char *inputString, uint8_t inputPos) {
|
||||
uint8_t i = 0;
|
||||
buffer[0]= 0;
|
||||
buffsize = 0;
|
||||
(void)inputPos;
|
||||
|
||||
if ((uint8_t)inputString[0] >> 4 == MQTTCONNECT) {
|
||||
buffer[buffsize++] = MQTTCONNACK << 4;
|
||||
@@ -336,7 +337,7 @@ void processMQTTMessage(char *inputString, uint8_t inputPos) {
|
||||
} else if (i==2) {
|
||||
msg.sensor = atoi(str); //SensorID
|
||||
} else if (i==3) {
|
||||
char match=255; //SensorType
|
||||
unsigned char match=255; //SensorType
|
||||
#ifdef MQTT_TRANSLATE_TYPES
|
||||
|
||||
for (uint8_t j=0; strcpy_P(convBuf, (char*)pgm_read_word(&(vType[j]))) ; j++) {
|
||||
@@ -348,7 +349,7 @@ void processMQTTMessage(char *inputString, uint8_t inputPos) {
|
||||
}
|
||||
|
||||
#endif
|
||||
if ( atoi(str)!=0 || str=="0" ) {
|
||||
if ( atoi(str)!=0 || (str[0]=='0' && str[1] =='\0') ) {
|
||||
match=atoi(str);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
* MockMySensors
|
||||
* FakeMySensors
|
||||
*
|
||||
* This skecth is intended to crate fake sensors which register and respond to the controller
|
||||
*
|
||||
* Barduino 2015
|
||||
* Barduino, GizMoCuz 2015
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <MySensor.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// SPI Pins
|
||||
#define CE_PIN 9
|
||||
@@ -18,14 +18,7 @@
|
||||
#define SHORT_WAIT 50
|
||||
|
||||
#define SKETCH_NAME "FakeMySensors "
|
||||
#define SKETCH_VERSION "v0.2"
|
||||
|
||||
// Define Sensors ids
|
||||
/* S_DOOR, S_MOTION, S_SMOKE, S_LIGHT, S_DIMMER, S_COVER, S_TEMP, S_HUM, S_BARO, S_WIND,
|
||||
S_RAIN, S_UV, S_WEIGHT, S_POWER, S_HEATER, S_DISTANCE, S_LIGHT_LEVEL, S_ARDUINO_NODE,
|
||||
S_ARDUINO_REPEATER_NODE, S_LOCK, S_IR, S_WATER, S_AIR_QUALITY, S_CUSTOM, S_DUST,
|
||||
S_SCENE_CONTROLLER
|
||||
*/
|
||||
#define SKETCH_VERSION "v0.3"
|
||||
|
||||
////#define ID_S_ARDUINO_NODE //auto defined in initialization
|
||||
////#define ID_S_ARDUINO_REPEATER_NODE //auto defined in initialization
|
||||
@@ -40,29 +33,28 @@
|
||||
//#define ID_S_HUM 8
|
||||
//#define ID_S_BARO 9
|
||||
//#define ID_S_WIND 10
|
||||
//#define ID_S_RAIN 11
|
||||
//#define ID_S_RAIN 11
|
||||
//#define ID_S_UV 12
|
||||
//#define ID_S_WEIGHT 13
|
||||
#define ID_S_POWER 14
|
||||
#define ID_S_HEATER 15
|
||||
#define ID_S_DISTANCE 16
|
||||
#define ID_S_LIGHT_LEVEL 17
|
||||
#define ID_S_LOCK 18
|
||||
#define ID_S_IR 19
|
||||
#define ID_S_WATER 20
|
||||
#define ID_S_AIR_QUALITY 21
|
||||
#define ID_S_DUST 22
|
||||
#define ID_S_SCENE_CONTROLLER 23
|
||||
|
||||
#define ID_S_CUSTOM 24
|
||||
//#define ID_S_POWER 14
|
||||
//#define ID_S_HEATER 15 <<-- not correctly implemented (1.5 API)
|
||||
//#define ID_S_DISTANCE 16
|
||||
//#define ID_S_LIGHT_LEVEL 17
|
||||
//#define ID_S_LOCK 18
|
||||
//#define ID_S_IR 19
|
||||
//#define ID_S_WATER 20
|
||||
//#define ID_S_AIR_QUALITY 21
|
||||
//#define ID_S_DUST 22
|
||||
//#define ID_S_SCENE_CONTROLLER 23
|
||||
//#define ID_S_CUSTOM 24
|
||||
|
||||
// Global Vars
|
||||
unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
|
||||
unsigned long SLEEP_TIME = 12000; // Sleep time between reads (in milliseconds)
|
||||
boolean metric = true;
|
||||
long randNumber;
|
||||
|
||||
// Instanciate MySersors Gateway
|
||||
MySensor gw(CE_PIN,CS_PIN);
|
||||
MySensor gw;
|
||||
|
||||
//Instanciate Messages objects
|
||||
|
||||
@@ -134,8 +126,10 @@ MySensor gw(CE_PIN,CS_PIN);
|
||||
#endif
|
||||
|
||||
#ifdef ID_S_HEATER
|
||||
MyMessage msg_S_HEATER_M(ID_S_HEATER,V_HEATER);
|
||||
MyMessage msg_S_HEATER_S(ID_S_HEATER,V_HEATER_SW);
|
||||
float current_set_point=21.5;
|
||||
MyMessage msg_S_HEATER_SP(ID_S_HEATER,V_HVAC_SETPOINT_HEAT);
|
||||
MyMessage msg_S_HEATER_F(ID_S_HEATER,V_HVAC_SETPOINT_HEAT);
|
||||
MyMessage msg_S_HEATER_T(ID_S_HEATER,V_TEMP);
|
||||
#endif
|
||||
|
||||
#ifdef ID_S_DISTANCE
|
||||
@@ -161,11 +155,11 @@ MySensor gw(CE_PIN,CS_PIN);
|
||||
#endif
|
||||
|
||||
#ifdef ID_S_AIR_QUALITY
|
||||
MyMessage msg_S_AIR_QUALITY(ID_S_AIR_QUALITY,V_VAR1);
|
||||
MyMessage msg_S_AIR_QUALITY(ID_S_AIR_QUALITY,V_LEVEL);
|
||||
#endif
|
||||
|
||||
#ifdef ID_S_DUST
|
||||
MyMessage msg_S_DUST(ID_S_DUST,V_DUST_LEVEL);
|
||||
MyMessage msg_S_DUST(ID_S_DUST,V_LEVEL);
|
||||
#endif
|
||||
|
||||
#ifdef ID_S_SCENE_CONTROLLER
|
||||
@@ -241,13 +235,13 @@ void setup()
|
||||
#endif
|
||||
|
||||
#ifdef ID_S_COVER
|
||||
Serial.println(" S_COVER";
|
||||
Serial.println(" S_COVER");
|
||||
gw.present(ID_S_COVER,S_COVER);
|
||||
gw.wait(SHORT_WAIT);
|
||||
#endif
|
||||
|
||||
#ifdef ID_S_TEMP
|
||||
Serial.println(" S_TMEP");
|
||||
Serial.println(" S_TEMP");
|
||||
gw.present(ID_S_TEMP,S_TEMP);
|
||||
gw.wait(SHORT_WAIT);
|
||||
#endif
|
||||
@@ -381,7 +375,7 @@ void loop()
|
||||
gw.wait(LONG_WAIT);
|
||||
|
||||
//Read Sensors
|
||||
#ifdef S_ID_DOOR
|
||||
#ifdef ID_S_DOOR
|
||||
door();
|
||||
#endif
|
||||
|
||||
@@ -492,9 +486,7 @@ void receiveTime(unsigned long controllerTime) {
|
||||
|
||||
}
|
||||
|
||||
//void door(){}
|
||||
|
||||
#ifdef S_ID_DOOR
|
||||
#ifdef ID_S_DOOR
|
||||
void door(){
|
||||
|
||||
Serial.print("Door is: " );
|
||||
@@ -623,7 +615,7 @@ void hum(){
|
||||
void baro(){
|
||||
|
||||
const char *weather[] = {"stable","sunny","cloudy","unstable","thunderstorm","unknown"};
|
||||
long pressure = map(randNumber,1,100,87000,108600);
|
||||
long pressure = map(randNumber,1,100,900,1200);
|
||||
int forecast = map(randNumber,1,100,0,5);
|
||||
|
||||
Serial.print("Atmosferic Pressure is: " );
|
||||
@@ -726,8 +718,9 @@ void power(){
|
||||
|
||||
#ifdef ID_S_HEATER
|
||||
void heater(){
|
||||
int heater_mode = gw.loadState(ID_S_HEATER);
|
||||
bool heater_switch = gw.loadState(ID_S_HEATER+1);
|
||||
int heater_set_point = gw.loadState(ID_S_HEATER);
|
||||
int heater_flow_state = gw.loadState(ID_S_HEATER+1);
|
||||
int heater_temp = gw.loadState(ID_S_HEATER+2);
|
||||
|
||||
Serial.print("Heater mode is: " );
|
||||
|
||||
@@ -754,6 +747,11 @@ void heater(){
|
||||
Serial.println(heater_switch?"On":"Off");
|
||||
|
||||
gw.send(msg_S_HEATER_S.set(heater_switch));
|
||||
|
||||
Serial.print("Heater Temperature is: " );
|
||||
Serial.println(map(randNumber,1,100,0,45));
|
||||
|
||||
gw.send(msg_S_HEATER_T.set(map(randNumber,1,100,0,45)));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@ Arduino sketch to fake sensor for the MySensors Library
|
||||
|
||||
This skecth is intended to crate fake sensors which register and respond to the controller
|
||||
|
||||
Barduino 2015
|
||||
Barduino, GizMoCuz 2015
|
||||
-----------------
|
||||
|
||||
Comment/Uncomment the sensors you would like to test
|
||||
@@ -12,4 +12,4 @@ Arduino Uno R3 can support about 12 sensors before it runs out of memory.
|
||||
You probably need to turn of the MySensor Lib debug to save some memory
|
||||
|
||||
Nest step will be to remove the read/write to the eprom
|
||||
and extend to support the v1.5 sensors
|
||||
and extend 'ID_S_HEATER' to support the v1.5 API
|
||||
|
||||
@@ -68,16 +68,16 @@ NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and
|
||||
MySensor gw;
|
||||
MyMessage msg(CHILD_ID,V_TRIPPED);
|
||||
int oldParkedStatus=-1;
|
||||
int sendInterval = 5000; // Send park status at maximum every 5 second.
|
||||
unsigned long sendInterval = 5000; // Send park status at maximum every 5 second.
|
||||
unsigned long lastSend;
|
||||
#endif
|
||||
|
||||
int blinkInterval = 100; // blink interval (milliseconds)
|
||||
unsigned long blinkInterval = 100; // blink interval (milliseconds)
|
||||
unsigned long lastBlinkPeriod;
|
||||
bool blinkColor = true;
|
||||
|
||||
// To make a fading motion on the led ring/tape we only move one pixel/distDebounce time
|
||||
int distDebounce = 30;
|
||||
unsigned long distDebounce = 30;
|
||||
unsigned long lastDebouncePeriod;
|
||||
int numLightPixels=0;
|
||||
int skipZero=0;
|
||||
@@ -161,4 +161,4 @@ void loop() {
|
||||
}
|
||||
pixels.show(); // This sends the updated pixel color to the hardware.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* REVISION HISTORY
|
||||
* Version 1.0 - Created by vil1driver
|
||||
*
|
||||
* DESCRIPTION
|
||||
* RGB led strip controled with three dimmers + one On/Off for run/stop rgb color cycle :p
|
||||
*
|
||||
*/
|
||||
|
||||
#define SN "RGB Led strip 3D"
|
||||
#define SV "v1"
|
||||
|
||||
// Load mysensors library
|
||||
#include <MySensor.h>
|
||||
// Load Serial Peripheral Interface library
|
||||
#include <SPI.h>
|
||||
|
||||
// Arduino pin attached to MOSFET Gate pin
|
||||
#define RED_PIN 3
|
||||
#define GREEN_PIN 5
|
||||
#define BLUE_PIN 6
|
||||
|
||||
MySensor gw;
|
||||
|
||||
// Define message name and type to send sensor info
|
||||
MyMessage RedStatus(RED_PIN, V_DIMMER);
|
||||
MyMessage GreenStatus(GREEN_PIN, V_DIMMER);
|
||||
MyMessage BlueStatus(BLUE_PIN, V_DIMMER);
|
||||
MyMessage Status(1, V_DIMMER);
|
||||
MyMessage rgbShowState(0, V_LIGHT);
|
||||
|
||||
// Serial.print translate sensor id to sensor name
|
||||
char color[][6] = {"","","","RED","","GREEN","BLUE"};
|
||||
|
||||
// Vars for rgbShow function
|
||||
int redval = 0;
|
||||
int greenval = 0;
|
||||
int blueval = 0;
|
||||
long time=0;
|
||||
int isShow;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initializes the sensor node (Callback function for incoming messages, node id, is repeater)
|
||||
gw.begin(incomingMessage, 31, true);
|
||||
|
||||
// Present sketch (name, version)
|
||||
gw.sendSketchInfo(SN, SV);
|
||||
|
||||
// Register sensors (id, type, description, ack back)
|
||||
gw.present(RED_PIN, S_DIMMER, "present RED light", false);
|
||||
gw.present(GREEN_PIN, S_DIMMER, "present GREEN light", false);
|
||||
gw.present(BLUE_PIN, S_DIMMER, "present BLUE light", false);
|
||||
gw.present(0, S_LIGHT, "present Show button", false);
|
||||
|
||||
// Define pin mode (pin number, type)
|
||||
pinMode(RED_PIN, OUTPUT);
|
||||
pinMode(GREEN_PIN, OUTPUT);
|
||||
pinMode(BLUE_PIN, OUTPUT);
|
||||
|
||||
// Correct saved RGB value for first start
|
||||
gw.saveState(RED_PIN, constrain((int8_t)gw.loadState(RED_PIN), 0, 100));
|
||||
gw.saveState(GREEN_PIN, constrain((int8_t)gw.loadState(GREEN_PIN), 0, 100));
|
||||
gw.saveState(BLUE_PIN, constrain((int8_t)gw.loadState(BLUE_PIN), 0, 100));
|
||||
|
||||
// Get value from eeprom and write to output
|
||||
analogWrite(RED_PIN, 255 * gw.loadState(RED_PIN) / 100);
|
||||
analogWrite(GREEN_PIN, 255 * gw.loadState(GREEN_PIN) / 100);
|
||||
analogWrite(BLUE_PIN, 255 * gw.loadState(BLUE_PIN) / 100);
|
||||
|
||||
// Write some debug info
|
||||
Serial.print("Load from eeprom RED: ");
|
||||
Serial.print(gw.loadState(RED_PIN));
|
||||
Serial.println("%");
|
||||
Serial.print("Load from eeprom GREEN: ");
|
||||
Serial.print(gw.loadState(GREEN_PIN));
|
||||
Serial.println("%");
|
||||
Serial.print("Load from eeprom BLUE: ");
|
||||
Serial.print(gw.loadState(BLUE_PIN));
|
||||
Serial.println("%");
|
||||
|
||||
// Send RGB value to controler (request ack back: true/false)
|
||||
Serial.println("Send eeprom value to controler");
|
||||
gw.send( RedStatus.set(gw.loadState(RED_PIN)), false );
|
||||
gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false );
|
||||
gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false );
|
||||
|
||||
// Correct RGB show state for first start and load it (set to 'On' at first start)
|
||||
gw.saveState(0, constrain((int8_t)gw.loadState(0), 0, 1));
|
||||
isShow=gw.loadState(0);
|
||||
|
||||
// Send RGB show state to controler (request ack back: true/false)
|
||||
gw.send( rgbShowState.set(isShow), false);
|
||||
|
||||
if (isShow==1){Serial.println("RGB show running..."); }
|
||||
Serial.println("Ready to receive messages...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Process incoming messages (like config and light state from controller)
|
||||
gw.process();
|
||||
|
||||
// Run RGB show if is set
|
||||
if (isShow==1)
|
||||
{
|
||||
rgbShow();
|
||||
analogWrite(RED_PIN, redval);
|
||||
analogWrite(GREEN_PIN, greenval);
|
||||
analogWrite(BLUE_PIN, blueval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void incomingMessage(const MyMessage &message)
|
||||
{
|
||||
if (message.isAck())
|
||||
{
|
||||
Serial.println("Got ack from gateway");
|
||||
}
|
||||
if (message.type == V_LIGHT)
|
||||
{
|
||||
// Incoming on/off command sent from controller ("1" or "0")
|
||||
int lightState = message.getString()[0] == '1';
|
||||
|
||||
// if receive RGB Show On commands, start the show
|
||||
if (message.sensor==0 && lightState==1){ rgbShowOn(); }
|
||||
// if receive RGB Show Off commands, stop the show
|
||||
else if (message.sensor==0 && lightState==0){ rgbShowOff(); }
|
||||
|
||||
// if receive RGB switch On command
|
||||
else if (lightState==1)
|
||||
{
|
||||
// Write some debug info
|
||||
Serial.print("Incoming change for ");
|
||||
Serial.print(color[message.sensor]);
|
||||
Serial.println(": On");
|
||||
Serial.print("Load from eeprom: ");
|
||||
|
||||
if ( gw.loadState(message.sensor) == 0)
|
||||
{
|
||||
// Pick up last saved dimmer level from the eeprom
|
||||
analogWrite(message.sensor, 255 * gw.loadState(10*message.sensor) / 100);
|
||||
// Save loaded value to current
|
||||
gw.saveState(message.sensor, gw.loadState(10*message.sensor));
|
||||
Serial.print(gw.loadState(10*message.sensor));
|
||||
Serial.println("%");
|
||||
// Send value to controler
|
||||
Serial.println("Send value to controler");
|
||||
gw.send(Status.setSensor(message.sensor).set(gw.loadState(10*message.sensor)),false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Pick up last saved dimmer level from the eeprom
|
||||
analogWrite(message.sensor, 255 * gw.loadState(message.sensor) / 100);
|
||||
Serial.print(gw.loadState(message.sensor));
|
||||
Serial.println("%");
|
||||
// Send value to controler
|
||||
Serial.println("Send value to controler");
|
||||
gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false);
|
||||
}
|
||||
// Stop the show if it's running
|
||||
if (isShow==1){ rgbShowStop(message.sensor); }
|
||||
}
|
||||
// if recieve switch Off command
|
||||
else if (lightState==0)
|
||||
{
|
||||
// Write output to 0 (Off)
|
||||
analogWrite(message.sensor, 0);
|
||||
// Save old value to eeprom if it'was not zero
|
||||
if ( gw.loadState(message.sensor) != 0 )
|
||||
{
|
||||
gw.saveState(10*message.sensor, constrain((int8_t)gw.loadState(message.sensor), 0, 100));
|
||||
}
|
||||
// Save new value to eeprom
|
||||
gw.saveState(message.sensor, 0);
|
||||
// Write some debug info
|
||||
Serial.print("Incoming change for ");
|
||||
Serial.print(color[message.sensor]);
|
||||
Serial.print(": ");
|
||||
Serial.println("Off");
|
||||
Serial.print("Store old value: ");
|
||||
Serial.print(gw.loadState(10*message.sensor));
|
||||
Serial.println("%");
|
||||
// Send value to controler
|
||||
Serial.println("Send value to controler");
|
||||
gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false);
|
||||
// Stop the show if it's running
|
||||
if (isShow==1){ rgbShowStop(message.sensor); }
|
||||
}
|
||||
}
|
||||
else if (message.type == V_DIMMER)
|
||||
{
|
||||
uint8_t incomingDimmerStatus = message.getByte();
|
||||
// limits range of sensor values to between 0 and 100
|
||||
incomingDimmerStatus = constrain((int8_t)incomingDimmerStatus, 0, 100);
|
||||
// Change Dimmer level
|
||||
analogWrite(message.sensor, 255 * incomingDimmerStatus / 100);
|
||||
//Save value to eeprom
|
||||
gw.saveState(message.sensor, incomingDimmerStatus);
|
||||
// Write some debug info
|
||||
Serial.print("Incoming change for ");
|
||||
Serial.print(color[message.sensor]);
|
||||
Serial.print(": ");
|
||||
Serial.print(incomingDimmerStatus);
|
||||
Serial.println("%");
|
||||
// Send value to controler
|
||||
Serial.println("Send value to controler");
|
||||
gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false);
|
||||
// Stop the show if it's running
|
||||
if (isShow==1){ rgbShowStop(message.sensor); }
|
||||
}
|
||||
}
|
||||
|
||||
void rgbShow()
|
||||
{
|
||||
time = millis();
|
||||
redval = 128+250*cos(2*PI/300000*time);
|
||||
greenval = 128+250*cos(2*PI/300000*time-222);
|
||||
blueval = 128+250*cos(2*PI/300000*time-111);
|
||||
// limits range of sensor values to between 0 and 255
|
||||
redval = constrain(redval, 0, 255);
|
||||
greenval = constrain(greenval, 0, 255);
|
||||
blueval = constrain(blueval, 0, 255);
|
||||
}
|
||||
|
||||
void rgbShowOn()
|
||||
{
|
||||
// define show On
|
||||
isShow=1;
|
||||
// Save state
|
||||
gw.saveState(0, 1);
|
||||
// Write some debug info
|
||||
Serial.println("Show must go on");
|
||||
}
|
||||
|
||||
void rgbShowOff()
|
||||
{
|
||||
// define show Off
|
||||
isShow=0;
|
||||
// Save state
|
||||
gw.saveState(0, 0);
|
||||
// Save RGB value to eeprom
|
||||
gw.saveState(RED_PIN, 100 * redval / 255);
|
||||
gw.saveState(GREEN_PIN, 100 * greenval / 255);
|
||||
gw.saveState(BLUE_PIN, 100 * blueval / 255);
|
||||
// Write some debug info
|
||||
Serial.println("Stop the show");
|
||||
// Send actual RGB value and state to controler and request ack back (true/false)
|
||||
Serial.println("Send eeprom value to controler");
|
||||
gw.send( RedStatus.set(gw.loadState(RED_PIN)), false );
|
||||
gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false );
|
||||
gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false );
|
||||
gw.send( rgbShowState.set(0), false);
|
||||
}
|
||||
|
||||
void rgbShowStop(int sensor)
|
||||
{
|
||||
// define show Off
|
||||
isShow=0;
|
||||
// Save state
|
||||
gw.saveState(0, 0);
|
||||
// Write some debug info
|
||||
Serial.println("Stop the show");
|
||||
// Send actual RGB value and state to controler and request ack back (true/false)
|
||||
Serial.println("Send eeprom value to controler");
|
||||
if (sensor != RED_PIN)
|
||||
{
|
||||
gw.saveState(RED_PIN, 100 * redval / 255);
|
||||
gw.send( RedStatus.set(gw.loadState(RED_PIN)), false );
|
||||
}
|
||||
if (sensor != GREEN_PIN)
|
||||
{
|
||||
gw.saveState(GREEN_PIN, 100 * greenval / 255);
|
||||
gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false );
|
||||
}
|
||||
if (sensor != BLUE_PIN)
|
||||
{
|
||||
gw.saveState(BLUE_PIN, 100 * blueval / 255);
|
||||
gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false );
|
||||
}
|
||||
gw.send( rgbShowState.set(0), false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ volatile int wasTippedBuffer = 0;
|
||||
int rainSensorThreshold = 50; //default rain sensor sensitivity in hundredths. Will be overwritten with msgTrippedVar2.
|
||||
byte state = 0;
|
||||
byte oldState = -1;
|
||||
int lastRainRate = 0;
|
||||
unsigned int lastRainRate = 0;
|
||||
int lastMeasure = 0;
|
||||
boolean gotTime = false;
|
||||
byte lastHour;
|
||||
|
||||
+2
-2
@@ -88,8 +88,8 @@ void loop()
|
||||
|
||||
// If no time has been received yet, request it every 10 second from controller
|
||||
// When time has been received, request update every hour
|
||||
if ((!timeReceived && now-lastRequest > 10*1000)
|
||||
|| (timeReceived && now-lastRequest > 60*1000*60)) {
|
||||
if ((!timeReceived && (now-lastRequest) > (10UL*1000UL))
|
||||
|| (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
|
||||
// Request time from controller.
|
||||
Serial.println("requesting time");
|
||||
gw.requestTime(receiveTime);
|
||||
|
||||
@@ -298,7 +298,6 @@ boolean validateKnock(){
|
||||
// reads the secret knock from EEPROM. (if any.)
|
||||
void readSecretKnock(){
|
||||
byte reading;
|
||||
int i;
|
||||
reading = gw.loadState(1);
|
||||
if (reading == eepromValid){ // only read EEPROM if the signature byte is correct.
|
||||
for (int i=0; i < maximumKnocks ;i++){
|
||||
|
||||
@@ -71,7 +71,7 @@ MySigningAtsha204 signer;
|
||||
#endif
|
||||
MySensor gw(radio, hw, signer);
|
||||
#else
|
||||
#error SecureActuator cannot possibly be secure without signing enabled
|
||||
// WARNING! SecureActuator cannot possibly be secure without signing enabled
|
||||
MySensor gw(radio, hw);
|
||||
#endif
|
||||
|
||||
@@ -85,7 +85,7 @@ void setup()
|
||||
// Fetch lock status
|
||||
for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS;lock++, pin++) {
|
||||
// Register all locks to gw (they will be created as child devices)
|
||||
gw.present(lock, S_LOCK, false);
|
||||
gw.present(lock, S_LOCK, "SecureActuator", false);
|
||||
// Then set lock pins in output mode
|
||||
pinMode(pin, OUTPUT);
|
||||
// Set lock to last known state (using eeprom storage)
|
||||
|
||||
@@ -237,7 +237,6 @@ void write_key(uint8_t* key)
|
||||
|
||||
void dump_configuration()
|
||||
{
|
||||
uint8_t config_word[4];
|
||||
uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
|
||||
uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
|
||||
uint8_t ret_code;
|
||||
@@ -682,6 +681,8 @@ void setup()
|
||||
uint8_t lockConfig = 0;
|
||||
uint8_t lockValue = 0;
|
||||
uint16_t crc;
|
||||
(void)crc;
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println(F("ATSHA204 personalization sketch for MySensors usage."));
|
||||
|
||||
@@ -18,48 +18,168 @@
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* REVISION HISTORY
|
||||
* Version 1.0 - Henrik Ekblad
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Example sketch sending soil moisture alarm to controller
|
||||
* http://www.mysensors.org/build/moisture
|
||||
*/
|
||||
|
||||
*
|
||||
* Arduino soil moisture based on gypsum sensor/resistive sensor to avoid electric catalyse in soil
|
||||
* Required to interface the sensor: 2 * 4.7kOhm + 2 * 1N4148
|
||||
*
|
||||
* Gypsum sensor and calibration:
|
||||
* DIY: See http://vanderleevineyard.com/1/category/vinduino/1.html
|
||||
* Built: Davis / Watermark 200SS
|
||||
* http://www.cooking-hacks.com/watermark-soil-moisture-sensor?_bksrc=item2item&_bkloc=product
|
||||
* http://www.irrometer.com/pdf/supportmaterial/sensors/voltage-WM-chart.pdf
|
||||
* cb (centibar) http://www.irrometer.com/basics.html
|
||||
* 0-10 Saturated Soil. Occurs for a day or two after irrigation
|
||||
* 10-20 Soil is adequately wet (except coarse sands which are drying out at this range)
|
||||
* 30-60 Usual range to irrigate or water (except heavy clay soils).
|
||||
* 60-100 Usual range to irrigate heavy clay soils
|
||||
* 100-200 Soil is becoming dangerously dry for maximum production. Proceed with caution.
|
||||
*
|
||||
* Connection:
|
||||
* D6, D7: alternative powering to avoid sensor degradation
|
||||
* A0, A1: alternative resistance mesuring
|
||||
*
|
||||
* Based on:
|
||||
* "Vinduino" portable soil moisture sensor code V3.00
|
||||
* Date December 31, 2012
|
||||
* Reinier van der Lee and Theodore Kaskalis
|
||||
* www.vanderleevineyard.com
|
||||
* Contributor: epierre
|
||||
**/
|
||||
|
||||
// Copyright (C) 2015, Reinier van der Lee
|
||||
// www.vanderleevineyard.com
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
#include <math.h> // Conversion equation from resistance to %
|
||||
#include <SPI.h>
|
||||
#include <MySensor.h>
|
||||
#include <MySensor.h>
|
||||
|
||||
#define DIGITAL_INPUT_SOIL_SENSOR 3 // Digital input did you attach your soil sensor.
|
||||
#define INTERRUPT DIGITAL_INPUT_SOIL_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
|
||||
#define CHILD_ID 0 // Id of the sensor child
|
||||
// Setting up format for reading 3 soil sensors
|
||||
#define NUM_READS 10 // Number of sensor reads for filtering
|
||||
#define CHILD_ID 0
|
||||
|
||||
MySensor gw;
|
||||
MyMessage msg(CHILD_ID, V_TRIPPED);
|
||||
int lastSoilValue = -1;
|
||||
MySensor gw; // Arduino initialization
|
||||
MyMessage msg(CHILD_ID, V_LEVEL);
|
||||
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
|
||||
|
||||
void setup()
|
||||
{
|
||||
long buffer[NUM_READS];
|
||||
int index;
|
||||
|
||||
typedef struct { // Structure to be used in percentage and resistance values matrix to be filtered (have to be in pairs)
|
||||
int moisture;
|
||||
long resistance;
|
||||
} values;
|
||||
|
||||
const long knownResistor = 4700; // Constant value of known resistor in Ohms
|
||||
|
||||
int supplyVoltage; // Measured supply voltage
|
||||
int sensorVoltage; // Measured sensor voltage
|
||||
|
||||
values valueOf[NUM_READS]; // Calculated moisture percentages and resistances to be sorted and filtered
|
||||
|
||||
int i; // Simple index variable
|
||||
|
||||
void setup() {
|
||||
// initialize serial communications at 9600 bps:
|
||||
Serial.begin(115200);
|
||||
gw.begin();
|
||||
gw.sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0");
|
||||
gw.present(CHILD_ID, S_HUM);
|
||||
// initialize the digital pins as an output.
|
||||
// Pin 6,7 is for sensor 1
|
||||
// initialize the digital pin as an output.
|
||||
// Pin 6 is sense resistor voltage supply 1
|
||||
pinMode(6, OUTPUT);
|
||||
|
||||
// initialize the digital pin as an output.
|
||||
// Pin 7 is sense resistor voltage supply 2
|
||||
pinMode(7, OUTPUT);
|
||||
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
gw.sendSketchInfo("Soil Moisture Sensor", "1.0");
|
||||
// sets the soil sensor digital pin as input
|
||||
pinMode(DIGITAL_INPUT_SOIL_SENSOR, INPUT);
|
||||
// Register all sensors to gw (they will be created as child devices)
|
||||
gw.present(CHILD_ID, S_MOTION);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Read digital soil value
|
||||
int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR); // 1 = Not triggered, 0 = In soil with water
|
||||
if (soilValue != lastSoilValue) {
|
||||
Serial.println(soilValue);
|
||||
gw.send(msg.set(soilValue==0?1:0)); // Send the inverse to gw as tripped should be when no water in soil
|
||||
lastSoilValue = soilValue;
|
||||
|
||||
void loop() {
|
||||
|
||||
measure(6,7,1);
|
||||
Serial.print ("\t");
|
||||
Serial.println (average());
|
||||
long read1 = average();
|
||||
|
||||
measure(7,6,0);
|
||||
Serial.print ("\t");
|
||||
Serial.println (average());
|
||||
long read2= average();
|
||||
|
||||
long sensor1 = (read1 + read2)/2;
|
||||
|
||||
Serial.print ("resistance bias =" );
|
||||
Serial.println (read1-read2);
|
||||
Serial.print ("sensor bias compensated value = ");
|
||||
Serial.println (sensor1);
|
||||
Serial.println ();
|
||||
|
||||
//send back the values
|
||||
gw.send(msg.set((long int)ceil(sensor1)));
|
||||
// delay until next measurement (msec)
|
||||
gw.sleep(SLEEP_TIME);
|
||||
}
|
||||
|
||||
void measure (int phase_b, int phase_a, int analog_input)
|
||||
{
|
||||
// read sensor, filter, and calculate resistance value
|
||||
// Noise filter: median filter
|
||||
|
||||
for (i=0; i<NUM_READS; i++) {
|
||||
|
||||
// Read 1 pair of voltage values
|
||||
digitalWrite(phase_a, HIGH); // set the voltage supply on
|
||||
delayMicroseconds(25);
|
||||
supplyVoltage = analogRead(analog_input); // read the supply voltage
|
||||
delayMicroseconds(25);
|
||||
digitalWrite(phase_a, LOW); // set the voltage supply off
|
||||
delay(1);
|
||||
|
||||
digitalWrite(phase_b, HIGH); // set the voltage supply on
|
||||
delayMicroseconds(25);
|
||||
sensorVoltage = analogRead(analog_input); // read the sensor voltage
|
||||
delayMicroseconds(25);
|
||||
digitalWrite(phase_b, LOW); // set the voltage supply off
|
||||
|
||||
// Calculate resistance
|
||||
// the 0.5 add-term is used to round to the nearest integer
|
||||
// Tip: no need to transform 0-1023 voltage value to 0-5 range, due to following fraction
|
||||
long resistance = (knownResistor * (supplyVoltage - sensorVoltage ) / sensorVoltage) ;
|
||||
|
||||
delay(1);
|
||||
addReading(resistance);
|
||||
Serial.print (resistance);
|
||||
Serial.print ("\t");
|
||||
}
|
||||
// Power down the radio and arduino until digital input changes.
|
||||
gw.sleep(INTERRUPT,CHANGE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Averaging algorithm
|
||||
void addReading(long resistance){
|
||||
buffer[index] = resistance;
|
||||
index++;
|
||||
if (index >= NUM_READS) index = 0;
|
||||
}
|
||||
|
||||
long average(){
|
||||
long sum = 0;
|
||||
for (int i = 0; i < NUM_READS; i++){
|
||||
sum += buffer[i];
|
||||
}
|
||||
return (long)(sum / NUM_READS);
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ void loop()
|
||||
|
||||
// If no time has been received yet, request it every 10 second from controller
|
||||
// When time has been received, request update every hour
|
||||
if ((!timeReceived && now-lastRequest > 10*1000)
|
||||
|| (timeReceived && now-lastRequest > 60*1000*60)) {
|
||||
if ((!timeReceived && (now-lastRequest) > (10UL*1000UL))
|
||||
|| (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
|
||||
// Request time from controller.
|
||||
Serial.println("requesting time");
|
||||
gw.requestTime(receiveTime);
|
||||
|
||||
+11
-10
@@ -77,17 +77,19 @@ int RESEND_DEBOUNCE = 2000; // Number of millisecons interval between sending of
|
||||
|
||||
// Add your buttons here. Max is 5 if you still want time at the top.
|
||||
char *buttons[] = {
|
||||
"Good Morning",
|
||||
"Clean Up!",
|
||||
"All Lights Off",
|
||||
"Music On/Off"
|
||||
(char *)"Good Morning",
|
||||
(char *)"Clean Up!",
|
||||
(char *)"All Lights Off",
|
||||
(char *)"Music On/Off"
|
||||
};
|
||||
|
||||
const int buttonCount = sizeof(buttons)/sizeof(char *);
|
||||
const int padding = 10;
|
||||
const int topBarHeight = 60;
|
||||
|
||||
MySensor gw(17,18);
|
||||
MyTransportNRF24 radio; // NRFRF24L01 radio driver
|
||||
MyHwATMega328 hw; // Select AtMega328 hardware profile
|
||||
MySensor gw(radio, hw);
|
||||
MyMessage on(CHILD_ID, V_SCENE_ON);
|
||||
MyMessage off(CHILD_ID, V_SCENE_OFF);
|
||||
|
||||
@@ -142,13 +144,12 @@ void loop()
|
||||
unsigned long now = millis();
|
||||
|
||||
if (myTouch.dataAvailable()) {
|
||||
unsigned long startPress = millis();
|
||||
int pressedButton = myButtons.checkButtons();
|
||||
|
||||
if (pressedButton>=0) {
|
||||
bool longPress = millis()-now>LONG_PRESS;
|
||||
bool longPress = millis()-now>(unsigned long)LONG_PRESS;
|
||||
|
||||
if (pressedButton != lastPressedButton || now-lastPressedButtonTime > RESEND_DEBOUNCE) {
|
||||
if (pressedButton != lastPressedButton || now-lastPressedButtonTime > (unsigned long)RESEND_DEBOUNCE) {
|
||||
if (longPress) {
|
||||
gw.send(off.set(pressedButton));
|
||||
Serial.print("Long pressed: ");
|
||||
@@ -165,8 +166,8 @@ void loop()
|
||||
|
||||
// If no time has been received yet, request it every 10 second from controller
|
||||
// When time has been received, request update every hour
|
||||
if ((!timeReceived && now-lastRequest > 10*1000)
|
||||
|| (timeReceived && now-lastRequest > 60*1000*60)) {
|
||||
if ((!timeReceived && now-lastRequest > (unsigned long)10*1000)
|
||||
|| (timeReceived && now-lastRequest > (unsigned long)60*1000*60)) {
|
||||
// Request time from controller.
|
||||
Serial.println("requesting time");
|
||||
gw.requestTime(receiveTime);
|
||||
|
||||
@@ -53,7 +53,7 @@ MyMessage uvMsg(CHILD_ID_UV, V_UV);
|
||||
unsigned long lastSend =0;
|
||||
float uvIndex;
|
||||
float lastUV = -1;
|
||||
int uvIndexValue [12] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170};
|
||||
uint16_t uvIndexValue [12] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170};
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -98,7 +98,7 @@ void loop()
|
||||
//Serial.println(uvIndex,2);
|
||||
|
||||
//Send value to gateway if changed, or at least every 5 minutes
|
||||
if ((uvIndex != lastUV)||(currentTime-lastSend >= 5*60*1000)) {
|
||||
if ((uvIndex != lastUV)||(currentTime-lastSend >= 5UL*60UL*1000UL)) {
|
||||
lastSend=currentTime;
|
||||
gw.send(uvMsg.set(uvIndex,2));
|
||||
lastUV = uvIndex;
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* Vibration Sensor
|
||||
*
|
||||
* connect the sensor as follows :
|
||||
*
|
||||
* VCC >>> 5V
|
||||
* S >>> D3
|
||||
* GND >>> GND
|
||||
*
|
||||
* Based on: http://www.dfrobot.com/wiki/index.php/DFRobot_Digital_Vibration_Sensor_V2_SKU:DFR0027
|
||||
* Contributor: epierre
|
||||
**/
|
||||
|
||||
|
||||
#include <MySensor.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#define CHILD_ID_VIBRATION 0
|
||||
#define VIBRATION_SENSOR_DIGITAL_PIN 3
|
||||
#define SensorLED 13
|
||||
|
||||
unsigned long SLEEP_TIME = 10*1000; // Sleep time between reads (in seconds)
|
||||
|
||||
//VARIABLES
|
||||
int val = 0; // variable to store the value coming from the sensor
|
||||
float valVIBRATION =0.0;
|
||||
float lastVIBRATION =0.0;
|
||||
unsigned char state = 0;
|
||||
|
||||
MySensor gw;
|
||||
MyMessage vibrationMsg(CHILD_ID_VIBRATION, V_LEVEL);
|
||||
|
||||
void setup()
|
||||
{
|
||||
gw.begin();
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
gw.sendSketchInfo("VIBRATION Sensor", "1.0");
|
||||
|
||||
// Register all sensors to gateway (they will be created as child devices)
|
||||
gw.present(CHILD_ID_VIBRATION, S_VIBRATION);
|
||||
|
||||
|
||||
pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT);
|
||||
attachInterrupt(1, blink, FALLING);// Trigger the blink function when the falling edge is detected
|
||||
pinMode(SensorLED, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if(state>=40){ // basically below 40 so ignire basic level
|
||||
gw.send(vibrationMsg.set(int(state)));
|
||||
state = 0;
|
||||
digitalWrite(SensorLED,HIGH);
|
||||
} else {
|
||||
state = 0;
|
||||
digitalWrite(SensorLED,LOW);
|
||||
}
|
||||
|
||||
|
||||
// Power down the radio. Note that the radio will get powered back up
|
||||
// on the next write() call.
|
||||
delay(1000); //delay to allow serial to fully print before sleep
|
||||
|
||||
gw.sleep(SLEEP_TIME); //sleep for: sleepTime
|
||||
}
|
||||
|
||||
void blink()//Interrupts function
|
||||
{
|
||||
state++;
|
||||
}
|
||||
@@ -463,7 +463,8 @@ uint8_t ATSHA204Class::sha204m_execute(uint8_t op_code, uint8_t param1, uint16_t
|
||||
uint8_t poll_delay, poll_timeout, response_size;
|
||||
uint8_t *p_buffer;
|
||||
uint8_t len;
|
||||
|
||||
(void)tx_size;
|
||||
|
||||
// Supply delays and response size.
|
||||
switch (op_code)
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ void RF24::csn(bool mode)
|
||||
delayMicroseconds(11); // allow csn to settle
|
||||
}
|
||||
}
|
||||
#else if !defined (__arm__) || defined (CORE_TEENSY)
|
||||
#elif !defined (__arm__) || defined (CORE_TEENSY)
|
||||
digitalWrite(csn_pin,mode);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -55,9 +55,9 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||
/* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_50000}, //default:5khz, (FDEV + BitRate/2 <= 500Khz)
|
||||
/* 0x06 */ { REG_FDEVLSB, RF_FDEVLSB_50000},
|
||||
|
||||
/* 0x07 */ { REG_FRFMSB, (freqBand==RF69_315MHZ ? RF_FRFMSB_315 : (freqBand==RF69_433MHZ ? RF_FRFMSB_433 : (freqBand==RF69_868MHZ ? RF_FRFMSB_868 : RF_FRFMSB_915))) },
|
||||
/* 0x08 */ { REG_FRFMID, (freqBand==RF69_315MHZ ? RF_FRFMID_315 : (freqBand==RF69_433MHZ ? RF_FRFMID_433 : (freqBand==RF69_868MHZ ? RF_FRFMID_868 : RF_FRFMID_915))) },
|
||||
/* 0x09 */ { REG_FRFLSB, (freqBand==RF69_315MHZ ? RF_FRFLSB_315 : (freqBand==RF69_433MHZ ? RF_FRFLSB_433 : (freqBand==RF69_868MHZ ? RF_FRFLSB_868 : RF_FRFLSB_915))) },
|
||||
/* 0x07 */ { REG_FRFMSB, (freqBand==RF69_315MHZ ? (const byte)RF_FRFMSB_315 : (freqBand==RF69_433MHZ ? (const byte)RF_FRFMSB_433 : (freqBand==RF69_868MHZ ? (const byte)RF_FRFMSB_868 : (const byte)RF_FRFMSB_915))) },
|
||||
/* 0x08 */ { REG_FRFMID, (freqBand==RF69_315MHZ ? (const byte)RF_FRFMID_315 : (freqBand==RF69_433MHZ ? (const byte)RF_FRFMID_433 : (freqBand==RF69_868MHZ ? (const byte)RF_FRFMID_868 : (const byte)RF_FRFMID_915))) },
|
||||
/* 0x09 */ { REG_FRFLSB, (freqBand==RF69_315MHZ ? (const byte)RF_FRFLSB_315 : (freqBand==RF69_433MHZ ? (const byte)RF_FRFLSB_433 : (freqBand==RF69_868MHZ ? (const byte)RF_FRFLSB_868 : (const byte)RF_FRFLSB_915))) },
|
||||
|
||||
// looks like PA1 and PA2 are not implemented on RFM69W, hence the max output power is 13dBm
|
||||
// +17dBm and +20dBm are possible on RFM69HW
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
|
||||
#define RF69_IRQ_PIN 2
|
||||
#define RF69_IRQ_NUM 0
|
||||
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
|
||||
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega2560__)
|
||||
#define RF69_IRQ_PIN 2
|
||||
#define RF69_IRQ_NUM 2
|
||||
#elif defined(__AVR_ATmega32U4__)
|
||||
|
||||
Reference in New Issue
Block a user