-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartAquarium.ino
70 lines (61 loc) · 1.86 KB
/
SmartAquarium.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include <Arduino.h>
#include "include/ConnectivityManager.h"
#include "include/TemperatureSensor.h"
#include "WaterLevelManager.h"
#include "TemperatureManager.h"
ConnectivityManager* CM = new ConnectivityManager("TOPNETE136FE54", "F57B95D1E6");
void ManageWaterLevelData(const uint8_t& sendMQTT, const uint8_t& debugSerial){
// Checks if the Water level has changed
if(WL_Changed == 1){
// Sends an MQTT message
if (sendMQTT)
CM->sendMQTTMessage("AQUAIOTSLEAM2020", getWaterLevelAsString().c_str());
// Sends on the serial
if (debugSerial){
Serial.print("Water level changed to : ");
Serial.print(getWaterLevelAsString());
Serial.println();
}
WL_Changed = 0; // ReInitialize the status for an upcoming access
}
}
void ManageTemperatureData(const uint8_t& sendMQTT, const uint8_t& debugSerial){
if (TMP_Changed == 1){
// Sends an MQTT message
if (sendMQTT)
CM->sendMQTTMessage("AQUAIOTSLEAM2020", String(temperature).c_str());
// Sends on the serial
if (debugSerial){
Serial.print("Temperature : ");
Serial.print(String(temperature));
Serial.println();
}
TMP_Changed = 0;
}
}
void setup() {
// Init the Serial
Serial.begin(115200);
//Init the Connectivity Manager
CM->connect();
// 0.1 sec delay
delay(100);
// Connect to the MQTT server
// CM->connectToMQTT("AQUAIOTSLEAM2020");
}
void loop() {
//Init the Connectivity Manager
CM->connect();
// This is called due to some connectivity issues with the server
CM->connectToMQTT("AQUAIOTSLEAM2020");
// Water level sensors loop
WaterLevelLoop();
// Water level sensors Display/Send Data
ManageWaterLevelData(true, true);
// Temperature sensor loop
TemperatureLoop();
// Temperature sensor Display/Send Data
ManageTemperatureData(true, true);
ESP.deepSleep(30e6);
}