hello
i am trying to send data in a mail using arduino uno wifi rev2, i tried this program but it doesn't work.
the arduino is already connected to the wifi.
could you check the following program and tell me what i have to change or any suggestions ?
thanks.
#include <WiFiNINA.h>
#include <SPI.h>
const int touch1 = 2; // touch sensor 1 is connected to pin number 2.
const int touch2 = 4; // touch sensor 2 is connected to pin number 4.
const int touch3 = 5; // touch sensor 3 is connected to pin number 5.
const int touch4 = 8; // touch sensor 4 is connected to pin number 8.
const int BUZZ = 9; // BUZZER is connected to pin number 9.
int A , B , C , D = 0;
const char net [] = "xxxxxxxxxx"; // name of the router
const char pass [] = "xxxxxxxxxx"; // wifi passwoard
int status = WL_IDLE_STATUS; // function that detect if the arduino is connected or disconnected
WiFiSSLClient wifi; // create wifi in wificlient class
IPAddress ip(192, 168, 43, 215); // give ip adress to arduino
char from [] = "arduinounowifirev2@yahoo.com"; // email of sender
char password [] = "xxxxxxxxxxx"; // email password
char to [] = "xxxxxxxxxxxxxx@xxxxxxx.com";
char sub [] = "Results";
String from_base64 = ("xxxxxxxxxxxxxxxxxxxxx"); // email of sender in base64
String password_base64 = ("xxxxxxxxxxxxxxx"); // email password in base64
const String host [] = "pop.mail.yahoo.com";
const String port [] = "995";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode ( touch1 , INPUT ); // set pin 2 as input.
pinMode ( touch2 , INPUT ); // set pin 4 as input.
pinMode ( touch3 , INPUT ); // set pin 5 as input.
pinMode ( touch4 , INPUT ); // set pin 8 as input.
pinMode ( BUZZ , OUTPUT ); // set pin 9 as output.
status = WiFi.begin( net , pass ); // start the wifi and give the wifi name and password
while( status != WL_CONNECTED ) // wait till the arduino is connected to the wifi
{
status = WiFi.begin ( net , pass );
}
Serial.println( "Connected to wifi" );
wifi.connect ( host , port );
if (wifi.connect(host, port)) {
Serial.println ( " access to server " );
wifi.println("EHLO kltan");
wifi.println(F("250"));
wifi.println("AUTH LOGIN");
wifi.println(F("334 YXJkdWlub3Vub3dpZmlyZXYyQGhvdG1haWwuY29t"));
wifi.println (from_base64);
wifi.println(F("334 bWhhbWFkMTIz"));
wifi.println ( password_base64 );
wifi.println ( F ("235"));
char mailfrom [20] = "MAIL FROM:<";
strcat ( mailfrom , from );
strcat ( mailfrom , ">" );
wifi.println ( mailfrom );
wifi.println (F ("250"));
char mailto [20] = "RCPT TO:<";
strcat ( mailto , to );
strcat ( mailto , ">" );
wifi.println ( mailto );
wifi.println ( F ("250"));
wifi.println ( "DATA" );
wifi.println ( F ("354"));
char efrom [50] = "FROM: ";
strcat ( efrom , from );
strcat ( efrom , " " );
strcat ( efrom , "<" );
strcat ( efrom , from );
strcat ( efrom , ">" );
wifi.println ( efrom );
char eto [50] = "TO: ";
strcat ( eto , to );
strcat ( eto , " " );
strcat ( eto , "<" );
strcat ( eto , to );
strcat ( eto , ">" );
wifi.println ( eto );
char subject [50] = "SUBJECT: ";
strcat ( subject , sub );
wifi.println ( subject );
wifi.println ( "\r\n" );
wifi.println ("welcome to Arduino, we will count the results and send them each 5 min. ");
wifi.println ( "\r\n" );
wifi.println ( "QUIT" );
}else{
Serial.println ( " couldn't access to server " );
}
printWiFiStatus();
Serial.println ( " welcome to Arduino, we will count the results and send them each 5 min. " );
Serial.println ( "_________________________________________________________________________________ " );
}
void loop() {
// put your main code here, to run repeatedly:
int e , f , g , h , i = 0 ;
int vtouch1 = digitalRead ( touch1 );
int vtouch2 = digitalRead ( touch2 );
int vtouch3 = digitalRead ( touch3 );
int vtouch4 = digitalRead ( touch4 );
for ( i = 0 ; i < 300000 ; i++ )
{
delay ( 1 );
if ( vtouch1 == 1 ) // if the touch sensor that correspond to trop bien is touched increase the result of trop bien and start the buzzer for 0.2s in a frecuency of 1000 HZ.
{
e++;
tone ( BUZZ , 1000 );
delay ( 200 );
noTone ( BUZZ );
A = A + e ; // e is the result of trop bien for 5 min. we added to A that is the result of trop bien for all time.
}
else if ( vtouch2 == 1 ) // if the touch sensor that correspond to bien is touched increase the result of trop bien and start the buzzer for 0.2s in a frecuency of 1000 HZ.
{
f++;
tone ( BUZZ , 1000 );
delay ( 200 );
noTone ( BUZZ );
B = B + f ; // f is the result of bien for 5 min. we added to B that is the result of bien for all time.
}
else if ( vtouch3 == 1 ) // if the touch sensor that correspond to mal is touched increase the result of trop bien and start the buzzer for 0.2s in a frecuency of 1000 HZ.
{
g++;
tone ( BUZZ , 1000 );
delay ( 200 );
noTone ( BUZZ );
C = C + g ; // g is the result of mal for 5 min. we added to C that is the result of mal for all time.
}
else if ( vtouch4 == 1 ) // if the touch sensor that correspond to trop mal is touched increase the result of trop bien and start the buzzer for 0.2s in a frecuency of 1000 HZ.
{
h++;
tone ( BUZZ , 1000 );
delay ( 200 );
noTone ( BUZZ );
D = D + h ; // h is the result of trop mal for 5 min. we added to D that is the result of trop mal for all time.
}
}
String m5 = " the result of the 5 min is : " ;
String mt = " the result of all time is : " ;
String tb = " trop bien , " ;
String b = " bien , " ;
String m = " mal et " ;
String TM = " trop mal." ;
String R5 = m5 + e + tb + f + b + g + m + h + TM ;
String RT = mt + A + tb + B + b + C + m + D + TM ;
Serial.println ( R5 );
Serial.println ( RT );
Serial.println ( "_________________________________________________________________________________ " );
}
void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}