@@ -24,7 +24,7 @@ S_TYPE | V_TYPE
24
24
S_TEMP | V_TEMP
25
25
S_HUM | V_HUM
26
26
S_BARO | V_PRESSURE, V_FORECAST
27
- S_WIND | V_WIND, V_GUST
27
+ S_WIND | V_WIND, V_GUST, V_DIRECTION
28
28
S_RAIN | V_RAIN, V_RAINRATE
29
29
S_UV | V_UV
30
30
S_WEIGHT | V_WEIGHT, V_IMPEDANCE
@@ -68,7 +68,7 @@ By using V_UNIT_PREFIX, it's possible to set a custom unit for any sensor. The s
68
68
69
69
For more information, visit the [ serial api] of MySensors.
70
70
71
- ### {% linkable_title Example sketch %}
71
+ ### {% linkable_title MySensors 1.5 example sketch %}
72
72
73
73
``` cpp
74
74
/* *
@@ -116,5 +116,69 @@ void loop()
116
116
}
117
117
```
118
118
119
+ ### {% linkable_title MySensors 2.x example sketch %}
120
+
121
+ ```cpp
122
+ /**
123
+ * Documentation: http://www.mysensors.org
124
+ * Support Forum: http://forum.mysensors.org
125
+ *
126
+ * http://www.mysensors.org/build/light
127
+ */
128
+
129
+ #define MY_DEBUG
130
+ #define MY_RADIO_NRF24
131
+
132
+ #include <BH1750.h>
133
+ #include <Wire.h>
134
+ #include <MySensors.h>
135
+
136
+ #define SN "LightLuxSensor"
137
+ #define SV "1.0"
138
+ #define CHILD_ID 1
139
+ unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
140
+
141
+ BH1750 lightSensor;
142
+ MyMessage msg(CHILD_ID, V_LEVEL);
143
+ MyMessage msgPrefix(CHILD_ID, V_UNIT_PREFIX); // Custom unit message.
144
+ uint16_t lastlux = 0;
145
+ bool initialValueSent = false;
146
+
147
+ void setup()
148
+ {
149
+ sendSketchInfo(SN, SV);
150
+ present(CHILD_ID, S_LIGHT_LEVEL);
151
+ lightSensor.begin();
152
+ }
153
+
154
+ void loop()
155
+ {
156
+ if (!initialValueSent) {
157
+ Serial.println("Sending initial value");
158
+ send(msgPrefix.set("custom_lux")); // Set custom unit.
159
+ send(msg.set(lastlux));
160
+ Serial.println("Requesting initial value from controller");
161
+ request(CHILD_ID, V_LEVEL);
162
+ wait(2000, C_SET, V_LEVEL);
163
+ }
164
+ uint16_t lux = lightSensor.readLightLevel(); // Get Lux value
165
+ if (lux != lastlux) {
166
+ send(msg.set(lux));
167
+ lastlux = lux;
168
+ }
169
+
170
+ sleep(SLEEP_TIME);
171
+ }
172
+
173
+ void receive(const MyMessage &message) {
174
+ if (message.type == V_LEVEL) {
175
+ if (!initialValueSent) {
176
+ Serial.println("Receiving initial value from controller");
177
+ initialValueSent = true;
178
+ }
179
+ }
180
+ }
181
+ ```
182
+
119
183
[ main component ] : /components/mysensors/
120
184
[ serial api ] : https://www.mysensors.org/download/serial_api_15
0 commit comments