MyMessage.h: Added some comments and presentation types from the web site, fixed a small typo
MockMySensors sketch: Fixed some small issues to conform to the 1.5 API (S_HEATER still needs to done)
This commit is contained in:
@@ -1,47 +1,29 @@
|
||||
/*
|
||||
* MockMySensors
|
||||
* FakeMySensors
|
||||
*
|
||||
* 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 <MyMessage.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define RADIO_ERROR_LED_PIN 4 // Error led pin
|
||||
#define RADIO_RX_LED_PIN 6 // Receive led pin
|
||||
#define RADIO_TX_LED_PIN 5 // the PCB, on board LED
|
||||
// SPI Pins
|
||||
#define CE_PIN 9
|
||||
#define CS_PIN 10
|
||||
|
||||
// Wait times
|
||||
#define LONG_WAIT 500
|
||||
#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
|
||||
|
||||
// Some of these ID's have not been updated for v1.5. Uncommenting too many of them
|
||||
// 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_DOOR 1
|
||||
//#define ID_S_MOTION 2
|
||||
//#define ID_S_SMOKE 3
|
||||
//#define ID_S_LIGHT 4
|
||||
@@ -51,11 +33,11 @@
|
||||
//#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_HEATER 15 <<-- not correctly implemented (1.5 API)
|
||||
//#define ID_S_DISTANCE 16
|
||||
//#define ID_S_LIGHT_LEVEL 17
|
||||
//#define ID_S_LOCK 18
|
||||
@@ -67,29 +49,12 @@
|
||||
//#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
|
||||
MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_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
|
||||
MySensor gw;
|
||||
|
||||
//Instanciate Messages objects
|
||||
|
||||
@@ -161,8 +126,10 @@ MySensor gw(transport, hw /*, signer*/);
|
||||
#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
|
||||
@@ -188,11 +155,11 @@ MySensor gw(transport, hw /*, signer*/);
|
||||
#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
|
||||
@@ -268,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
|
||||
@@ -408,7 +375,7 @@ void loop()
|
||||
gw.wait(LONG_WAIT);
|
||||
|
||||
//Read Sensors
|
||||
#ifdef S_ID_DOOR
|
||||
#ifdef ID_S_DOOR
|
||||
door();
|
||||
#endif
|
||||
|
||||
@@ -519,9 +486,7 @@ void receiveTime(unsigned long controllerTime) {
|
||||
|
||||
}
|
||||
|
||||
//void door(){}
|
||||
|
||||
#ifdef S_ID_DOOR
|
||||
#ifdef ID_S_DOOR
|
||||
void door(){
|
||||
|
||||
Serial.print("Door is: " );
|
||||
@@ -650,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: " );
|
||||
@@ -753,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: " );
|
||||
|
||||
@@ -781,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
|
||||
|
||||
Reference in New Issue
Block a user