IoT - Modular - DepthProbes.cpp

From The TinkerNet Wiki
Jump to navigation Jump to search

#includes, Defines, etc...

 1 #include "libraries.h"
 2 #include "functions.h"
 3 
 4 /*
 5  * Puplish to tele/TankLevel
 6  * 
 7  * If all probes are high
 8  *  publish {"Tank":"PumpHouse", "Level":0}
 9  * If bottom probe is low
10  *  publish {"Tank":"PumpHouse", "Level":25}
11  * If bottom probe is low
12  *  publish {"Tank":"PumpHouse", "Level":50}
13  * If bottom probe is low
14  *  publish {"Tank":"PumpHouse", "Level":75}
15  * If bottom probe is low
16  *  publish {"Tank":"PumpHouse", "Level":100}
17  */
18 
19 int Probe1 = 4; // no pullup...
20 int Probe2 = 5;
21 int Probe3 = 12; // no pullup...
22 int Probe4 = 13;

Depth_init()

 1 void Depth_init()
 2 {
 3     char debugTEXT[46];
 4     debug_SectionTitle("Configuring Depth Probes...");
 5     // pinMode(Probe1, INPUT_PULLUP);
 6     // pinMode(Probe2, INPUT_PULLUP);
 7     // pinMode(Probe3, INPUT_PULLUP);
 8     // pinMode(Probe4, INPUT_PULLUP);
 9     pinMode(Probe1, INPUT);
10     pinMode(Probe2, INPUT);
11     pinMode(Probe3, INPUT);
12     pinMode(Probe4, INPUT);
13 #ifdef DEBUG
14     sprintf(debugTEXT, "Depth Probes on GPIOs %d %d %d & %d", Probe1, Probe2, Probe3, Probe4);
15     debug_LineOut(debugTEXT);
16 #endif
17 }

CheckProbes()

 1 void CheckProbes()
 2 {
 3     Serial.print("Probes: ");
 4     Serial.print(digitalRead(Probe1));
 5     Serial.print(" ");
 6     Serial.print(digitalRead(Probe2));
 7     Serial.print(" ");
 8     Serial.print(digitalRead(Probe3));
 9     Serial.print(" ");
10     Serial.print(digitalRead(Probe4));
11     Serial.println(" ");
12     if (!digitalRead(Probe4)) // 14   D5
13     {
14         MQTT_SendTELE("Level", "{\"Tank\":\"PumpHouse\", \"Level\":100}");
15         // MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "{\"Tank\":\"PumpHouse\", \"Level\":100}");
16         MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "100");
17         // Serial.println("PROBE 4");
18     }
19     // return 100;
20     else if (!digitalRead(Probe3)) // 13   D7
21     {
22         MQTT_SendTELE("Level", "{\"Tank\":\"PumpHouse\", \"Level\":75}");
23         // MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "{\"Tank\":\"PumpHouse\", \"Level\":75}");
24         MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "75");
25         // Serial.println("PROBE 3");
26     }
27     // return 75;
28     else if (!digitalRead(Probe2)) // 12   D6
29     {
30         MQTT_SendTELE("Level", "{\"Tank\":\"PumpHouse\", \"Level\":50}");
31         // MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "{\"Tank\":\"PumpHouse\", \"Level\":50}");
32         MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "50");
33         // Serial.println("PROBE 2");
34     }
35     // return 50;
36     else if (!digitalRead(Probe1)) // 5    D1
37     {
38         MQTT_SendTELE("Level", "{\"Tank\":\"PumpHouse\", \"Level\":25}");
39         // MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "{\"Tank\":\"PumpHouse\", \"Level\":25}");
40         MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "25");
41         // Serial.println("PROBE 1");
42     }
43     // return 25;
44     else
45     {
46         MQTT_SendTELE("Level", "{\"Tank\":\"PumpHouse\", \"Level\":0}");
47         // MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "{\"Tank\":\"PumpHouse\", \"Level\":0}");
48         MQTT_SendCMND("cmnd/SugarShack_Alarm/Level", "0");
49         // Serial.println("NO PROBE");
50     }
51     // return 0;
52 }