|
| 1 | +/** |
| 2 | + The MySensors Arduino library handles the wireless radio link and protocol |
| 3 | + between your home built sensors/actuators and HA controller of choice. |
| 4 | + The sensors forms a self healing radio network with optional repeaters. Each |
| 5 | + repeater and gateway builds a routing tables in EEPROM which keeps track of the |
| 6 | + network topology allowing messages to be routed to nodes. |
| 7 | +
|
| 8 | + Created by mboyer85 |
| 9 | + Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors |
| 10 | +
|
| 11 | + Documentation: http://www.mysensors.org |
| 12 | + Support Forum: http://forum.mysensors.org |
| 13 | +
|
| 14 | + This program is free software; you can redistribute it and/or |
| 15 | + modify it under the terms of the GNU General Public License |
| 16 | + version 2 as published by the Free Software Foundation. |
| 17 | +
|
| 18 | + ******************************* |
| 19 | +
|
| 20 | + DESCRIPTION |
| 21 | +
|
| 22 | + Example sketch showing how to send PH readings back to the controller |
| 23 | +*/ |
| 24 | + |
| 25 | +// Enable debug prints to serial monitor |
| 26 | +//#define MY_DEBUG |
| 27 | + |
| 28 | +// Enable and select radio type attached |
| 29 | +#define MY_RADIO_NRF24 |
| 30 | +//#define MY_RADIO_RFM69 |
| 31 | + |
| 32 | +#include <SPI.h> |
| 33 | +#include <MySensor.h> |
| 34 | + |
| 35 | +#define COMPARE_PH 1 // Send PH only if changed? 1 = Yes 0 = No |
| 36 | + |
| 37 | +unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds) |
| 38 | +float lastPH; |
| 39 | +boolean receivedConfig = false; |
| 40 | +boolean metric = true; |
| 41 | +// Initialize PH message |
| 42 | +MyMessage msg(0, V_PH); |
| 43 | + |
| 44 | +void setup() |
| 45 | +{ |
| 46 | + //Setup your PH sensor here (I2C,Serial,Phidget...) |
| 47 | +} |
| 48 | + |
| 49 | +float getPH() { |
| 50 | + //query your PH sensor here (I2C,Serial,Phidget...) |
| 51 | + float dummy = 7; |
| 52 | + return dummy; |
| 53 | +} |
| 54 | + |
| 55 | +void presentation() { |
| 56 | + // Send the sketch version information to the gateway and Controller |
| 57 | + sendSketchInfo("PH Sensor", "1.1"); |
| 58 | + present(0, S_WATER_QUALITY); |
| 59 | + |
| 60 | +} |
| 61 | + |
| 62 | +void loop() |
| 63 | +{ |
| 64 | + float ph = getPH(); |
| 65 | + |
| 66 | +#if COMPARE_PH == 1 |
| 67 | + if (lastPH != ph) { |
| 68 | +#endif |
| 69 | + |
| 70 | + // Send in the new PH value |
| 71 | + send(msg.set(ph, 1)); |
| 72 | + // Save new PH value for next compare |
| 73 | + lastPH = ph; |
| 74 | + |
| 75 | +#if COMPARE_PH == 1 |
| 76 | + } |
| 77 | +#endif |
| 78 | + sleep(SLEEP_TIME); |
| 79 | +} |
0 commit comments