more improvements
This commit is contained in:
+24
-2
@@ -36,17 +36,25 @@ Pump pump(SSR_PIN, PRESSURE_PIN, INT_HALL_PIN, STATUS_LED_1_PIN);
|
||||
Valve valves(MAX_VALVE_OPEN);
|
||||
EthernetClient ethClient;
|
||||
PubSubClient client(ethClient);
|
||||
// Adafruit_BMP085 bmp;
|
||||
|
||||
void reconnect();
|
||||
void callback(char* topic, byte* payload, unsigned int length);
|
||||
void sendPumpStatus();
|
||||
void sendValveStatus(uint8_t valveNumber);
|
||||
void sendInfo();
|
||||
// void sendEnviromentInfo();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("Arduino Irrigation"));
|
||||
|
||||
// if (!bmp.begin()) {
|
||||
// Serial.println(F("Could not find a valid BMP085 sensor,check wiring!"));
|
||||
// while (true);
|
||||
// }
|
||||
|
||||
|
||||
pinMode(SROE_PIN, OUTPUT);
|
||||
pinMode(SRCLR_PIN, OUTPUT);
|
||||
digitalWrite(SROE_PIN, LOW);
|
||||
@@ -62,7 +70,7 @@ void setup() {
|
||||
client.setCallback(callback);
|
||||
|
||||
Ethernet.begin(mac, ip, dns, gateway, subnet);
|
||||
Serial.print("Info: ");
|
||||
Serial.print(F("Info: "));
|
||||
Serial.println(Ethernet.localIP() );
|
||||
|
||||
// if (Ethernet.begin(mac) == 0) {
|
||||
@@ -95,6 +103,7 @@ void loop() {
|
||||
if (millis() - lastDataSend > 2000) {
|
||||
sendInfo();
|
||||
sendPumpStatus();
|
||||
// sendEnviromentInfo();
|
||||
for (uint8_t i = 0; i < VALVE_COUNT; i++)
|
||||
sendValveStatus(i);
|
||||
lastDataSend = millis();
|
||||
@@ -111,7 +120,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
DeserializationError error = deserializeJson(doc, payload, length);
|
||||
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.print("deserializeJson() failed: ");
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
@@ -212,3 +221,16 @@ void sendInfo() {
|
||||
client.publish(topic, buffer, n);
|
||||
}
|
||||
|
||||
// void sendEnviromentInfo() {
|
||||
// StaticJsonDocument<96> doc;
|
||||
// JsonObject enviroment = doc.createNestedObject("enviroment");
|
||||
|
||||
// enviroment["temperature"] = bmp.readTemperature();
|
||||
// enviroment["pressure"] = bmp.readPressure();
|
||||
|
||||
// char buffer[256];
|
||||
// char topic[64];
|
||||
// sprintf(topic, "%s/info", mainTopic);
|
||||
// size_t n = serializeJson(doc, buffer);
|
||||
// client.publish(topic, buffer, n);
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user