Update mysensors sensor (#1976)

* Add V_DIRECTION.
* Add example sketch for mysensors 2.x.
This commit is contained in:
Martin Hjelmare 2017-02-05 21:07:45 +01:00 committed by GitHub
parent d7d4ed83f5
commit 74ac6b9383

View File

@ -24,7 +24,7 @@ S_TYPE | V_TYPE
S_TEMP | V_TEMP S_TEMP | V_TEMP
S_HUM | V_HUM S_HUM | V_HUM
S_BARO | V_PRESSURE, V_FORECAST S_BARO | V_PRESSURE, V_FORECAST
S_WIND | V_WIND, V_GUST S_WIND | V_WIND, V_GUST, V_DIRECTION
S_RAIN | V_RAIN, V_RAINRATE S_RAIN | V_RAIN, V_RAINRATE
S_UV | V_UV S_UV | V_UV
S_WEIGHT | V_WEIGHT, V_IMPEDANCE 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
For more information, visit the [serial api] of MySensors. For more information, visit the [serial api] of MySensors.
### {% linkable_title Example sketch %} ### {% linkable_title MySensors 1.5 example sketch %}
```cpp ```cpp
/** /**
@ -116,5 +116,69 @@ void loop()
} }
``` ```
### {% linkable_title MySensors 2.x example sketch %}
```cpp
/**
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* http://www.mysensors.org/build/light
*/
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <BH1750.h>
#include <Wire.h>
#include <MySensors.h>
#define SN "LightLuxSensor"
#define SV "1.0"
#define CHILD_ID 1
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
BH1750 lightSensor;
MyMessage msg(CHILD_ID, V_LEVEL);
MyMessage msgPrefix(CHILD_ID, V_UNIT_PREFIX); // Custom unit message.
uint16_t lastlux = 0;
bool initialValueSent = false;
void setup()
{
sendSketchInfo(SN, SV);
present(CHILD_ID, S_LIGHT_LEVEL);
lightSensor.begin();
}
void loop()
{
if (!initialValueSent) {
Serial.println("Sending initial value");
send(msgPrefix.set("custom_lux")); // Set custom unit.
send(msg.set(lastlux));
Serial.println("Requesting initial value from controller");
request(CHILD_ID, V_LEVEL);
wait(2000, C_SET, V_LEVEL);
}
uint16_t lux = lightSensor.readLightLevel(); // Get Lux value
if (lux != lastlux) {
send(msg.set(lux));
lastlux = lux;
}
sleep(SLEEP_TIME);
}
void receive(const MyMessage &message) {
if (message.type == V_LEVEL) {
if (!initialValueSent) {
Serial.println("Receiving initial value from controller");
initialValueSent = true;
}
}
}
```
[main component]: /components/mysensors/ [main component]: /components/mysensors/
[serial api]: https://www.mysensors.org/download/serial_api_15 [serial api]: https://www.mysensors.org/download/serial_api_15