Hi,
i tried to build a device who is measuring a battery of a camping vehicle and send a whatsapp message if the battery is undervolting. The measuring is still working and the case of transmitting status is given but no message is sended. I dont know why...
What is my Goal:
I build a sketch who measure a voltage on PIN 0 who comes from a voltage divider. if it less then 3V the a whatsapp go sending. In the case that the device not still working or have an issue once a week an another message will be send with a lifesign. so far so good but it doesnt works.
Here is the Sketch:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
// WiFi-Einstellungen
const char* ssid = "this is my SSID";
const char* password = "my Pssword";
// CallMeBot-API-Einstellungen
const char* callMeBotNumber = "4912345678";
const char* callMeBotToken = "12345678";
// ADC-Pin-Einstellungen
const int adcPin = A0;
const float vref = 3.3;
const float voltageDividerRatio = 2.0;
// Statusüberprüfung
const unsigned long checkInterval = 86400000; // 1 Tag in Millisekunden
unsigned long lastCheckTime = 0;
// Spannungsüberprüfung
const float voltageThreshold = 3.0;
bool voltageAlertSent = false;
void setup() {
Serial.begin(115200);
// WiFi-Verbindung herstellen
WiFi.begin(ssid, password);
Serial.print("Verbindung zum WiFi-Netzwerk wird hergestellt");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi-Verbindung hergestellt");
lastCheckTime = millis();
}
void loop() {
// Spannung messen
int adcValue = analogRead(adcPin);
float voltage = (adcValue * vref / 1024.0) / voltageDividerRatio;
Serial.print("Gemessene Spannung: ");
Serial.print(voltage);
Serial.println("V");
// Messwerte an CallMeBot-API senden
if (voltage < voltageThreshold && !voltageAlertSent) {
WiFiClient client;
HTTPClient http;
Serial.println("Sende Spannung");
String url = "https://api.callmebot.com/whatsapp.php?phone=" + String(callMeBotNumber) + "&text=Batterie%20leer&apikey=" + String(callMeBotToken);
http.begin(client, url);
int httpResponseCode = http.GET();
http.end();
Serial.println("Spannung gesendet");
Serial.println (url);
voltageAlertSent = true;
}
// Statusüberprüfung durchführen
if (millis() - lastCheckTime > checkInterval) {
Serial.println("System läuft noch");
WiFiClient client;
HTTPClient http;
String url = "https://api.callmebot.com/whatsapp.php?phone=" + String(callMeBotNumber) + "&text=System%20läuft%20noch&apikey=" + String(callMeBotToken);
http.begin(client, url);
int httpResponseCode = http.GET();
http.end();
lastCheckTime = millis();
voltageAlertSent = false;
}
delay(1000);
}
Can someone help my ?