Hi
I am making a project with an esp32 devkit and a W5500.
I am using number input on de web dashboard to change a variable in my code.
But it is not working.
I also want to use the terminal to see all things send to serial monitor.
And I want the current time from the esp32 to be visible in the web dashboard.
I want that everything is synced so that the current value from the variable is visible in the number input widget.
I curently have this as code but it is not working. The variables d’ont change when i change it in the web dashboard.
#define BLYNK_TEMPLATE_ID "Template ID"
#define BLYNK_TEMPLATE_NAME "Automatic Chicken Feeder"
#define BLYNK_AUTH_TOKEN "BLYNK auth token"
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <EthernetUdp.h>
#include <NTPClient.h>
#include <Wire.h>
#include <RTClib.h>
// --- PIN DEFINITIONS ---
const int W5500_CS = 5;
const int W5500_RST = 33;
const int buzzPin = 27;
const int relPin = 25;
// --- ALARM TIMES ---
int Hour = 8, Minute = 0, Second = 0;
int Hour2 = 13, Minute2 = 0, Second2 = 0;
int Hour3 = 18, Minute3 = 0, Second3 = 0;
int Count = 20;
// --- OBJECTEN ---
RTC_DS3231 rtc;
EthernetUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
// --- TIMING ---
unsigned long lastPrintTime = 0;
unsigned long lastNTPSync = 0;
unsigned long lastBlynkCheck = 0;
const unsigned long NTP_INTERVAL = 86400000UL;
// --- STATUS ---
bool alarmActive = false;
bool relayActive = false;
unsigned long relayStart = 0;
unsigned long lastToneTime = 0;
int toneStep = 0;
const int totalTones = 14;
// ============================================================
// BLYNK CALLBACKS
// ============================================================
BLYNK_CONNECTED() {
Serial.println("[Blynk] Verbonden! Instellingen ophalen...");
Blynk.syncAll();
}
BLYNK_WRITE(V1) { Hour = param.asInt(); Serial.printf("[Blynk] Update A1 Uur: %d\n", Hour); }
BLYNK_WRITE(V2) { Hour2 = param.asInt(); Serial.printf("[Blynk] Update A2 Uur: %d\n", Hour2); }
BLYNK_WRITE(V3) { Hour3 = param.asInt(); Serial.printf("[Blynk] Update A3 Uur: %d\n", Hour3); }
BLYNK_WRITE(V4) { Minute = param.asInt(); Serial.printf("[Blynk] Update A1 Min: %d\n", Minute); }
BLYNK_WRITE(V5) { Minute2 = param.asInt(); Serial.printf("[Blynk] Update A2 Min: %d\n", Minute2); }
BLYNK_WRITE(V6) { Minute3 = param.asInt(); Serial.printf("[Blynk] Update A3 Min: %d\n", Minute3); }
BLYNK_WRITE(V7) { Second = param.asInt(); Serial.printf("[Blynk] Update A1 Sec: %d\n", Second); }
BLYNK_WRITE(V8) { Second2 = param.asInt(); Serial.printf("[Blynk] Update A2 Sec: %d\n", Second2); }
BLYNK_WRITE(V9) { Second3 = param.asInt(); Serial.printf("[Blynk] Update A3 Sec: %d\n", Second3); }
BLYNK_WRITE(V10) { Count = param.asInt(); Serial.printf("[Blynk] Update Voerduur: %d sec\n", Count); }
BLYNK_WRITE(V12) {
if (param.asInt() == 1 && !relayActive) {
Serial.println("[Blynk] Handmatige actie gestart!");
startAlarm();
}
}
// ============================================================
// LOGICA
// ============================================================
void startAlarm() {
alarmActive = true;
relayActive = true;
toneStep = 0;
relayStart = millis();
digitalWrite(relPin, HIGH);
if(Blynk.connected()) Blynk.logEvent("feeding", "Kippen krijgen eten!");
}
void stopAlarm() {
digitalWrite(relPin, LOW);
noTone(buzzPin);
relayActive = false;
alarmActive = false;
Serial.println("[Alarm] Voeren voltooid.");
}
void setup() {
Serial.begin(115200);
pinMode(buzzPin, OUTPUT);
pinMode(relPin, OUTPUT);
digitalWrite(relPin, LOW);
pinMode(W5500_RST, OUTPUT);
digitalWrite(W5500_RST, LOW);
delay(100);
digitalWrite(W5500_RST, HIGH);
delay(500);
Wire.begin(21, 22);
if (!rtc.begin()) Serial.println("Fout: RTC niet gevonden!");
Ethernet.init(W5500_CS);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Serial.println("Verbinden met netwerk...");
if (Ethernet.begin(mac) != 0) {
Blynk.config(BLYNK_AUTH_TOKEN);
Blynk.connect();
timeClient.begin();
} else {
Serial.println("Ethernet mislukt. Werkt offline.");
}
}
void loop() {
if (Blynk.connected()) {
Blynk.run();
} else if (millis() - lastBlynkCheck > 10000) {
Blynk.connect();
lastBlynkCheck = millis();
}
DateTime now = rtc.now();
unsigned long currentMillis = millis();
// Elke seconde status naar Serial (Nu inclusief duur!)
if (currentMillis - lastPrintTime >= 1000) {
lastPrintTime = currentMillis;
char t[10];
sprintf(t, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
if (Blynk.connected()) Blynk.virtualWrite(V11, t);
// Hier zie je nu de duur (Count) in je monitor staan
Serial.printf("Tijd: %s | A1: %02d:%02d | A2: %02d:%02d | A3: %02d:%02d | DUUR: %ds\n",
t, Hour, Minute, Hour2, Minute2, Hour3, Minute3, Count);
}
// Alarm Check
if (!relayActive) {
bool match = (now.hour() == Hour && now.minute() == Minute && now.second() == Second) ||
(now.hour() == Hour2 && now.minute() == Minute2 && now.second() == Second2) ||
(now.hour() == Hour3 && now.minute() == Minute3 && now.second() == Second3);
if (match) {
Serial.println("[Alarm] Automatische voertijd bereikt!");
startAlarm();
}
}
// Buzzer
if (alarmActive && toneStep < totalTones) {
if (currentMillis - lastToneTime >= 500) {
lastToneTime = currentMillis;
if (toneStep % 2 == 0) tone(buzzPin, 523); else noTone(buzzPin);
toneStep++;
}
}
// Relay Timer
if (relayActive && (currentMillis - relayStart >= (unsigned long)Count * 1000)) {
stopAlarm();
}
}
´´´
Sorry if my english is'nt good. It is not my main language
Thanks in advance
Noamopilo