Files
MySensors/examples/PHSensor/PHSensor.ino
Patrick Fallberg 8e1ef13804 Repo restyled using astyle (#683)
The rules are in .tools/astyle/config/style.cfg
and can also be reviewed at
https://www.mysensors.org/view/260#coding-guidelines-core-library
2016-12-07 23:44:29 +01:00

81 lines
1.9 KiB
C++

/**
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 <MySensors.h>
#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;
bool receivedConfig = false;
bool 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);
}