lekkage melder

Hardware geleverd door Arduino
Berichten: 2
Geregistreerd: 15 Apr 2018, 13:33

lekkage melder

Berichtdoor RobDraak » 15 Apr 2018, 15:32

Beste Forum,
Ik wil een stukje code toevoegen (#include "sendemail.h"), maar ik weet niet waar ik het moet plaatsen.
Als ik alles invul (parameters) en de code er tussen stop krijg ik een melding van een fout bij het compileren,exit status 1
Waar moet ik het zetten??



De bestaande code:

// Project 6: Lekkagemelder
#include <ESP8266WiFi.h>
#include "sendemail.h"

const char* ssid = "SSID";
const char* password = "WACHTWOORD";
const int puls = 5; // D1
const int sensor = 0; // A0
const int grenswaarde = 100; // Boven deze meetwaarde is het te nat.
const int wachttijd = 1000; // 1 seconde

const String server_host = "SMTP-SERVER";
const int server_port = 25;
const String server_login = "";
const String server_password = "";
const int server_timeout = 5000;
const bool server_ssl = false;

SendEmail email(server_host, server_port, server_login, server_password, server_timeout, server_ssl);

const String mail_from = "MAIL_VAN";
const String mail_to = "MAIL_NAAR";
const String mail_subject = "Lek!";
const String mail_message = "Lek gedetecteerd";

bool lek;

void setup() {
Serial.begin(115200);

pinMode(puls, OUTPUT);
digitalWrite(puls, LOW);
lek = false;

// Verbind met WiFi-netwerk
Serial.println();
Serial.println();
Serial.print("Verbind met ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi verbonden");
Serial.print("IP-adres: ");
Serial.println(WiFi.localIP());
}

void loop() {

digitalWrite(puls, HIGH);
int meting = analogRead(sensor);
digitalWrite(puls, LOW);
Serial.println(meting);

if(meting >= grenswaarde && !lek) {
lek = true;
if(!email.send(mail_from, mail_to, mail_subject, mail_message))
Serial.println("Fout bij verzenden e-mail");
}

delay(wachttijd);

}
-------------------------------------------------------------------------------------------------------------------

De nieuwe code bestaat uit 2 bestanden. ( te vinden op https://github.com/gpepe/esp8266-sendem ... master/src

#include "sendemail.h"

uitgepakt 2x bestand:

SendEmail::SendEmail(const String& host, const int port, const String& user, const String& passwd, const int timeout, const bool ssl) :
host(host), port(port), user(user), passwd(passwd), timeout(timeout), ssl(ssl), client((ssl) ? new WiFiClientSecure() : new WiFiClient())
{

}

String SendEmail::readClient()
{
String r = client->readStringUntil('\n');
r.trim();
while (client->available()) r += client->readString();
return r;
}

bool SendEmail::send(const String& from, const String& to, const String& subject, const String& msg)
{
if (!host.length())
{
return false;
}
client->stop();
client->setTimeout(timeout);
// smtp connect
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.print("Connecting: ");
DEBUG_EMAIL_PORT.print(host);
DEBUG_EMAIL_PORT.print(":");
DEBUG_EMAIL_PORT.println(port);
#endif
if (!client->connect(host.c_str(), port))
{
return false;
}
String buffer = readClient();
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
if (!buffer.startsWith(F("220")))
{
return false;
}
buffer = F("EHLO ");
buffer += client->localIP();
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = readClient();
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
if (!buffer.startsWith(F("250")))
{
return false;
}
if (user.length()>0 && passwd.length()>0 )
{
buffer = F("AUTH LOGIN");
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = readClient();
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
if (!buffer.startsWith(F("334")))
{
return false;
}
base64 b;
buffer = user;
buffer = b.encode(buffer);
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = readClient();
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
if (!buffer.startsWith(F("334")))
{
return false;
}
buffer = this->passwd;
buffer = b.encode(buffer);
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = readClient();
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
if (!buffer.startsWith(F("235")))
{
return false;
}
}
// smtp send mail
buffer = F("MAIL FROM: ");
buffer += from;
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = readClient();
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
if (!buffer.startsWith(F("250")))
{
return false;
}
buffer = F("RCPT TO: ");
buffer += to;
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = readClient();
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
if (!buffer.startsWith(F("250")))
{
return false;
}
buffer = F("DATA");
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = readClient();
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
if (!buffer.startsWith(F("354")))
{
return false;
}
buffer = F("From: ");
buffer += from;
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = F("To: ");
buffer += to;
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = F("Subject: ");
buffer += subject;
buffer += F("\r\n");
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = msg;
client->println(buffer);
client->println('.');
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
buffer = F("QUIT");
client->println(buffer);
#ifdef DEBUG_EMAIL_PORT
DEBUG_EMAIL_PORT.println(buffer);
#endif
return true;
}


#ifndef __SENDEMAIL_H
#define __SENDEMAIL_H

//#define DEBUG_EMAIL_PORT

#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <base64.h>

class SendEmail
{
private:
const String host;
const int port;
const String user;
const String passwd;
const int timeout;
const bool ssl;
WiFiClient* client;
String readClient();
public:
SendEmail(const String& host, const int port, const String& user, const String& passwd, const int timeout, const bool ssl);
bool send(const String& from, const String& to, const String& subject, const String& msg);
~SendEmail() {client->stop(); delete client;}
};

#endif

Advertisement

Berichten: 2381
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: lekkage melder

Berichtdoor shooter » 16 Apr 2018, 22:37

verbose aanzetten en een beetje omhoog scrollen dan staat daar in de compiler uitvoer wat er fout is.

En vooral stukje voor stukje controleren, er niet vanuit gaan dat ale software correct is, en zeker niet met al die vrschillende versies
paul deelen
shooter@home.nl

Berichten: 2
Geregistreerd: 15 Apr 2018, 13:33

Re: lekkage melder

Berichtdoor RobDraak » 22 Apr 2018, 20:57

Bedankt Paul!

Terug naar Arduino hardware

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 1 gast