MySensors Library & Examples  2.3.2
PHSensor.ino
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 Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2019 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  *
19  *******************************
20  *
21  * REVISION HISTORY
22  * Version 1.0 - mboyer85
23  *
24  * DESCRIPTION
25  * Example sketch showing how to send PH readings back to the controller
26  */
27 
28 // Enable debug prints to serial monitor
29 //#define MY_DEBUG
30 
31 // Enable and select radio type attached
32 #define MY_RADIO_RF24
33 //#define MY_RADIO_NRF5_ESB
34 //#define MY_RADIO_RFM69
35 //#define MY_RADIO_RFM95
36 
37 #include <MySensors.h>
38 
39 #define COMPARE_PH 1 // Send PH only if changed? 1 = Yes 0 = No
40 
41 uint32_t SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
42 float lastPH;
43 bool receivedConfig = false;
44 bool metric = true;
45 // Initialize PH message
46 MyMessage msg(0, V_PH);
47 
48 void setup()
49 {
50  //Setup your PH sensor here (I2C,Serial,Phidget...)
51 }
52 
53 float getPH()
54 {
55  //query your PH sensor here (I2C,Serial,Phidget...)
56  float dummy = 7;
57  return dummy;
58 }
59 
61 {
62  // Send the sketch version information to the gateway and Controller
63  sendSketchInfo("PH Sensor", "1.1");
64  present(0, S_WATER_QUALITY);
65 
66 }
67 
68 void loop()
69 {
70  float ph = getPH();
71 
72 #if COMPARE_PH == 1
73  if (lastPH != ph) {
74 #endif
75 
76  // Send in the new PH value
77  send(msg.set(ph, 1));
78  // Save new PH value for next compare
79  lastPH = ph;
80 
81 #if COMPARE_PH == 1
82  }
83 #endif
84  sleep(SLEEP_TIME);
85 }
MyMessage is used to create, manipulate, send and read MySensors messages.
Definition: MyMessage.h:289
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
API declaration for MySensors.
bool send(MyMessage &msg, const bool requestEcho=false)
bool present(const uint8_t sensorId, const mysensors_sensor_t sensorType, const char *description="", const bool requestEcho=false)
void setup()
Called after node initialises but before main loop.
Definition: PHSensor.ino:48
int8_t sleep(const uint32_t sleepingMS, const bool smartSleep=false)
void presentation()
Node presentation.
Definition: PHSensor.ino:60
MyMessage & set(const void *payload, const size_t length)
Set entire payload.
void loop()
Main loop.
Definition: PHSensor.ino:68