MySensors Library & Examples  2.3.2-62-ge298769
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-2022 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 //#define MY_PJON
37 
38 #include <MySensors.h>
39 
40 #define COMPARE_PH 1 // Send PH only if changed? 1 = Yes 0 = No
41 
42 uint32_t SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
43 float lastPH;
44 bool receivedConfig = false;
45 bool metric = true;
46 // Initialize PH message
47 MyMessage msg(0, V_PH);
48 
49 void setup()
50 {
51  //Setup your PH sensor here (I2C,Serial,Phidget...)
52 }
53 
54 float getPH()
55 {
56  //query your PH sensor here (I2C,Serial,Phidget...)
57  float dummy = 7;
58  return dummy;
59 }
60 
62 {
63  // Send the sketch version information to the gateway and Controller
64  sendSketchInfo("PH Sensor", "1.1");
65  present(0, S_WATER_QUALITY);
66 
67 }
68 
69 void loop()
70 {
71  float ph = getPH();
72 
73 #if COMPARE_PH == 1
74  if (lastPH != ph) {
75 #endif
76 
77  // Send in the new PH value
78  send(msg.set(ph, 1));
79  // Save new PH value for next compare
80  lastPH = ph;
81 
82 #if COMPARE_PH == 1
83  }
84 #endif
85  sleep(SLEEP_TIME);
86 }
sendSketchInfo
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
loop
void loop()
Main loop.
Definition: PHSensor.ino:69
presentation
void presentation()
Node presentation.
Definition: PHSensor.ino:61
MyMessage::set
MyMessage & set(const void *payload, const size_t length)
Set entire payload.
send
bool send(MyMessage &msg, const bool requestEcho=false)
present
bool present(const uint8_t sensorId, const mysensors_sensor_t sensorType, const char *description="", const bool requestEcho=false)
setup
void setup()
Called after node initialises but before main loop.
Definition: PHSensor.ino:49
sleep
int8_t sleep(const uint32_t sleepingMS, const bool smartSleep=false)
MySensors.h
API declaration for MySensors.
MyMessage
MyMessage is used to create, manipulate, send and read MySensors messages.
Definition: MyMessage.h:290