Default channel should be 76 (not the presumed 70)

This commit is contained in:
Henrik Ekblad
2014-03-04 19:11:54 +01:00
parent a5422954e6
commit 0506187e27
4 changed files with 429 additions and 430 deletions
+85 -85
View File
@@ -1,85 +1,85 @@
/* /*
The Sensor Net Arduino library adds a new layer on top of the RF24 library. The Sensor Net Arduino library adds a new layer on top of the RF24 library.
It handles radio network routing, relaying and ids. It handles radio network routing, relaying and ids.
Created by Henrik Ekblad <henrik.ekblad@gmail.com> Created by Henrik Ekblad <henrik.ekblad@gmail.com>
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation. version 2 as published by the Free Software Foundation.
*/ */
#ifndef Gateway_h #ifndef Gateway_h
#define Gateway_h #define Gateway_h
#include "Relay.h" #include "Relay.h"
#define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from vera #define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from vera
#define MAX_SEND_LENGTH 120 // Max buffersize needed for messages coming from vera #define MAX_SEND_LENGTH 120 // Max buffersize needed for messages coming from vera
class Gateway : public Relay class Gateway : public Relay
{ {
public: public:
/** /**
* Constructor * Constructor
* *
* Creates a new instance of Gateway class. * Creates a new instance of Gateway class.
* If you don't use status leds and/or inclusion mode button on your arduino gateway * If you don't use status leds and/or inclusion mode button on your arduino gateway
* you can disable this functionality by calling the 2 argument constructor. * you can disable this functionality by calling the 2 argument constructor.
* *
* @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9) * @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9)
* @param _cspin The pin attached to RF24 Chip Select (defualt 10) * @param _cspin The pin attached to RF24 Chip Select (defualt 10)
* @param _inclusion_time Time of inclusion mode (in minutes, default 1) * @param _inclusion_time Time of inclusion mode (in minutes, default 1)
* @param _inclusion_pin Digital pin that triggers inclusion mode * @param _inclusion_pin Digital pin that triggers inclusion mode
* @param _rx Digital pin for receive led * @param _rx Digital pin for receive led
* @param _tx Digital pin for transfer led * @param _tx Digital pin for transfer led
* @param _er Digital pin for error led * @param _er Digital pin for error led
* *
*/ */
Gateway(uint8_t _cepin=9, uint8_t _cspin=10, uint8_t _inclusion_time = 1); Gateway(uint8_t _cepin=9, uint8_t _cspin=10, uint8_t _inclusion_time = 1);
Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time, uint8_t _inclusion_pin, uint8_t _rx, uint8_t _tx, uint8_t _er); Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time, uint8_t _inclusion_pin, uint8_t _rx, uint8_t _tx, uint8_t _er);
/* Use this and pass a function that should be called when you want to process commands that arrive from radio network */ /* Use this and pass a function that should be called when you want to process commands that arrive from radio network */
void begin(rf24_pa_dbm_e paLevel=RF24_PA_MAX, uint8_t channel=70, void (*dataCallback)(char *)=NULL); void begin(rf24_pa_dbm_e paLevel=RF24_PA_MAX, uint8_t channel=76, void (*dataCallback)(char *)=NULL);
void processRadioMessage(); void processRadioMessage();
void parseAndSend(char *inputString); void parseAndSend(char *inputString);
boolean isLedMode(); boolean isLedMode();
void ledTimersInterrupt(); void ledTimersInterrupt();
void startInclusionInterrupt(); void startInclusionInterrupt();
private: private:
char serialBuffer[MAX_SEND_LENGTH]; // Buffer for building string when sending data to vera char serialBuffer[MAX_SEND_LENGTH]; // Buffer for building string when sending data to vera
unsigned long inclusionStartTime; unsigned long inclusionStartTime;
boolean inclusionMode; // Keeps track on inclusion mode boolean inclusionMode; // Keeps track on inclusion mode
boolean buttonTriggeredInclusion; boolean buttonTriggeredInclusion;
volatile uint8_t countRx; volatile uint8_t countRx;
volatile uint8_t countTx; volatile uint8_t countTx;
volatile uint8_t countErr; volatile uint8_t countErr;
boolean ledMode; boolean ledMode;
boolean useWriteCallback; boolean useWriteCallback;
void (*dataCallback)(char *); void (*dataCallback)(char *);
uint8_t pinInclusion; uint8_t pinInclusion;
uint8_t inclusionTime; uint8_t inclusionTime;
uint8_t pinRx; uint8_t pinRx;
uint8_t pinTx; uint8_t pinTx;
uint8_t pinEr; uint8_t pinEr;
void serial(const char *fmt, ... ); void serial(const char *fmt, ... );
uint8_t validate(uint8_t length); uint8_t validate(uint8_t length);
void serial(message_s msg); void serial(message_s msg);
void interruptStartInclusion(); void interruptStartInclusion();
void checkButtonTriggeredInclusion(); void checkButtonTriggeredInclusion();
void setInclusionMode(boolean newMode); void setInclusionMode(boolean newMode);
void checkInclusionFinished(); void checkInclusionFinished();
void ledTimers(); void ledTimers();
void rxBlink(uint8_t cnt); void rxBlink(uint8_t cnt);
void txBlink(uint8_t cnt); void txBlink(uint8_t cnt);
void errBlink(uint8_t cnt); void errBlink(uint8_t cnt);
}; };
#endif #endif
+62 -62
View File
@@ -1,62 +1,62 @@
/* /*
The Sensor Net Arduino library adds a new layer on top of the RF24 library. The Sensor Net Arduino library adds a new layer on top of the RF24 library.
It handles radio network routing, relaying and ids. It handles radio network routing, relaying and ids.
Created by Henrik Ekblad <henrik.ekblad@gmail.com> Created by Henrik Ekblad <henrik.ekblad@gmail.com>
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation. version 2 as published by the Free Software Foundation.
*/ */
#ifndef Relay_h #ifndef Relay_h
#define Relay_h #define Relay_h
#include "Sensor.h" #include "Sensor.h"
#ifdef DEBUG #ifdef DEBUG
#define debug(x,...) debugPrint(x, ##__VA_ARGS__) #define debug(x,...) debugPrint(x, ##__VA_ARGS__)
#else #else
#define debug(x,...) #define debug(x,...)
#endif #endif
#define EEPROM_ROUTES_ADDRESS ((uint8_t)3) // Where to start storing routing information in EEPROM. Will allocate 256 bytes. #define EEPROM_ROUTES_ADDRESS ((uint8_t)3) // Where to start storing routing information in EEPROM. Will allocate 256 bytes.
class Relay : public Sensor class Relay : public Sensor
{ {
public: public:
/** /**
* Constructor * Constructor
* *
* Creates a new instance of Relay class. * Creates a new instance of Relay class.
* *
* @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9) * @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9)
* @param _cspin The pin attached to RF24 Chip Select (defualt 10) * @param _cspin The pin attached to RF24 Chip Select (defualt 10)
*/ */
Relay(uint8_t _cepin = 9, uint8_t _cspin = 10); Relay(uint8_t _cepin = 9, uint8_t _cspin = 10);
void begin(uint8_t radioId=AUTO, rf24_pa_dbm_e paLevel=RF24_PA_MAX, uint8_t channel=70); void begin(uint8_t radioId=AUTO, rf24_pa_dbm_e paLevel=RF24_PA_MAX, uint8_t channel=76);
boolean messageAvailable(); boolean messageAvailable();
boolean send(message_s message, int length); boolean send(message_s message, int length);
boolean sendData(uint8_t from, uint8_t to, uint8_t childId, uint8_t messageType, uint8_t type, const char *data, uint8_t length, boolean binary); boolean sendData(uint8_t from, uint8_t to, uint8_t childId, uint8_t messageType, uint8_t type, const char *data, uint8_t length, boolean binary);
protected: protected:
void sendChildren(); void sendChildren();
private: private:
uint8_t childNodeTable[256]; // Buffer to store child node information. Store this in EEPROM uint8_t childNodeTable[256]; // Buffer to store child node information. Store this in EEPROM
uint8_t getChildRoute(uint8_t childId); uint8_t getChildRoute(uint8_t childId);
void addChildRoute(uint8_t childId, uint8_t route); void addChildRoute(uint8_t childId, uint8_t route);
void removeChildRoute(uint8_t childId); void removeChildRoute(uint8_t childId);
void clearChildRoutes(); void clearChildRoutes();
void relayMessage(uint8_t length, uint8_t pipe); void relayMessage(uint8_t length, uint8_t pipe);
}; };
#endif #endif
+281 -281
View File
@@ -1,281 +1,281 @@
/* /*
The Sensor Net Arduino library adds a new layer on top of the RF24 library. The Sensor Net Arduino library adds a new layer on top of the RF24 library.
It handles radio network routing, relaying and ids. It handles radio network routing, relaying and ids.
Created by Henrik Ekblad <henrik.ekblad@gmail.com> Created by Henrik Ekblad <henrik.ekblad@gmail.com>
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation. version 2 as published by the Free Software Foundation.
*/ */
#ifndef Sensor_h #ifndef Sensor_h
#define Sensor_h #define Sensor_h
#include <nRF24L01.h> #include <nRF24L01.h>
#include <RF24.h> #include <RF24.h>
#include <RF24_config.h> #include <RF24_config.h>
#include <Arduino.h> #include <Arduino.h>
#include <stddef.h> #include <stddef.h>
#include <SPI.h> #include <SPI.h>
#include <EEPROM.h> #include <EEPROM.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <stdarg.h> #include <stdarg.h>
//#define DEBUG #define DEBUG
#ifdef DEBUG #ifdef DEBUG
#define debug(x,...) debugPrint(x, ##__VA_ARGS__) #define debug(x,...) debugPrint(x, ##__VA_ARGS__)
#else #else
#define debug(x,...) #define debug(x,...)
#endif #endif
#define LIBRARY_VERSION "1.2+" #define LIBRARY_VERSION "1.2+"
#define PROTOCOL_VERSION 1 #define PROTOCOL_VERSION 1
#define BAUD_RATE 115200 #define BAUD_RATE 115200
#define AUTO 0xFF // 0-254. Id 255 is reserved for auto initialization of radioId. #define AUTO 0xFF // 0-254. Id 255 is reserved for auto initialization of radioId.
#define NODE_CHILD_ID 0xFF // Node child id is always created for when a new sensor is detected #define NODE_CHILD_ID 0xFF // Node child id is always created for when a new sensor is detected
#define EEPROM_RADIO_ID_ADDRESS 0 // Where to store radio id in EEPROM #define EEPROM_RADIO_ID_ADDRESS 0 // Where to store radio id in EEPROM
#define EEPROM_RELAY_ID_ADDRESS 1 // Where to store relay id in EEPROM #define EEPROM_RELAY_ID_ADDRESS 1 // Where to store relay id in EEPROM
#define EEPROM_DISTANCE_ADDRESS 2 // Where to store distance to gateway in EEPROM #define EEPROM_DISTANCE_ADDRESS 2 // Where to store distance to gateway in EEPROM
// This is the radioId for sensor net gateway receiver sketch (where all sensors should send their data). // This is the radioId for sensor net gateway receiver sketch (where all sensors should send their data).
// This is also act as base value for sensor radioId // This is also act as base value for sensor radioId
#define BASE_RADIO_ID ((uint64_t)0xABCDABC000LL) #define BASE_RADIO_ID ((uint64_t)0xABCDABC000LL)
#define GATEWAY_ADDRESS ((uint8_t)0) #define GATEWAY_ADDRESS ((uint8_t)0)
#define BROADCAST_ADDRESS ((uint8_t)0xFF) #define BROADCAST_ADDRESS ((uint8_t)0xFF)
#define TO_ADDR(x) (BASE_RADIO_ID + x) #define TO_ADDR(x) (BASE_RADIO_ID + x)
#define WRITE_PIPE ((uint8_t)0) #define WRITE_PIPE ((uint8_t)0)
#define CURRENT_NODE_PIPE ((uint8_t)1) #define CURRENT_NODE_PIPE ((uint8_t)1)
#define BROADCAST_PIPE ((uint8_t)2) #define BROADCAST_PIPE ((uint8_t)2)
#define WRITE_RETRY 5 #define WRITE_RETRY 5
#define FIND_RELAY_RETRIES 20 #define FIND_RELAY_RETRIES 20
#define MAX_MESSAGE_LENGTH 32 #define MAX_MESSAGE_LENGTH 32
// Message types // Message types
typedef enum { typedef enum {
M_PRESENTATION = 0, M_PRESENTATION = 0,
M_SET_VARIABLE = 1, M_SET_VARIABLE = 1,
M_REQ_VARIABLE = 2, M_REQ_VARIABLE = 2,
M_ACK_VARIABLE = 3, M_ACK_VARIABLE = 3,
M_INTERNAL = 4 M_INTERNAL = 4
} messageType; } messageType;
// Sensor variables that can be used in sketches // Sensor variables that can be used in sketches
typedef enum { typedef enum {
V_TEMP,V_HUM, V_LIGHT, V_DIMMER, V_PRESSURE, V_FORECAST, V_RAIN, V_TEMP,V_HUM, V_LIGHT, V_DIMMER, V_PRESSURE, V_FORECAST, V_RAIN,
V_RAINRATE, V_WIND, V_GUST, V_DIRECTION, V_UV, V_WEIGHT, V_DISTANCE, V_RAINRATE, V_WIND, V_GUST, V_DIRECTION, V_UV, V_WEIGHT, V_DISTANCE,
V_IMPEDANCE, V_ARMED, V_TRIPPED, V_WATT, V_KWH, V_SCENE_ON, V_SCENE_OFF, V_IMPEDANCE, V_ARMED, V_TRIPPED, V_WATT, V_KWH, V_SCENE_ON, V_SCENE_OFF,
V_HEATER, V_HEATER_SW, V_LIGHT_LEVEL, V_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5, V_HEATER, V_HEATER_SW, V_LIGHT_LEVEL, V_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5,
V_UP, V_DOWN, V_STOP, V_IR_SEND, V_IR_RECEIVE, V_FLOW, V_VOLUME, V_LOCK_STATUS V_UP, V_DOWN, V_STOP, V_IR_SEND, V_IR_RECEIVE, V_FLOW, V_VOLUME, V_LOCK_STATUS
} variableType; } variableType;
// Internal messages // Internal messages
typedef enum { typedef enum {
I_BATTERY_LEVEL, I_BATTERY_DATE, I_LAST_TRIP, I_TIME, I_VERSION, I_REQUEST_ID, I_BATTERY_LEVEL, I_BATTERY_DATE, I_LAST_TRIP, I_TIME, I_VERSION, I_REQUEST_ID,
I_INCLUSION_MODE, I_RELAY_NODE, I_LAST_UPDATE, I_PING, I_PING_ACK, I_INCLUSION_MODE, I_RELAY_NODE, I_LAST_UPDATE, I_PING, I_PING_ACK,
I_LOG_MESSAGE, I_CHILDREN, I_UNIT I_LOG_MESSAGE, I_CHILDREN, I_UNIT
} internalMessageType; } internalMessageType;
// Sensor types // Sensor types
typedef enum { typedef enum {
S_DOOR, S_MOTION, S_SMOKE, S_LIGHT, S_DIMMER, S_COVER, S_TEMP, S_HUM, S_BARO, S_WIND, 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_RAIN, S_UV, S_WEIGHT, S_POWER, S_HEATER, S_DISTANCE, S_LIGHT_LEVEL, S_ARDUINO_NODE,
S_ARDUINO_RELAY, S_LOCK, S_IR, S_WATER S_ARDUINO_RELAY, S_LOCK, S_IR, S_WATER
} sensor; } sensor;
// Possible return values by validate() when doing crc check of received message. // Possible return values by validate() when doing crc check of received message.
enum { enum {
VALIDATE_OK, VALIDATE_BAD_CRC, VALIDATE_BAD_VERSION VALIDATE_OK, VALIDATE_BAD_CRC, VALIDATE_BAD_VERSION
}; };
// The message structure // The message structure
typedef struct { typedef struct {
uint8_t crc : 8; // 8 bits crc uint8_t crc : 8; // 8 bits crc
uint8_t version : 3; // 3 bits protocol version uint8_t version : 3; // 3 bits protocol version
uint8_t binary : 1; // 1 bit. Data is binary and should be encoded when sent to sensor net gateway uint8_t binary : 1; // 1 bit. Data is binary and should be encoded when sent to sensor net gateway
uint8_t from : 8; // 8 bits. RadioId of sender node uint8_t from : 8; // 8 bits. RadioId of sender node
uint8_t to : 8; // 8 bits. RadioId of destination node uint8_t to : 8; // 8 bits. RadioId of destination node
uint8_t last : 8; // 8 bits. RadioId of last node this message passed uint8_t last : 8; // 8 bits. RadioId of last node this message passed
uint8_t childId : 8; // 1 byte. Up to MAX_CHILD_DEVICES child sensors per radioId uint8_t childId : 8; // 1 byte. Up to MAX_CHILD_DEVICES child sensors per radioId
uint8_t messageType : 4; // 4 bits. Type of message. See messageType uint8_t messageType : 4; // 4 bits. Type of message. See messageType
uint8_t type : 8; // 8 bits. variableType or deviceType depending on messageType uint8_t type : 8; // 8 bits. variableType or deviceType depending on messageType
} header_s; } header_s;
typedef struct { typedef struct {
header_s header; header_s header;
char data[MAX_MESSAGE_LENGTH - sizeof(header_s) + 1]; // Each message can transfer a payload. Add one extra byte for \0 char data[MAX_MESSAGE_LENGTH - sizeof(header_s) + 1]; // Each message can transfer a payload. Add one extra byte for \0
} message_s; } message_s;
class Sensor : public RF24 class Sensor : public RF24
{ {
public: public:
/** /**
* Constructor * Constructor
* *
* Creates a new instance of Sensor class. * Creates a new instance of Sensor class.
* *
* @param _cepin The pin attached to RF24 Chip Enable on the RF module (defualt 9) * @param _cepin The pin attached to RF24 Chip Enable on the RF module (defualt 9)
* @param _cspin The pin attached to RF24 Chip Select (default 10) * @param _cspin The pin attached to RF24 Chip Select (default 10)
*/ */
Sensor(uint8_t _cepin=9, uint8_t _cspin=10); Sensor(uint8_t _cepin=9, uint8_t _cspin=10);
/** /**
* Begin operation of the sensor net library * Begin operation of the sensor net library
* *
* Call this in setup(), before calling any other sensor net library methods. * Call this in setup(), before calling any other sensor net library methods.
* @param radioId The unique id (1-254) for this sensor. Default 255 (auto mode). * @param radioId The unique id (1-254) for this sensor. Default 255 (auto mode).
* @param paLevel Radio PA Level for this sensor. Default RF24_PA_MAX * @param paLevel Radio PA Level for this sensor. Default RF24_PA_MAX
* @param channel Radio channel. Default RF24_PA_MAX * @param channel Radio channel. Default RF24_PA_MAX
*/ */
void begin(uint8_t radioId=AUTO, rf24_pa_dbm_e paLevel=RF24_PA_MAX, uint8_t channel=70); void begin(uint8_t radioId=AUTO, rf24_pa_dbm_e paLevel=RF24_PA_MAX, uint8_t channel=76);
uint8_t getRadioId(); uint8_t getRadioId();
/** /**
* The arduino node must send a presentation of all the sensors connected before any * The arduino node must send a presentation of all the sensors connected before any
* variable changes will be registered on sensor net gateway side. * variable changes will be registered on sensor net gateway side.
* Usually it's good to present all sensors when arduino starts up (setup). * Usually it's good to present all sensors when arduino starts up (setup).
* Note that gateway must be in include mode to register new devices. * Note that gateway must be in include mode to register new devices.
* *
* @param childId The unique child id for the different sensors connected to this arduino. 0-254. * @param childId The unique child id for the different sensors connected to this arduino. 0-254.
* @param sensorType Sensor types to create. They will be numbered from 0 up to 127. * @param sensorType Sensor types to create. They will be numbered from 0 up to 127.
*/ */
void sendSensorPresentation(uint8_t childId, uint8_t sensorType); void sendSensorPresentation(uint8_t childId, uint8_t sensorType);
/** /**
* Sends a variable change to sensor net gateway (or another sensor if radioId is specified) * Sends a variable change to sensor net gateway (or another sensor if radioId is specified)
* *
* @param radioId The radioId of other node in radio network (used for communicating between sensors) * @param radioId The radioId of other node in radio network (used for communicating between sensors)
* @param childId The child id for which to update variable. Value can be 0-254. * @param childId The child id for which to update variable. Value can be 0-254.
* @param variableType The variableType to update * @param variableType The variableType to update
* @param value New value of the variable * @param value New value of the variable
*/ */
void sendVariable(uint8_t childId, uint8_t variableType, const char *value); void sendVariable(uint8_t childId, uint8_t variableType, const char *value);
void sendVariable(uint8_t childId, uint8_t variableType, double value, int decimals); void sendVariable(uint8_t childId, uint8_t variableType, double value, int decimals);
void sendVariable(uint8_t childId, uint8_t variableType, unsigned long value); void sendVariable(uint8_t childId, uint8_t variableType, unsigned long value);
void sendVariable(uint8_t childId, uint8_t variableType, long value); void sendVariable(uint8_t childId, uint8_t variableType, long value);
void sendVariable(uint8_t childId, uint8_t variableType, unsigned int value); void sendVariable(uint8_t childId, uint8_t variableType, unsigned int value);
void sendVariable(uint8_t childId, uint8_t variableType, int value); void sendVariable(uint8_t childId, uint8_t variableType, int value);
void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, const char *value); void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, const char *value);
void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, double value, int decimals); void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, double value, int decimals);
void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, unsigned long value); void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, unsigned long value);
void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, long value); void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, long value);
void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, unsigned int value); void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, unsigned int value);
void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, int value); void sendVariable(uint8_t radioId, uint8_t childId, uint8_t variableType, int value);
/** /**
* Sends battery status to sensor net gateway for this radio node. * Sends battery status to sensor net gateway for this radio node.
* @param value Set a value between 0-100(%) * @param value Set a value between 0-100(%)
*/ */
void sendBatteryLevel(int value); void sendBatteryLevel(int value);
/** /**
* Requests a variable value from sensor net gateway (or another sensor). This method will not wait for an answer. * Requests a variable value from sensor net gateway (or another sensor). This method will not wait for an answer.
* You should use mesageAvailable/getMessage to pick up the response. * You should use mesageAvailable/getMessage to pick up the response.
* *
* @param radioId The radioId of other node in radio network (used when fetching from other node) * @param radioId The radioId of other node in radio network (used when fetching from other node)
* @param childId The unique child id for the different sensors connected to this arduino. 0-254. * @param childId The unique child id for the different sensors connected to this arduino. 0-254.
* @param variableType The variableType to fetch * @param variableType The variableType to fetch
*/ */
void requestStatus(uint8_t childId, uint8_t variableType); void requestStatus(uint8_t childId, uint8_t variableType);
void requestStatus(uint8_t radioId, int8_t childId, uint8_t variableType); void requestStatus(uint8_t radioId, int8_t childId, uint8_t variableType);
/** /**
* Requests status for a sensor variable from sensor net gateway. Waits until message arrives. * Requests status for a sensor variable from sensor net gateway. Waits until message arrives.
* *
* @param radioId The radioId of other node in radio network (used when fetching from other node) * @param radioId The radioId of other node in radio network (used when fetching from other node)
* @param childId The unique child id for the different sensors connected to this arduino. 0-254. * @param childId The unique child id for the different sensors connected to this arduino. 0-254.
* @param variableType The variableType to fetch * @param variableType The variableType to fetch
* @return The variable value * @return The variable value
*/ */
char *getStatus(uint8_t childId, uint8_t variableType); char *getStatus(uint8_t childId, uint8_t variableType);
char *getStatus(uint8_t radioId, int8_t childId, uint8_t variableType); char *getStatus(uint8_t radioId, int8_t childId, uint8_t variableType);
/** /**
* Fetches time from sensor net gateway * Fetches time from sensor net gateway
*/ */
void requestTime(); void requestTime();
unsigned long getTime(); unsigned long getTime();
/** /**
* Fetches unit setting from sensor net gateway. Returns true if metric system has been selected which means * Fetches unit setting from sensor net gateway. Returns true if metric system has been selected which means
* that sensor should report it's information in: celsius, meter, cm, gram, km/h, m/s etc.. * that sensor should report it's information in: celsius, meter, cm, gram, km/h, m/s etc..
* If false is returned the sensor should report data in imperial system which means * If false is returned the sensor should report data in imperial system which means
* fahrenheit, feet, gallon, mph etc... * fahrenheit, feet, gallon, mph etc...
*/ */
void requestIsMetricSystem(); void requestIsMetricSystem();
bool isMetricSystem(); bool isMetricSystem();
/** /**
* Busy waits until there is a message for this node available to be read * Busy waits until there is a message for this node available to be read
*/ */
message_s waitForMessage(void); message_s waitForMessage(void);
/** /**
* Returns true if there is a message addressed for this node is available to be read * Returns true if there is a message addressed for this node is available to be read
*/ */
boolean messageAvailable(void); boolean messageAvailable(void);
/** /**
* Returns the last received message * Returns the last received message
*/ */
message_s getMessage(void); message_s getMessage(void);
/** /**
* Validates consistency of the message including CRC and protocol version * Validates consistency of the message including CRC and protocol version
*/ */
uint8_t validate(uint8_t length); uint8_t validate(uint8_t length);
#ifdef DEBUG #ifdef DEBUG
void debugPrint(const char *fmt, ... ); void debugPrint(const char *fmt, ... );
int freeRam(); int freeRam();
#endif #endif
protected: protected:
uint8_t failedTransmissions; uint8_t failedTransmissions;
boolean isRelay; boolean isRelay;
uint8_t radioId; uint8_t radioId;
uint8_t distance; // This nodes distance to sensor net gateway (number of hops) uint8_t distance; // This nodes distance to sensor net gateway (number of hops)
uint8_t relayId; uint8_t relayId;
message_s msg; // Buffer for incoming messages. message_s msg; // Buffer for incoming messages.
char convBuffer[20]; char convBuffer[20];
void setupRadio(rf24_pa_dbm_e paLevel, uint8_t channel); void setupRadio(rf24_pa_dbm_e paLevel, uint8_t channel);
void findRelay(); void findRelay();
boolean send(message_s message, int length); boolean send(message_s message, int length);
boolean sendWrite(uint8_t dest, message_s message, int length); boolean sendWrite(uint8_t dest, message_s message, int length);
boolean readMessage(); boolean readMessage();
void buildMsg(uint8_t from, uint8_t to, uint8_t childId, uint8_t messageType, uint8_t type, const char *data, uint8_t length, boolean binary); void buildMsg(uint8_t from, uint8_t to, uint8_t childId, uint8_t messageType, uint8_t type, const char *data, uint8_t length, boolean binary);
void sendInternal(uint8_t variableType, const char *value); void sendInternal(uint8_t variableType, const char *value);
boolean sendVariableAck(); boolean sendVariableAck();
boolean sendData(uint8_t from, uint8_t to, uint8_t childId, uint8_t messageType, uint8_t type, const char *data, uint8_t length, boolean binaryMessage); boolean sendData(uint8_t from, uint8_t to, uint8_t childId, uint8_t messageType, uint8_t type, const char *data, uint8_t length, boolean binaryMessage);
private: private:
message_s ack; // Buffer for ack messages. message_s ack; // Buffer for ack messages.
void initializeRadioId(); void initializeRadioId();
uint8_t crc8Message(message_s, uint8_t length); uint8_t crc8Message(message_s, uint8_t length);
char* get(uint8_t nodeId, uint8_t childId, uint8_t sendType, uint8_t receiveType, uint8_t variableType); char* get(uint8_t nodeId, uint8_t childId, uint8_t sendType, uint8_t receiveType, uint8_t variableType);
char *getInternal(uint8_t variableType); char *getInternal(uint8_t variableType);
}; };
#endif #endif
@@ -10,7 +10,7 @@
#define RELAY_ON 0 #define RELAY_ON 0
#define RELAY_OFF 1 #define RELAY_OFF 1
Relay gw; Sensor gw;
void setup() void setup()
{ {
@@ -20,7 +20,6 @@ void setup()
for (int i=0; i<NUMBER_OF_RELAYS;i++) { for (int i=0; i<NUMBER_OF_RELAYS;i++) {
gw.sendSensorPresentation(RELAY_1+i, S_LIGHT); gw.sendSensorPresentation(RELAY_1+i, S_LIGHT);
} }
// Fetch relay status // Fetch relay status
for (int i=0; i<NUMBER_OF_RELAYS;i++) { for (int i=0; i<NUMBER_OF_RELAYS;i++) {
// Make sure relays are off when starting up // Make sure relays are off when starting up