Merge pull request #170 from gizmocuz/master

MyMessage.h comments fixed / MockMySensors changes to get it working in 1.5
This commit is contained in:
Henrik Ekblad
2015-08-15 09:23:46 +02:00
3 changed files with 75 additions and 103 deletions
+42 -41
View File
@@ -58,7 +58,7 @@ typedef enum {
S_UV, // Uv sensor, V_UV S_UV, // Uv sensor, V_UV
S_WEIGHT, // Personal scale sensor, V_WEIGHT, V_IMPEDANCE S_WEIGHT, // Personal scale sensor, V_WEIGHT, V_IMPEDANCE
S_POWER, // Power meter, V_WATT, V_KWH 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_DISTANCE, // Distance sensor, V_DISTANCE
S_LIGHT_LEVEL, // Light level sensor, V_LIGHT_LEVEL (uncalibrated in percentage), V_LEVEL (light level in lux) 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 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_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_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_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_MULTIMETER, // Multimeter device, V_VOLTAGE, V_CURRENT, V_IMPEDANCE
S_SPRINKLER, // Sprinkler, V_STATUS (turn on/off), V_TRIPPED (if fire detecting device) S_SPRINKLER, // Sprinkler, V_STATUS (turn on/off), V_TRIPPED (if fire detecting device)
S_WATER_LEAK, // Water leak sensor, V_TRIPPED, V_ARMED 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) // Type of sensor data (for set/req/ack messages)
typedef enum { typedef enum {
V_TEMP, // S_TEMP V_TEMP, // S_TEMP. Temperature S_TEMP, S_HEATER, S_HVAC
V_HUM, // S_HUM V_HUM, // S_HUM. Humidity
V_STATUS, // S_LIGHT, S_DIMMER, S_SPRINKLER, S_HVAC, S_HEATER. Used for setting binary (on/off) status. 1=on, 0=off 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_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_DIMMER=3, // S_DIMMER. Same as V_PERCENTAGE.
V_PRESSURE, // S_BARO V_PRESSURE, // S_BARO. Atmospheric Pressure
V_FORECAST, // S_BARO V_FORECAST, // S_BARO. Whether forecast. string of "stable", "sunny", "cloudy", "unstable", "thunderstorm" or "unknown"
V_RAIN, // S_RAIN V_RAIN, // S_RAIN. Amount of rain
V_RAINRATE, // S_RAIN V_RAINRATE, // S_RAIN. Rate of rain
V_WIND, // S_WIND V_WIND, // S_WIND. Wind speed
V_GUST, // S_WIND V_GUST, // S_WIND. Gust
V_DIRECTION, // S_WIND V_DIRECTION, // S_WIND. Wind direction 0-360 (degrees)
V_UV, // S_UV V_UV, // S_UV. UV light level
V_WEIGHT, // S_WEIGHT V_WEIGHT, // S_WEIGHT. Weight(for scales etc)
V_DISTANCE, // S_DISTANCE V_DISTANCE, // S_DISTANCE. Distance
V_IMPEDANCE, // S_MULTIMETER, S_WEIGHT V_IMPEDANCE, // S_MULTIMETER, S_WEIGHT. Impedance value
V_ARMED, // S_DOOR, S_MOTION, S_SMOKE, S_SPRINKLER 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 (for sprinklers with fire detection) 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 V_WATT, // S_POWER, S_LIGHT, S_DIMMER, S_RGB, S_RGBW. Watt value for power meters
V_KWH, // S_POWER V_KWH, // S_POWER. Accumulated number of KWH for a power meter
V_SCENE_ON, // S_SCENE_CONTROLLER V_SCENE_ON, // S_SCENE_CONTROLLER. Turn on a scene
V_SCENE_OFF, // S_SCENE_CONTROLLER V_SCENE_OFF, // S_SCENE_CONTROLLER. Turn of a scene
V_HEATER, // Deprecated. Use V_HVAC_FLOW_STATE instead. 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_FLOW_STATE=21, // S_HEATER, S_HVAC. HVAC flow state ("Off", "HeatOn", "CoolOn", or "AutoChangeOver")
V_HVAC_SPEED, // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto") V_HVAC_SPEED, // S_HVAC, S_HEATER. 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_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_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5,
V_UP, // S_COVER V_UP, // S_COVER. Window covering. Up
V_DOWN, // S_COVER V_DOWN, // S_COVER. Window covering. Down
V_STOP, // S_COVER V_STOP, // S_COVER. Window covering. Stop
V_IR_SEND, // S_IR V_IR_SEND, // S_IR. Send out an IR-command
V_IR_RECEIVE, // S_IR V_IR_RECEIVE, // S_IR. This message contains a received IR-command
V_FLOW, // S_WATER V_FLOW, // S_WATER. Flow of water (in meter)
V_VOLUME, // S_WATER V_VOLUME, // S_WATER. Water volume
V_LOCK_STATUS, // S_LOCK 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_LEVEL, // S_DUST, S_AIR_QUALITY, S_SOUND (dB), S_VIBRATION (hz), S_LIGHT_LEVEL (lux)
V_VOLTAGE, // S_MULTIMETER V_VOLTAGE, // S_MULTIMETER
V_CURRENT, // S_MULTIMETER V_CURRENT, // S_MULTIMETER
@@ -128,15 +128,16 @@ typedef enum {
// Sent as ASCII hex: RRGGBB (RR=red, GG=green, BB=blue component) // Sent as ASCII hex: RRGGBB (RR=red, GG=green, BB=blue component)
V_RGBW, // S_RGBW_LIGHT V_RGBW, // S_RGBW_LIGHT
// Used for sending color information to multi color LED lighting. // 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 V_ID, // S_TEMP
// Used for sending in sensors hardware ids (i.e. OneWire DS1820b). // Used for sending in sensors hardware ids (i.e. OneWire DS1820b).
V_UNIT_PREFIX, // Allows sensors to send in a string representing the V_UNIT_PREFIX, // S_DUST, S_AIR_QUALITY
// unit prefix to be displayed in GUI, not parsed by controller! E.g. cm, m, km, inch. // Allows sensors to send in a string representing the
// Can be used for S_DISTANCE or gas concentration (S_DUST, S_AIR_QUALITY) // unit prefix to be displayed in GUI, not parsed by controller! E.g. cm, m, km, inch.
V_HVAC_SETPOINT_COOL, // HVAC cool setpoint (Integer between 0-100). S_HVAC // Can be used for S_DISTANCE or gas concentration
V_HVAC_SETPOINT_HEAT, // HVAC/Heater setpoint (Integer between 0-100). S_HEATER, S_HVAC V_HVAC_SETPOINT_COOL, // S_HVAC. HVAC cool setpoint (Integer between 0-100)
V_HVAC_FLOW_MODE, // Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn"). S_HVAC 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; } mysensor_data;
@@ -1,47 +1,29 @@
/* /*
* MockMySensors * FakeMySensors
* *
* This skecth is intended to crate fake sensors which register and respond to the controller * This skecth is intended to crate fake sensors which register and respond to the controller
* *
* Barduino 2015 * Barduino, GizMoCuz 2015
*/ */
#include <MySigningNone.h>
#include <MyTransportRFM69.h>
#include <MyTransportNRF24.h>
#include <MyHwATMega328.h>
#include <MySigningAtsha204Soft.h>
#include <MySigningAtsha204.h>
#include <SPI.h>
#include <MySensor.h> #include <MySensor.h>
#include <MyMessage.h> #include <SPI.h>
#define RADIO_ERROR_LED_PIN 4 // Error led pin // SPI Pins
#define RADIO_RX_LED_PIN 6 // Receive led pin #define CE_PIN 9
#define RADIO_TX_LED_PIN 5 // the PCB, on board LED #define CS_PIN 10
// Wait times // Wait times
#define LONG_WAIT 500 #define LONG_WAIT 500
#define SHORT_WAIT 50 #define SHORT_WAIT 50
#define SKETCH_NAME "FakeMySensors " #define SKETCH_NAME "FakeMySensors "
#define SKETCH_VERSION "v0.2" #define SKETCH_VERSION "v0.3"
// 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 ID_S_ARDUINO_NODE //auto defined in initialization ////#define ID_S_ARDUINO_NODE //auto defined in initialization
////#define ID_S_ARDUINO_REPEATER_NODE //auto defined in initialization ////#define ID_S_ARDUINO_REPEATER_NODE //auto defined in initialization
// Some of these ID's have not been updated for v1.5. Uncommenting too many of them //#define ID_S_DOOR 1
// will make the sketch too large for a pro mini's memory so it's probably best to try
// one at a time.
#define ID_S_DOOR 1
//#define ID_S_MOTION 2 //#define ID_S_MOTION 2
//#define ID_S_SMOKE 3 //#define ID_S_SMOKE 3
//#define ID_S_LIGHT 4 //#define ID_S_LIGHT 4
@@ -51,11 +33,11 @@
//#define ID_S_HUM 8 //#define ID_S_HUM 8
//#define ID_S_BARO 9 //#define ID_S_BARO 9
//#define ID_S_WIND 10 //#define ID_S_WIND 10
//#define ID_S_RAIN 11 //#define ID_S_RAIN 11
//#define ID_S_UV 12 //#define ID_S_UV 12
//#define ID_S_WEIGHT 13 //#define ID_S_WEIGHT 13
//#define ID_S_POWER 14 //#define ID_S_POWER 14
//#define ID_S_HEATER 15 //#define ID_S_HEATER 15 <<-- not correctly implemented (1.5 API)
//#define ID_S_DISTANCE 16 //#define ID_S_DISTANCE 16
//#define ID_S_LIGHT_LEVEL 17 //#define ID_S_LIGHT_LEVEL 17
//#define ID_S_LOCK 18 //#define ID_S_LOCK 18
@@ -67,29 +49,12 @@
//#define ID_S_CUSTOM 24 //#define ID_S_CUSTOM 24
// Global Vars // 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; boolean metric = true;
long randNumber; long randNumber;
// Instanciate MySersors Gateway // Instanciate MySersors Gateway
MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW); MySensor gw;
//MyTransportRFM69 transport;
// Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
//MySigningNone signer;
//MySigningAtsha204Soft signer;
//MySigningAtsha204 signer;
// Hardware profile
MyHwATMega328 hw;
// Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
// To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
#ifdef WITH_LEDS_BLINKING
MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
#else
MySensor gw(transport, hw /*, signer*/);
#endif
//Instanciate Messages objects //Instanciate Messages objects
@@ -161,8 +126,10 @@ MySensor gw(transport, hw /*, signer*/);
#endif #endif
#ifdef ID_S_HEATER #ifdef ID_S_HEATER
MyMessage msg_S_HEATER_M(ID_S_HEATER,V_HEATER); float current_set_point=21.5;
MyMessage msg_S_HEATER_S(ID_S_HEATER,V_HEATER_SW); 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 #endif
#ifdef ID_S_DISTANCE #ifdef ID_S_DISTANCE
@@ -188,11 +155,11 @@ MySensor gw(transport, hw /*, signer*/);
#endif #endif
#ifdef ID_S_AIR_QUALITY #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 #endif
#ifdef ID_S_DUST #ifdef ID_S_DUST
MyMessage msg_S_DUST(ID_S_DUST,V_DUST_LEVEL); MyMessage msg_S_DUST(ID_S_DUST,V_LEVEL);
#endif #endif
#ifdef ID_S_SCENE_CONTROLLER #ifdef ID_S_SCENE_CONTROLLER
@@ -268,13 +235,13 @@ void setup()
#endif #endif
#ifdef ID_S_COVER #ifdef ID_S_COVER
Serial.println(" S_COVER"; Serial.println(" S_COVER");
gw.present(ID_S_COVER,S_COVER); gw.present(ID_S_COVER,S_COVER);
gw.wait(SHORT_WAIT); gw.wait(SHORT_WAIT);
#endif #endif
#ifdef ID_S_TEMP #ifdef ID_S_TEMP
Serial.println(" S_TMEP"); Serial.println(" S_TEMP");
gw.present(ID_S_TEMP,S_TEMP); gw.present(ID_S_TEMP,S_TEMP);
gw.wait(SHORT_WAIT); gw.wait(SHORT_WAIT);
#endif #endif
@@ -408,7 +375,7 @@ void loop()
gw.wait(LONG_WAIT); gw.wait(LONG_WAIT);
//Read Sensors //Read Sensors
#ifdef S_ID_DOOR #ifdef ID_S_DOOR
door(); door();
#endif #endif
@@ -519,9 +486,7 @@ void receiveTime(unsigned long controllerTime) {
} }
//void door(){} #ifdef ID_S_DOOR
#ifdef S_ID_DOOR
void door(){ void door(){
Serial.print("Door is: " ); Serial.print("Door is: " );
@@ -650,7 +615,7 @@ void hum(){
void baro(){ void baro(){
const char *weather[] = {"stable","sunny","cloudy","unstable","thunderstorm","unknown"}; 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); int forecast = map(randNumber,1,100,0,5);
Serial.print("Atmosferic Pressure is: " ); Serial.print("Atmosferic Pressure is: " );
@@ -753,8 +718,9 @@ void power(){
#ifdef ID_S_HEATER #ifdef ID_S_HEATER
void heater(){ void heater(){
int heater_mode = gw.loadState(ID_S_HEATER); int heater_set_point = gw.loadState(ID_S_HEATER);
bool heater_switch = gw.loadState(ID_S_HEATER+1); int heater_flow_state = gw.loadState(ID_S_HEATER+1);
int heater_temp = gw.loadState(ID_S_HEATER+2);
Serial.print("Heater mode is: " ); Serial.print("Heater mode is: " );
@@ -781,6 +747,11 @@ void heater(){
Serial.println(heater_switch?"On":"Off"); Serial.println(heater_switch?"On":"Off");
gw.send(msg_S_HEATER_S.set(heater_switch)); 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 #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 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 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 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 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