-
Notifications
You must be signed in to change notification settings - Fork 3
/
MyMultiSensor.ino
252 lines (227 loc) · 5.32 KB
/
MyMultiSensor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// Enable debug prints
//#define MY_DEBUG
#define TEST
#define SKETCH_NAME "Multisensor"
#define SKETCH_MAJOR_VER "2"
#define SKETCH_MINOR_VER "8"
// Enable and select radio type attached
#define MY_RADIO_RFM69
#define MY_RFM69_CS_PIN 10
#define MY_RFM69_IRQ_PIN 2
#define MY_RFM69_NEW_DRIVER
#define MY_RFM69_ATC_MODE_DISABLED
#define MY_RFM69_TX_POWER_DBM 10
#define MY_SIGNAL_REPORT_ENABLED
#ifdef LARGE_BATHROOM_MOTION
#define MY_NODE_ID 3
#define SKETCH_SUBNAME "LargeBathroom"
#define USE_BME280
#define USE_BH1750
#define MULTISENSOR
#endif
#ifdef LIVINGROOM
#define MY_NODE_ID 20
#define SKETCH_SUBNAME "Livingroom"
#define USE_BME280
#define INITIAL_BOOST false
#define ALWAYS_BOOST false
#define LOW_VOLTAGE_BOOST true
#define LI_ION_BATTERY false
#define BUTTON_PIN 2
#undef MY_RFM69_IRQ_PIN
#define MY_RFM69_IRQ_PIN 3
#define LED_PIN -1
#endif
#ifdef SMALL_BATHROOM
#define MY_NODE_ID 21
#define SKETCH_SUBNAME "SmallBathroom"
#define USE_BME280
#define USE_BH1750
#define INITIAL_BOOST false
#define ALWAYS_BOOST false
#define LOW_VOLTAGE_BOOST true
#define LI_ION_BATTERY false
#define BUTTON_PIN 3
#define LED_PIN -1
#endif
#ifdef CORRIDOR_MOTION
#define MY_NODE_ID 26
#define SKETCH_SUBNAME "Corridor"
#define USE_BH1750
#define MULTISENSOR
#endif
#ifdef LARGE_BEDROOM_MOTION
#define MY_NODE_ID 27
#define SKETCH_SUBNAME "LargeBedroom"
#define USE_BME280
#define USE_BH1750
#define MULTISENSOR
#endif
#ifdef SMALL_BEDROOM_MOTION
#define MY_NODE_ID 28
#define SKETCH_SUBNAME "SmallBedroom"
#define USE_BME280
#define USE_BH1750
#define MULTISENSOR
#endif
#ifdef KITCHEN_MOTION
#define MY_NODE_ID 29
#define SKETCH_SUBNAME "Kitchen"
#define USE_BH1750
#define MULTISENSOR
#endif
#ifdef BALCONY_MOTION
#define MY_NODE_ID 30
#define SKETCH_SUBNAME "Balcony"
#define USE_MOTION
#define INITIAL_BOOST false
#define ALWAYS_BOOST false
#define LOW_VOLTAGE_BOOST false
#define LI_ION_BATTERY false
#define BUTTON_PIN INTERRUPT_NOT_DEFINED
#define LED_PIN -1
#endif
#ifdef FRIDGE
#define MY_NODE_ID 4
#define SKETCH_SUBNAME "Fridge"
#endif
#ifdef SMALL_BEDROOM_BUTTON1
#define MY_NODE_ID 31
#undef SKETCH_NAME
#define SKETCH_NAME "Button"
#define SKETCH_SUBNAME "SmallBedroom"
#endif
#ifdef SMALL_BEDROOM_BUTTON2
#define MY_NODE_ID 32
#undef SKETCH_NAME
#define SKETCH_NAME "Button2"
#define SKETCH_SUBNAME "SmallBedroom"
#endif
#ifdef DUST_SENSOR
#define MY_NODE_ID 33
#undef MY_RFM69_IRQ_PIN
#define MY_RFM69_IRQ_PIN 3
#undef SKETCH_NAME
#define SKETCH_NAME "Dust"
#define SKETCH_SUBNAME "Sensor"
#endif
#ifdef TEST
#define MY_NODE_ID 25
#undef SKETCH_NAME
#define SKETCH_NAME "Test"
#define SKETCH_SUBNAME ""
#endif
#include <Wire.h>
#include <MySensors.h>
#include <MySensorsToolkit.h>
#include "BME280Sensor.h"
#include "BH1750Sensor.h"
#include <MySensorsToolkit/Sensor/MotionSensor.h>
#include "DHTSensor.h"
#include "DS18B20Sensor.h"
#include <MySensorsToolkit/Sensor/ButtonSensor.h>
#include "DustSensor.h"
using namespace mys_toolkit;
#define BATTERY_SENSE_PIN A7
#define POWER_BOOST_PIN A2
#ifdef MULTISENSOR
#define USE_MOTION
#define INITIAL_BOOST false
#define ALWAYS_BOOST true
#define LOW_VOLTAGE_BOOST false
#define LI_ION_BATTERY true
#define BUTTON_PIN INTERRUPT_NOT_DEFINED
#define LED_PIN -1
#endif
#ifdef FRIDGE
#define USE_DS18B20
#define INITIAL_BOOST true
#define ALWAYS_BOOST false
#define LOW_VOLTAGE_BOOST false
#define LI_ION_BATTERY false
#define BUTTON_PIN 3
#define LED_PIN -1
#endif
#ifdef SMALL_BEDROOM_BUTTON1
#define USE_BUTTON
#define INITIAL_BOOST false
#define ALWAYS_BOOST false
#define LOW_VOLTAGE_BOOST true
#define LI_ION_BATTERY false
#define BUTTON_PIN INTERRUPT_NOT_DEFINED
#define LED_PIN -1
#endif
#ifdef SMALL_BEDROOM_BUTTON2
#define USE_BUTTON
#define INITIAL_BOOST false
#define ALWAYS_BOOST false
#define LOW_VOLTAGE_BOOST true
#define LI_ION_BATTERY false
#define BUTTON_PIN INTERRUPT_NOT_DEFINED
#define LED_PIN -1
#endif
#ifdef DUST_SENSOR
DustSensor ds(1, 2, 3, 6, 5);
#define INITIAL_BOOST true
#define ALWAYS_BOOST false
#define LI_ION_BATTERY true
#define LOW_VOLTAGE_BOOST false
#define BUTTON_PIN 2
#define LED_PIN A1
#endif
#ifdef TEST
//#define USE_BME280
//#define USE_BH1750
//#define USE_MOTION
//#define USE_DHT
//#define USE_DS18B20
#define INITIAL_BOOST false
#define ALWAYS_BOOST false
#define LI_ION_BATTERY false
#define LOW_VOLTAGE_BOOST true
#define BUTTON_PIN 3//INTERRUPT_NOT_DEFINED
#define LED_PIN A1
#endif
#ifdef USE_BME280
BME280Sensor bme280(0, 1, 3.0, 0.5);
#endif
#ifdef USE_BH1750
BH1750Sensor bh1750(2, 20);
#endif
#ifdef USE_MOTION
MotionSensor motion(4, 3);
#endif
#ifdef USE_DHT
DHTSensor dht(5, 6, 6, 3.0, 0.5);
#endif
#ifdef USE_DS18B20
DS18B20Sensor ds18b20(7, A5, 0.5);
#endif
#ifdef USE_BUTTON
ButtonSensor button(8, 3);
#endif
void before()
{
#if defined(USE_BME280) || defined(USE_BH1750)
#if defined(USE_DS18B20)
#error "Cannot set USE_DS18B20 toghether with USE_BME280 or USE_BH1750"
#endif
Wire.begin();
#endif
SensorBase::begin(BATTERY_SENSE_PIN, LI_ION_BATTERY, POWER_BOOST_PIN,
INITIAL_BOOST, ALWAYS_BOOST, LOW_VOLTAGE_BOOST,
BUTTON_PIN, LED_PIN);
}
void presentation()
{
// Send the sketch version information to the gateway
sendSketchInfo(SKETCH_NAME "-" SKETCH_SUBNAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
SensorBase::present();
}
void loop()
{
SensorBase::update();
}
void receive(const MyMessage &message) {
SensorBase::receive(message);
}