NEW AND UPDATED CODE DOWN IN THE SECOND POST!!!
KINDLY CHECK TO AVOID CONFUSION!
WARNING! THIS IS THE OLD POST
So I watched this "meant-to-be-easy video" by educ8ts.tv:
Arduino ESP8266 Tutorial: Send an email easily with your Wemos D1 board using a PHP script! - YouTube
Knowing that DHT.h was used to read the inputs from the temp and humidity sensor, how does one do the code to read the input with a different sensor? I think my code is okay but it does not send anything on my email whatsoever. I used a PHP script like in the video but for the web-server I used smtp2go.com because I still would like to test if it works. On my behalf, I have a vibration switch sensor plugged into WEMOS d1 mini and I would like to have ANY sort of input from the sensor(or even a certain buffer) read be sent by email.
Any sort of help would be appreciated. Thank you!
Also another question, am I meant to set-up anything else in smtp2.go.com apart from the account creation? On their website, it says "SMTP Server: mail.smtp2go.com" under "Connecting via SMTP". Because according to my serial monitor, I managed to connect in my address but it fails to connect in the SMTP server:
[/u][/b]
eir..
Connected
connected
220 mail.smtp2go.com ESMTP Exim 4.87 Mon, 17 Apr 2017 19:56:55 +0000
500 unrecognized command
500 unrecognized command
500 unrecognized command
500 Too many unrecognized commands
ÿ
ARDUINO CODE
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
const char* ssid = "eir"; // SSID of local network
const char* password = ""; // Password on network
int sensorPin = A0; // select the input pin for the vibration sensor
int motion = 0; // variable to store the value coming from the sensor
WiFiClient client;
char servername[] = "mail.smtp2go.com"; // remote server we will connect to
String result;
void setup() {
delay(2000);
Serial.begin(9600);
Serial.println("Connecting");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
Serial.println("Connected");
delay(1000);
// read the value from the sensor:
motion = analogRead(sensorPin);
String motionString = String(motion, 1);
sendDataToServer(motionString);
}
void loop() {
}
void sendDataToServer(String motion)
{
if (client.connect(servername, 80)) { //starts client connection, checks for connection
Serial.println("connected");
client.println("GET /send_email.php?motion=" + motion + " HTTP/1.1"); //Send data
client.println("Host: OralBear.com");
client.println("Connection: close"); //close 1.1 persistent connection
client.println(); //end of get request
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
while (client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
result = result + c;
}
client.stop(); //stop client
Serial.println(result);
}
PHP SCRIPT
<?php
$motion = $_GET["motion"];
$text ="Toothbrush has been recently activated! Motion: {$motion} ";
$admin_email = "...@gmail.com";
$email = "...@gmail.com";
$subject ="Toothbrush Report";
//send email
mail($admin_email,"$subject",$text,"From:" .$email);
?>