Nimbin[12]?Embedded / esp_garden / client_pump/main/OLD.client_pump.ino

esp_garden git · master

Distributed ESP sensor and actuator system (garden)

esp32 esp-idf iot sensors c++ sql · first commit 2025-10-15 · last commit 2026-01-20 (8 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/mic/esp_garden

C++ 70.7% Markdown 18% C 10.7%
git clone https://git.christianimmanuel.de/embedded/esp_garden.gitwget https://git.christianimmanuel.de/embedded/esp_garden/archive/esp_garden.tar.gz
client_pump/main/OLD.client_pump.ino 1.9 KB · 76 lines raw
#include "ClientPump.h"

#include "esp_system.h"
extern "C" esp_err_t esp_base_mac_addr_set(const uint8_t mac[6]);




long long next_message_unix = 0;
bool received_starting_message = false;

PumpConfig_s pump_configs[PUMP_COUNT] = {
    {"pump_1", 0, 0, 0, 0, INACTIVE},
    {"pump_2", 0, 0, 0, 0, INACTIVE},
};



void start_Pump(PumpConfig_s& pump_data) {
    DBG_PRINTF("Starting Pump %s\n", pump_data.pump_name);
    pump_data.pumping_started_at_unix = get_CurrentUnix();
    pump_data.pumping_status = RUNNING;
    // whatever we have to do to make the pump running
}

void stop_Pump(PumpConfig_s& pump_data) {
    DBG_PRINTF("Stopped Pump %s\n", pump_data.pump_name);
    pump_data.pumping_status = INACTIVE;
    // whatever we have to do to stop the pump
}

void setup() {
    uint32_t setup_start = millis();

    DBG_BEGIN();

    esp_base_mac_addr_set(PEER_PUMP);

    setup_Timezone();
    init_WiFi();
    init_EspNow();

    next_message_unix = 0;
    received_starting_message = false;

    g_setup_duration = millis() - setup_start;
    DBG_PRINTF("Setup duration: %u ms\n", g_setup_duration);
}


void loop() {
    bool pumping = false;
    for (size_t i = 0; i < PUMP_COUNT; i++) {
        PumpConfig_s& cfg = pump_configs[i];

        if (START == cfg.pumping_status) {

            pumping = true;
            received_starting_message = false;
            start_Pump(cfg);

        } else
        if (RUNNING == cfg.pumping_status) {

            long long stop_time = cfg.pumping_started_at_unix + cfg.pumping_duration;
            long long now = get_CurrentUnix();
            // maybe we should add a safety here so we dont pump longer than n seconds,...
            if (stop_time <= now)
                stop_Pump(cfg);
            else pumping = true;

        }
    }
    if (!pumping && next_message_unix != 0 && !received_starting_message)
        sleep_UntilNextSend(next_message_unix);
}