1- when program is downloaded , servo is opening and closing , the same with LEDs.
2- when resButton = 1 ;
it does not call sendtoemail
function. could you notice something wrong ?!
3 - I changed timers to clocks counter until I know how to avoid running timers after downlaoding the code.
4- Blynk.email(Email.c_str() , "YOUR CODE" , randNumber );
it didn’t send any email , even when I do examples .
#include <Servo.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SoftwareSerial.h>
char auth[] = "553f8416608c43a78daecd8efc6b8765";
char ssid[] = "...";
char pass[] = "...";
String Email ;
String vcode ;
String randNumber;
int detect1 = D0; // sensor 1 in nodemcu
int detect2 = D1; // sensor 2
int detect3 = D2; // sensor 3
int LED1ava = D3; // LED PARK 1 Availble
int LED2ava = D4; // LED PARK 2 Availble
int LED3res = D5; // LED PARK 3 reserving
int servo = D6; // Gate
int result1 = 0;
int result2 = 0;
int result3 = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int Clock1 = 1;
int Clock2 = 1;
int Clock3 = 1;
int resButton = 0;
int callcode1 = 0;
int callcode2 = 0;
Servo myservo;
//SimpleTimer timer;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
Blynk.virtualWrite(V2, 1 );
Blynk.virtualWrite(V4, 1 );
Blynk.virtualWrite(V7, 1 );
Blynk.virtualWrite(V17, 0 );
pinMode (detect1 , INPUT );
pinMode (detect2 , INPUT );
pinMode (detect3 , INPUT );
pinMode (LED1ava , OUTPUT );
pinMode (LED2ava , OUTPUT );
pinMode (LED3res , OUTPUT );
myservo.attach(D6);
Blynk.email(Email.c_str() , "YOUR CODE" , randNumber );
/*timer.setTimer(1000L, sendtoemail , 30 );
timer.setTimer(1000L, vercode, 60 );
timer.setTimer(1000L, gatelock , 60 );
timer.setTimeout(80000L, refresh );*/
}
void loop()
{
Blynk.run();
if ( resButton == 1 ) // calling email function
{
sendtoemail ;
}else if ( resButton == 2 ){} // do nothing after taking an email to strat calling next function
else if ( resButton == 3){
Blynk.virtualWrite(V17 , 1 ); // keep switch ON
}else if ( resButton == 0 ){
refresh;
}
result1 = digitalRead (detect1); // 0 means busy .... 1 means Available
result2 = digitalRead (detect2);
result3 = digitalRead (detect3);
if ( result1 == LOW )
{
Serial.println("PARK 1 BUSY");
Blynk.virtualWrite(V2 , 0 );
digitalWrite ( LED1ava , LOW );
} else {
Serial.println("PARK 1 Available");
Blynk.virtualWrite(V2, 255 );
digitalWrite ( LED1ava , HIGH );
}
if ( result2 == LOW )
{
Serial.println("PARK 2 BUSY");
Blynk.virtualWrite(V4 , 0 );
digitalWrite ( LED2ava , LOW );
} else {
Serial.println("PARK 2 Available");
Blynk.virtualWrite(V4, 255);
digitalWrite ( LED2ava , HIGH );
}
if ( result3 == LOW )
{
Serial.println("PARK 3 BUSY");
Blynk.virtualWrite(V7 , 0 );
digitalWrite ( LED3res , LOW );
} else {
Serial.println("PARK 3 Available");
Blynk.virtualWrite(V7, 255);
}
if ( callcode1 == 1 )
{
vercode ;
}else{}
if ( callcode2 == 1 )
{
gatelock;
}else{}
Serial.println(".............................");
delay(1000);
//timer.run();
}
void sendtoemail ()
{
Blynk.virtualWrite(V17 , 1 ); // keep switch ON
Serial.print(" Park 3 reserved at : ");
Serial.print(Clock1); // * tracking the counter on Serial Monitor *
Serial.print(" sec");
Clock1 ++;
Serial.println();
Serial.println("Email in function is :"); // while the counter is running I'd like to see the Email
Serial.println(Email);
if ( Email == "" )
{}
else
{
Blynk.email(Email.c_str() , "YOUR CODE" , randNumber );
Clock1 = 0;
resButton = 2; // do nothing
callcode1 = 1; // start calling next function
}
if ( Clock1 >= 30 )
{
Clock1 = 0;
resButton = 0 ;
}
}
void vercode ()
{
Clock2 ++;
Serial.print ( " Waiting your code , " );
Serial.print (Clock2);
Serial.print ( "sec" );
if ( Clock2 <= 60 )
{
if ( vcode == randNumber )
{
digitalWrite ( LED3res , HIGH );
vcode = ""; // delete vcode that user entered on app
callcode1 = 0; // void loop will stop calling this function
callcode2 = 1 ; // start tracking second verification to open the servo
resButton = 3; // keep switch ON
}
} else
{
Clock2 = 0;
callcode1 = 0;
resButton = 0; // call refresh
}
}
void gatelock ()
{
Serial.print ( " Gate is waiting you : " );
Serial.print (Clock3);
Serial.print ( "sec" );
Clock3 ++ ;
if ( Clock3 <= 60 )
{
if ( vcode == randNumber )
{
myservo.write(80);
delay (2000);
myservo.write(160);
callcode2 = 0 ; // stop calling this function
delay (3000);
resButton = 0;
}
}else {
Clock3 = 0;
callcode2 = 0;
resButton = 0;
}
}
void refresh ()
{
Serial.print ( " ( Time is up ) " );
vcode = "";
Email = "";
digitalWrite ( LED3res , LOW );
Blynk.virtualWrite(V17 , 0 );
}
BLYNK_WRITE(V6)
{
Email = param.asStr();
}
BLYNK_WRITE(V8){
vcode = param.asStr();
Serial.print(" verification code from Blynk is : " );
Serial.print( vcode );
}
BLYNK_WRITE(V17){
int pinValue = param.asInt();
if ( pinValue == 1 ){
int resButton = 1;
String Email = "" ;
String vcode = "" ;
randNumber = random(1000,3000);
Serial.println(" Verification Code is : ");
Serial.print (randNumber);
Serial.println();
// timer.setTimer(1000L, sendtoemail , 30 );
}
}
BLYNK_WRITE(V15){
int ser = param.asInt();
if ( ser == 1 )
{
myservo.write(80);
}
else {
myservo.write(160);
}
}