mobizt/Firebase-ESP-Client

WARN.mRunUntil: Terminating because the ssl engine closed.

manariamantion opened this issue · 6 comments

WARN.mRunUntil: Terminating because the ssl engine closed.

WARN.mRunUntil: Terminating because the ssl engine closed.
ERROR.write: Failed while waiting for the engine to enter BR_SSL_SENDAPP.

my code is

//************** include library ***************
#include <Preferences.h> //for save state of pin in flash
#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
#include <NTPClient.h>
#include <Arduino.h>
#include <WiFi.h>
#include <Firebase_ESP_Client.h>
#include <WiFiUdp.h>
#include <Adafruit_GFX.h> //ssd lib
#include <Adafruit_SSD1306.h> //ssd lib
#include "addons/TokenHelper.h" //Provide the token generation process info.
#include "addons/RTDBHelper.h" //Provide the RTDB payload printing info and other helper functions.
#include <WiFiMulti.h>
//################# Variables #################
WiFiMulti wifiMulti;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
Preferences preferences;
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

FirebaseData fbdo; //2. Define FirebaseESP8266 data object for data sending and receiving
FirebaseAuth auth;
FirebaseConfig config;
bool signupOK = false;
//################# define #################
#define API_KEY "AIzaSyCRxMrKqA4p3WeqOQqpYX56-L1XsEihBiA" // Insert Firebase project API Key
#define DATABASE_URL "pum-phouse-remot-consol.firebaseio.com" // Insert RTDB URLefine the RTDB URL
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define wifi_led 2
#define motor 18
#define light 19
// #define motor2 13
#define modem_power_pin 14
#define ON 0
#define OFF 1
const uint32_t connectTimeoutMs = 15000;
int reconnect_time = 15000;
int last_try_time = 0;
int prog_day = 5, prog_month = 3, prog_year = 24;
int DAY, MONTH, YEAR, HH, MM, Sec, HHMM;
int TLON, TLOF, TMON1, TMOF1, TMON2, TMOF2; //TIMER LIGHT ON,OFF, MOTOR1 ON,OFF, MOTOR2 ON,OFF
int lightState1, motorState1, lightState2, motorState2;// 0 = manual, 1 = automatic, 1 = manual, 2 = auto
int input_code ; // input code value from FB
int MODE = 0;/* 0 = AUTO MODE, 1 = MANUAL WHEN WIFI TRUE*/
int RTC_SYNC = 0; // 0 = rtc not sync after setup, 1 = rtc sync after setup,
int UPDATEFLAGE;
//################### setup #################
void setup() { // put your setup code here, to run once:
config.api_key = API_KEY; // Assign the api key (required)
config.database_url = DATABASE_URL; // Assign the RTDB URL (required)
fbdo.setBSSLBufferSize(4096 /* Rx buffer size in bytes from 512 - 16384 /, 1024 / Tx buffer size in bytes from 512 - 16384 */);
PIN_SETUP();
Wire.begin();
Serial.begin(115200);
preferences.begin("my-app", false);
wifiMulti.addAP("r4jm3n4ri4", "r4jm3n4ri4");
wifiMulti.addAP("", "");
wifiMulti.addAP("JioFiber-amfda", "em3haichoo9xahPu");
DATA_INIT();
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); }
display.display(); delay(1000);
display.clearDisplay();
display.drawRect(0, 0, 128, 64, WHITE); display.display();
display.setCursor( 5, 25); display.print("Display found"); display.display(); delay(1000);
if (! rtc.begin()) { Serial.println("Couldn't find RTC"); Serial.flush(); while (1) delay(100); }
if (! rtc.isrunning()) { Serial.println("RTC is NOT running, let's set the time!"); }
Serial.println("SETUP DONE");
}
//################# main loop #################
void loop() { // put your main code here, to run repeatedly:
get_rtc_DATA();
update_display();
MODE ? setOutputsStates2() : setOutputsStates1(); // run by firebase : run by timer
(WiFi.status() == WL_CONNECTED) ? wifi_true() : wifi_false() ;
Serial.println(" ");
}
//################# functiont #################

void get_rtc_DATA() {
DateTime now = rtc.now();
DAY = now.day();
MONTH = now.month();
YEAR = now.year()-2000;
HH = now.hour();
MM = now.minute();
Sec = now.second();
HHMM = (HH*60) + MM;
Serial.print(HH); Serial.print(":"); Serial.print(MM); Serial.print(":");Serial.print(Sec); Serial.print(" ");
}

void update_display() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.drawRect(0, 0, 128, 64, WHITE);
display.drawLine(0, 15, 128, 15, WHITE);
display.drawLine(64, 0, 64, 15, WHITE);
display.setCursor(5, 4); display.print(DAY);
display.setCursor(28, 4); display.print(MONTH);
display.setCursor(50, 4); display.print(YEAR);
display.setCursor(71, 4); display.print(HH);
display.setCursor(84, 4); display.print(":");
display.setCursor(91, 4); display.print(MM);
display.setCursor(103, 4); display.print(":");
display.setCursor(109, 4); display.print(Sec);
display.setCursor(5, 20); display.print("wifi : ");
display.setCursor(45, 20);
(WiFi.status() == WL_CONNECTED) ? display.print("connected ") : display.print("not connected");
display.setCursor(10, 35); display.print(UPDATEFLAGE);
display.setCursor(25, 35); display.print(input_code);
display.display();
Serial.print("DISPLAY PRINT ");
}

void initWiFi() {
int current_millis = millis();
if(current_millis - last_try_time > reconnect_time) {
for(int i = 0;i < 20; i++) {
digitalWrite(wifi_led, !ON);
delay(50);
digitalWrite(wifi_led, !OFF);
delay(50); }
if(wifiMulti.run(connectTimeoutMs) == WL_CONNECTED) {
Serial.print("WiFi connected: ");
Serial.print(WiFi.SSID());
delay(100);
Serial.print(" ");
Serial.println(WiFi.localIP());
delay(100); }
if (Firebase.signUp(&config, &auth, "", "")){
Serial.println("ok");
signupOK = true;
}
else { Serial.printf("%s\n", config.signer.signupError.message.c_str()); }
/* Assign the callback function for the long running token generation task */
//config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
delay(100);
Firebase.begin(&config, &auth);
delay(100);
Firebase.reconnectWiFi(true);
delay(100);
last_try_time = millis(); }
}
void get_NTP_DATA() { // Initialize a NTPClient to get time
timeClient.begin();
delay(100);
timeClient.setTimeOffset(19800); // Set offset time in seconds to adjust +5:30
delay(100);
timeClient.update();
time_t epochTime = timeClient.getEpochTime();
struct tm *ptm = gmtime ((time_t *)&epochTime);
DAY = ptm->tm_mday;
MONTH = ptm->tm_mon+1;
YEAR = ptm->tm_year+1900;
HH = timeClient.getHours();
MM = timeClient.getMinutes();
Sec = timeClient.getSeconds();
rtc.adjust(DateTime(YEAR, MONTH, DAY, HH, MM, Sec)); //( YYYY,MM,DD,HH,MM,SS )
Serial.print(" RTC SYNC ");
Firebase.RTDB.setInt(&fbdo, "NEWDB/DAY", DAY) ? timerUpdateflageSettingtrue() : timerUpdateflageSettingfalse();
Firebase.RTDB.setInt(&fbdo, "NEWDB/MONTH", MONTH) ? timerUpdateflageSettingtrue() : timerUpdateflageSettingfalse();
Firebase.RTDB.setInt(&fbdo, "NEWDB/YEAR", YEAR) ? timerUpdateflageSettingtrue() : timerUpdateflageSettingfalse();
Firebase.RTDB.setInt(&fbdo, "NEWDB/HH", HH) ? timerUpdateflageSettingtrue() : timerUpdateflageSettingfalse();
Firebase.RTDB.setInt(&fbdo, "NEWDB/MM", MM) ? timerUpdateflageSettingtrue() : timerUpdateflageSettingfalse();
RTC_SYNC = 1;
}
void PIN_SETUP() { // PIN SETUP
pinMode(wifi_led, OUTPUT);
pinMode(motor, OUTPUT);
pinMode(light, OUTPUT);
// pinMode(motor2, OUTPUT);
pinMode(modem_power_pin, OUTPUT);
digitalWrite(wifi_led, !OFF);
digitalWrite(motor, OFF);
digitalWrite(light, OFF);
// digitalWrite(motor2, OFF);
digitalWrite(modem_power_pin, OFF);
}

void RUN_TIMER() { // RUN TIMER FUNCTIONS
if( (HHMM >= 0 && HHMM < TLOF) || (HHMM >= TLON && HHMM <= 1439) ) // timer function for road light
{ lightState1 = ON; } else { lightState1 = OFF; }
if( (HHMM >= TMON1 && HHMM < TMOF1) || (HHMM >= TMON2 && HHMM < TMOF2) ) // timer function for motor
{ motorState1 = ON; } else { motorState1 = OFF; }
}
void DATA_INIT() { // GET TIMER DATA FROM EEPROM
TMON1 = preferences.getInt("TMON1", 360); // MOTOR ON TIME 1
TMOF1 = preferences.getInt("TMOF1", 420); // MOTOR OFF TIME 1
TMON2 = preferences.getInt("TMON2", 1020); // MOTOR ON TIME 2
TMOF2 = preferences.getInt("TMOF2", 1080); // MOTOR OFF TIME 2
TLON = preferences.getInt("TLON" , 1080); // LIGHT ON TIME
TLOF = preferences.getInt("TLOF" , 360); // LIGHT OFF TIME
}
void setOutputsStates1() { RUN_TIMER(); digitalWrite(motor, motorState1); digitalWrite(light, lightState1);Serial.print("set Outputs BY States1 ");}
void setOutputsStates2() { digitalWrite(motor, motorState2); digitalWrite(light, lightState2);Serial.print("set Outputs BY States2 ");}
bool RTC_STATUS(void) { // chacking RTC is sync or NOT
get_rtc_DATA();
if (DAY >= prog_day && MONTH >= prog_month && YEAR >= prog_year) { return true; }
return false;
}
void wifi_true(){ //true block run if wifi connected
digitalWrite(wifi_led, !ON);
if(RTC_SYNC == 0){ get_NTP_DATA(); } //after 1st connected wifi sync rtc with ntp server
if(RTC_STATUS() == false){ get_NTP_DATA(); }
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/UPDATEFLAGE")) { if (fbdo.dataType() == "int") { UPDATEFLAGE = fbdo.intData();} }
if(UPDATEFLAGE) {
if(Firebase.RTDB.getInt(&fbdo, "/NEWDB/input_code")) {
if (fbdo.dataType() == "int")
{
input_code = fbdo.intData();
}
}
Firebase.RTDB.setInt(&fbdo, "NEWDB/UPDATEFLAGE", 0) ? timerUpdateflageSettingtrue() : timerUpdateflageSettingfalse();
test_input_code();
}
/* else
{
if(MODE == 1)
{
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/D_lightState2")) { if (fbdo.dataType() == "int") { lightState2 = fbdo.intData(); Serial.println(lightState2); } }
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/D_motorState2")) { if (fbdo.dataType() == "int") { motorState2 = fbdo.intData(); Serial.println(motorState2); } }
}
}*/
}
void wifi_false(){ MODE = 0; digitalWrite(wifi_led, ON); initWiFi(); } //false block run if wifi not connected
void timerUpdateflageSettingtrue() {
Serial.println("Set Int data success");
}
void timerUpdateflageSettingfalse() {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
void test_input_code(void){
switch (input_code) {
case 0: // your hand is on the sensor
Serial.println("input_code_0");
input_code_0();
break;
case 1: // your hand is close to the sensor
Serial.println("input_code_1");
input_code_1();
break;
case 2: // your hand is a few inches from the sensor
Serial.println("input_code_2");
input_code_2();
break;
}
}
void input_code_0(void){
Serial.println("DO NOTHING");
}
void input_code_1(void){ // WHEN INPUT CODE = 1 , MEANS MODE VALUE UPDATE
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/AA_MODE")) { if (fbdo.dataType() == "int") { MODE = fbdo.intData();} }
Firebase.RTDB.setInt(&fbdo, "NEWDB/UPDATEFLAGE", 0) ? timerUpdateflageSettingtrue() : timerUpdateflageSettingfalse();
}
void input_code_2(void){ // WHEN INPUT CODE = 2 , MEANS TIMER VALUE UPDATE
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/A_TMON1")) { if (fbdo.dataType() == "int") { TMON1 = fbdo.intData();} }
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/A_TMOF1")) { if (fbdo.dataType() == "int") { TMOF1 = fbdo.intData();} }
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/A_TMON2")) { if (fbdo.dataType() == "int") { TMON2 = fbdo.intData();} }
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/A_TMOF2")) { if (fbdo.dataType() == "int") { TMOF2 = fbdo.intData();} }
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/A_TLON")) { if (fbdo.dataType() == "int") { TLON = fbdo.intData();} }
if (Firebase.RTDB.getInt(&fbdo, "/NEWDB/A_TLOF")) { if (fbdo.dataType() == "int") { TLOF = fbdo.intData();} }
preferences.putInt("TMON1", TMON1);
preferences.putInt("TMOF1", TMOF1);
preferences.putInt("TMON2", TMON2);
preferences.putInt("TMOF2", TMOF2);
preferences.putInt("TLON", TLON);
preferences.putInt("TLOF", TLOF);
Firebase.RTDB.setInt(&fbdo, "NEWDB/UPDATEFLAGE", 0) ? timerUpdateflageSettingtrue() : timerUpdateflageSettingfalse();
}

program run for a minut, data post and get firebase for aprox one minut then get error msg "WARN.mRunUntil: Terminating because the ssl engine closed.
ERROR.write: Failed while waiting for the engine to enter BR_SSL_SENDAPP."

firebase get-post not work, rest part of code work fine.

Incorrectly usage.

You should check the examples and read the comments in the examples carefully.

sir, i am not now so deep knowledge about coding, plz tell me about that part of code for invalid use.

Read and follow the examples.
See what requirement was missed in your code.

Sign up as guess is not recommended and you should avoid use this feature without knowing the risk.

ok sir, i will try this, thank you for your fast reply