Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <ESP8266WiFi.h>
- #include <ESP_Mail_Client.h>
- /*
- * Werte sollten nicht geändert werden.
- */
- #define TRIGGER_PIN 16
- #define ECHO_PIN 5
- #define SENSOR_OFFSET 1
- typedef enum enumWLAN_STATUS_CODES
- {
- WLAN_IDLE_STATUS,
- WLAN_NO_SSID_AVAILABLE,
- WLAN_SCAN_COMPLETED,
- WLAN_CONNECTED,
- WLAN_CONNECT_FAILD,
- WLAN_CONNECTION_LOST,
- WLAN_DISCONNECTED,
- };
- /*
- * W-LAN Konfiguration
- */
- #ifndef STASSID
- #define STASSID "TEST"
- #define STAPSK "*****"
- #endif
- /*
- * E-Mail Server Konfiguration
- */
- #define SMTP_HOST " smtp.mail.yahoo.com"
- #define SMTP_PORT esp_mail_smtp_port_587
- #define AUTHOR_EMAIL "*******"
- #define AUTHOR_PASSWORD "wassolldasdenn"
- /*
- * Diese Werte müssen an den entsprechenden Tank angepasst werden..
- * -> HEIGHT_TANK:= Höhe des Tankes
- * -> DEVIATION:= Höhe von Füllinhalt max. bis zu dem Sensor..
- */
- #define HEIGHT_TANK 20
- #define DEVIATION 7
- #define GET_PERCENT(VALUE) ( 100 - ( ( ( VALUE-DEVIATION ) * 100 ) / HEIGHT_TANK ))
- SMTPSession smtp;
- void smtpCallback(SMTP_Status status);
- void setup()
- {
- Serial.begin(9600);
- delay( 500 );
- Serial.println( "W-LAN Netzwerk(e) in der Naehe werden gesucht.." );
- uint8_t uiWIFIn = WiFi.scanNetworks();
- Serial.print( "W-LAN Status: " );
- Serial.println( WiFi.status() );
- Serial.print( "Es wurde(n) " );
- Serial.print( uiWIFIn );
- Serial.println( " W-LAN Netzwerk(e) in der Naehe gefunden!." );
- Serial.println( "" );
- Serial.println("Verbindung zum W-LAN herstellen..");
- WiFi.begin( STASSID, STAPSK );
- while( WiFi.status() != WL_CONNECTED )
- {
- delay(1000);
- Serial.print( "." );
- }
- Serial.println( "" );
- Serial.print( "W-LAN Status: " );
- Serial.println( WiFi.status() );
- Serial.println( "" );
- Serial.println( "W-LAN verbunden!." );
- Serial.print( "IP Addresse: " );
- Serial.println( WiFi.localIP() );
- Serial.println( "" );
- //Debug Meldungen anzeigen
- smtp.debug(1);
- //Ein Callback definieren welcher nach dem Senden der Mail ausgeführt werden soll.
- smtp.callback(smtpCallback);
- //Mail Session
- ESP_Mail_Session session;
- //Serverdaten setzen
- session.server.host_name = SMTP_HOST;
- session.server.port = SMTP_PORT;
- session.login.email = AUTHOR_EMAIL;
- session.login.password = AUTHOR_PASSWORD;
- session.login.user_domain = "smtp.gmail.com";
- //Wenn keine Verbindung aufgebaut werden konnte soll die Funktion verlassen werden.
- if (!smtp.connect(&session))
- {
- return;
- }
- pinMode(TRIGGER_PIN, OUTPUT);
- pinMode(ECHO_PIN, INPUT);
- }
- void loop()
- {
- Serial.println ( "********************************" );
- long lDistance = GetDistance();
- Serial.print( "Distanz: " );
- Serial.println( lDistance );
- Serial.print( "Füllstand in %: " );
- Serial.println( GET_PERCENT( lDistance ) );
- Serial.print( "W-LAN Status: " );
- Serial.println( WiFi.status() );
- Serial.println ( "********************************" );
- delay(1500);
- }
- long GetDistance()
- {
- long lDistance = 0;
- long lLength = 0;
- digitalWrite(TRIGGER_PIN, LOW);
- delay(5);
- digitalWrite(TRIGGER_PIN, HIGH);
- delay(10);
- digitalWrite(TRIGGER_PIN, LOW);
- lLength = pulseIn(ECHO_PIN, HIGH);
- lDistance = ( lLength / 2 ) * 0.03432;
- return ( lDistance - SENSOR_OFFSET );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement