From 6aa1fb6e886dc075601c6cf57f72c8ae623b23f2 Mon Sep 17 00:00:00 2001 From: mboyer85 Date: Wed, 27 Jan 2016 19:25:04 +0100 Subject: [PATCH] Adding water quality management PHSensor example --- libraries/MySensors/examples/PHSensor.ino | 79 +++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 libraries/MySensors/examples/PHSensor.ino diff --git a/libraries/MySensors/examples/PHSensor.ino b/libraries/MySensors/examples/PHSensor.ino new file mode 100644 index 0000000..9e7a6c6 --- /dev/null +++ b/libraries/MySensors/examples/PHSensor.ino @@ -0,0 +1,79 @@ +/** + The MySensors Arduino library handles the wireless radio link and protocol + between your home built sensors/actuators and HA controller of choice. + The sensors forms a self healing radio network with optional repeaters. Each + repeater and gateway builds a routing tables in EEPROM which keeps track of the + network topology allowing messages to be routed to nodes. + + Created by mboyer85 + Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + + Documentation: http://www.mysensors.org + Support Forum: http://forum.mysensors.org + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + ******************************* + + DESCRIPTION + + Example sketch showing how to send PH readings back to the controller +*/ + +// Enable debug prints to serial monitor +//#define MY_DEBUG + +// Enable and select radio type attached +#define MY_RADIO_NRF24 +//#define MY_RADIO_RFM69 + +#include +#include + +#define COMPARE_PH 1 // Send PH only if changed? 1 = Yes 0 = No + +unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds) +float lastPH; +boolean receivedConfig = false; +boolean metric = true; +// Initialize PH message +MyMessage msg(0, V_PH); + +void setup() +{ + //Setup your PH sensor here (I2C,Serial,Phidget...) +} + +float getPH() { + //query your PH sensor here (I2C,Serial,Phidget...) + float dummy = 7; + return dummy; +} + +void presentation() { + // Send the sketch version information to the gateway and Controller + sendSketchInfo("PH Sensor", "1.1"); + present(0, S_WATER_QUALITY); + +} + +void loop() +{ + float ph = getPH(); + +#if COMPARE_PH == 1 + if (lastPH != ph) { +#endif + + // Send in the new PH value + send(msg.set(ph, 1)); + // Save new PH value for next compare + lastPH = ph; + +#if COMPARE_PH == 1 + } +#endif + sleep(SLEEP_TIME); +}