Hello, my sketch has a lot of other information in it and is mostly in german but I’ll post it if ist more helpful.
Yes I have the Widget and I get it working in my other function. The only thing I need is: I just want it to post the time as first thing when it goes online.
For better understanding, my Project is a laser tripwire which sends notification and Information to the phone and Needs a Passwort in the terminall to deactivate.
I already implemented the rtc function for my Alarm message in the terminal. I just have a Problem as I am not able to send the time when the Project goes online. Why do I Need this? - The terminal clears when the Sketch connects but sometimes when I have booting Errors for example there is still the message from earlier in the terminal and I thought it to be useful if it sends the time as it goes online to Show me as a user when this was send.
However, here is the full Sketch (which is working well):
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
char auth[] =
char ssid[] =
char pass[] =
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(11, 12); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 19200
ESP8266 wifi(&EspSerial);
WidgetTerminal terminal(V2);
BlynkTimer timer;
WidgetRTC rtc;
//Konstanten
const int redled = 3; //Pin für rote LED
const int greenled = 4; //Pin für grüne LED
const int ldrdigital = 10; //Alternativ das Modul digital auslesen
const int speaker = 5; //Pin für akkustischen Alarm
const int armbutton = 6; //Pin für An- und Ausschalten des Systems
const int armbutton2 = 8; //analog
const int gelbled = 7; //Pin für gelbe LED
//Variablen
boolean aktiv = true; // Variable für Aktivierung
boolean alarm = false; // Variable für Alarm
int buttonVal = 0; // Variable um Buttonzustand festzustellen
int prev_buttonVal = 0; // Variable um Buttonzustand zu vergleichen
int buttonVal2 = 0; // Analog
int prev_buttonVal2 = 0;
// Konstanten für Sirene
const int lowrange = 2000; // niedrigste Frequenz
const int highrange = 4000; // höchste
//Flags //Vermeiden von loop für Benachrichtigungen und Terminal
int flagAlarm = 0;
int flagAktiv = 0;
//Strings
String password = "cool";
void setup()
{
//Bestimmen der Output und Input Pins
pinMode(redled,OUTPUT);
pinMode(greenled,OUTPUT);
pinMode(gelbled, OUTPUT);
pinMode(speaker,OUTPUT);
pinMode(ldrdigital, INPUT);
pinMode(armbutton, INPUT);
timer.setInterval(1000L, data); //timer will run every sec
Serial.begin(19200);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
rtc.begin();
Aktivieren ();
}
void loop()
{
Blynk.run();
timer.run();
}
void data()
{
String currentTime = String(hour()) + ":" + minute() + ":" + second();
int buttonVal = digitalRead(armbutton); //liest Button aus und vergleicht
if ((buttonVal == HIGH) && (prev_buttonVal == LOW)){
Aktivieren(); //Wenn Bedingung erfüllt wird das System ativiert
if (flagAktiv == 0){
terminal.println(F("Sie haben das System aktiviert!"));
terminal.flush();
flagAktiv = 1;
}
delay(50);
}
int digitalValue = digitalRead(ldrdigital); //liest den Wert des LDR Moduls aus
if ((aktiv) && (digitalValue == HIGH)){ //vergleicht ausgelesenen Wert mit Grenzwert
alarm = true;
}
if (alarm){
if (flagAlarm == 0){
Blynk.notify("Der Alarm wurde ausgelöst!");
terminal.print(F("Der Alarm wurde um "));
terminal.print (currentTime);
terminal.println (F(" ausgelöst."));
terminal.println(F("Geben Sie Ihr Passwort ein, um den Alarm auszuschalten!"));
terminal.flush();
flagAlarm = 1;
}
// Sirene
// steigender Ton
for (int i = lowrange; i <= highrange; i++)
{
tone (speaker, i, 250);
}
// sinkender Ton
for (int i = highrange; i >= lowrange; i--)
{
tone (speaker, i, 250);
}
// optischer Alarm bzw. blinken
digitalWrite(gelbled, HIGH);
digitalWrite(redled, HIGH);
digitalWrite(greenled, HIGH);
delay(10);
digitalWrite(greenled, LOW);
digitalWrite(gelbled, LOW);
digitalWrite(redled, LOW);
}
delay(20);
// Funktion aktiviert das System
void Aktivieren(){
if (aktiv){
digitalWrite(greenled, LOW);
digitalWrite(redled, HIGH);
alarm = false;
aktiv = false;
} else {
digitalWrite(greenled, HIGH);
digitalWrite(redled, LOW);
tone(speaker, 220, 125);
delay(200);
tone(speaker, 196, 250);
aktiv = true;
}
}
//Verbindung mit Blynk
BLYNK_CONNECTED() {
Blynk.syncAll();
terminal.clear();
terminal.println(F("Blynk v" BLYNK_VERSION ": Sie sind jetzt online."));
terminal.println("-------------");
terminal.flush();
}
//Passwortschutz Terminal Blynk
BLYNK_WRITE(V2)
{
if (alarm) {
if (String (password) == param.asStr()){
//deactivate alarm
aktiv = false;
alarm = false;
flagAlarm = 0;
flagAktiv = 0;
digitalWrite(greenled, LOW);
digitalWrite(redled, HIGH);
tone(speaker, 196, 250);
delay(200);
tone(speaker, 220, 125);
terminal.println(F("Korrekt! Alarm deaktiviert."));
terminal.flush();
}
else {
terminal.println(F("Falsches Passwort!"));
terminal.flush();
}
}
}
´´´