Go Down

Topic: i have problem with WiFiClientSecure :( (Read 219 times) previous topic - next topic

irmecir

hi
in this code i want give data from google Sheet and send data in telegram bot,
i use this project to give data from google sheet:
Google Sheet and Esp8266

and use this project for recive and send data from telegram robat:
universal telegram bot

i use esp8266
i merge two above project but i cant compile because i give error , because two project use WiFiClientSecure.h library , and same client :(

this is my merge code:

Code: [Select]
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include "HTTPSRedirect.h"




//======================From Telegram===============================
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>

#define BOTtoken "339475786:AAH7IjXu51xPom_sMx8IRnvQbcTD5FfO2Wc"  // your Bot Token (Get from Botfather)
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done
bool Start = false;

const int ledPin = 2;
int ledStatus = 0;

void handleNewMessages(int numNewMessages) {
  Serial.println("handleNewMessages");
  Serial.println(String(numNewMessages));

  for (int i=0; i<numNewMessages; i++) {
    String chat_id = String(bot.messages[i].chat_id);
    String text = bot.messages[i].text;

    String from_name = bot.messages[i].from_name;
    if (from_name == "") from_name = "Guest";

    if (text == "/ledon") {
      digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
      ledStatus = 1;
      bot.sendMessage(chat_id, "Led is ON", "");
    }

    if (text == "/ledoff") {
      ledStatus = 0;
      digitalWrite(ledPin, LOW);    // turn the LED off (LOW is the voltage level)
      bot.sendMessage(chat_id, "Led is OFF", "");
    }

    if (text == "/status") {
      if(ledStatus){
        bot.sendMessage(chat_id, "Led is ON", "");
      } else {
        bot.sendMessage(chat_id, "Led is OFF", "");
      }
    }

    if (text == "/start") {
      String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
      welcome += "This is Flash Led Bot example.\n\n";
      welcome += "/ledon : to switch the Led ON\n";
      welcome += "/ledoff : to switch the Led OFF\n";
      welcome += "/status : Returns current status of LED\n";
      bot.sendMessage(chat_id, welcome, "Markdown");
    }
  }
}
//***************************************************************************




#define WRITE_INTERVAL_MINITES 1

#define MAX_CONNECT 200 //reuse 2 times same clent
#define MAX_ERROR 100 //restart everything

const char *ssid =  "sajjad";
const char *pass =  "1q2w3e4r5t6y";

const char* host = "script.google.com";
const int httpsPort = 443;

int seconds = (WRITE_INTERVAL_MINITES * 60) - 20; // schedule first sending to TS in 20 sec after start

char *GScriptId = "AKfycbxRzkMt87iyiyU9EDY6REoRDpl5C9oHdjVyCSF6A4QN7jkNMGHD";   // Put your  GScriptId   here

// Access to Google Spreadsheet
String url = String("/macros/s/") + GScriptId + "/exec?";


HTTPSRedirect* client = nullptr;


float hum;
float tem;

void setup() {
  Serial.begin(115200);
  Serial.println();
  delay(200);
  Serial.println("Starting ...");

  delay(200);
 
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  if (WiFi.status() != WL_CONNECTED) WiFi.begin(ssid, pass);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
  delay(10);
  digitalWrite(ledPin, LOW); // initialize pin as off
}

void loop() {
  
  //==============================From telegram=========================================
  if (millis() > Bot_lasttime + Bot_mtbs)  {
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

    while(numNewMessages) {
      Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }

    Bot_lasttime = millis();
  }
  //***********************************************************************
  
  static int error_count = 0;
  static int connect_count = 0;
  static bool flag = false;

  if (!flag){
    client = new HTTPSRedirect(httpsPort);
    flag = true;
    client->setPrintResponseBody(true); // or false and use String getResponseBody();
    client->setContentTypeHeader("application/json");  
    if (!client->connected()) client->connect(host, httpsPort);
    ++connect_count;
  }

   // 30 sec after writing
  

    if (client != nullptr){
      if (!client->connected()){
        client->connect(host, httpsPort);
      }
    }
    else{
      Serial.println("Error2 creating client object!");
      error_count = -10;
    }

    Serial.println("=========================");
    if (client->GET(url + String("readrow=last"), host)){
      DynamicJsonBuffer jsonBuffer;
      JsonObject& json = jsonBuffer.parseObject(client->getResponseBody());
      //json.printTo(Serial);
      String Timestamp = json["values"][0];
      int MaxT0        = json["values"][1];
      int minT0        = json["values"][2];
      String Con0      = json["values"][3];
      int Hu0          = json["values"][4];
      String WS0       = json["values"][5];
      String WD0       = json["values"][6];

      int MaxT1        = json["values"][7];
      int minT1        = json["values"][8];
      String Con1      = json["values"][9];
      int Hu1          = json["values"][10];
      String WS1       = json["values"][11];
      String WD1       = json["values"][12];

      int MaxT2        = json["values"][13];
      int minT2        = json["values"][14];
      String Con2      = json["values"][15];
      int Hu2          = json["values"][16];
      String WS2       = json["values"][17];
      String WD2       = json["values"][18];

      int MaxT3        = json["values"][19];
      int minT3        = json["values"][20];
      String Con3      = json["values"][21];
      int Hu3          = json["values"][22];
      String WS3       = json["values"][23];
      String WD3       = json["values"][24];
      
      float TEMP       = json["values"][25];
      float Hu         = json["values"][26];
      
      Serial.println(Timestamp);
      Serial.println(MaxT0);
      Serial.println(minT0);
      Serial.println(Con0);
      Serial.println(Hu0);
      Serial.println(WS0);
      Serial.println(WD0);

      Serial.println("");
      Serial.println(MaxT1);
      Serial.println(minT1);
      Serial.println(Con1);
      Serial.println(Hu1);
      Serial.println(WS1);
      Serial.println(WD1);

      Serial.println("");
      Serial.println(MaxT2);
      Serial.println(minT2);
      Serial.println(Con2);
      Serial.println(Hu2);
      Serial.println(WS2);
      Serial.println(WD2);

      Serial.println("");
      Serial.println(MaxT3);
      Serial.println(minT3);
      Serial.println(Con3);
      Serial.println(Hu3);
      Serial.println(WS3);
      Serial.println(WD3);

      Serial.println("");
      Serial.println(TEMP);
      Serial.println(Hu);      
      ++connect_count;
    } else {
      ++error_count;
      Serial.println("GET Last row val failed!");
      seconds = 10; // stage again in 10 sec
    }


   if (error_count > MAX_ERROR){
     Serial.println("Errors > MAX_ERROR...");
     //delete client;
     //client = nullptr;
     //connect_count = -1;
     //error_count = 0;
     //flag = false;
     ESP.restart();
   }

   if (connect_count > MAX_CONNECT){
      Serial.println("Connects > MAX_CONNECT... rebuild");
      connect_count = -1;
      flag = false;
      delete client;
    
      //return;  //where?
   }
  
   seconds++;
   delay(1000); //1 sec loop
}


and this is my error when i want compile program:
compile error

please help me
thanks

PaulS

If you want help on pastebin, post your question there.

If you want help HERE, post your output HERE.
The art of getting good answers lies in asking good questions.

irmecir

#2
Oct 10, 2017, 09:49 pm Last Edit: Oct 10, 2017, 09:58 pm by irmecir
excuse me
I could not write because the character limit

this is my error when i want to compile:




Code: [Select]

Googlesheet_DHT_simple:88: error: conflicting declaration 'HTTPSRedirect* client'

HTTPSRedirect* client = nullptr;

               ^

Googlesheet_DHT_simple:13: error: 'client' has a previous declaration as 'WiFiClientSecure client'

WiFiClientSecure client;

                 ^

C:\Users\hossein\Videos\Googlesheet_DHT_simple-master\Googlesheet_DHT_simple\Googlesheet_DHT_simple.ino: In function 'void loop()':

Googlesheet_DHT_simple:139: error: no match for 'operator=' (operand types are 'WiFiClientSecure' and 'HTTPSRedirect*')

    client = new HTTPSRedirect(httpsPort);

           ^

C:\Users\hossein\Videos\Googlesheet_DHT_simple-master\Googlesheet_DHT_simple\Googlesheet_DHT_simple.ino:139:12: note: candidate is:

In file included from C:\Users\hossein\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/ESP8266WiFi.h:41:0,

                from C:\Users\hossein\Videos\Googlesheet_DHT_simple-master\Googlesheet_DHT_simple\Googlesheet_DHT_simple.ino:1:

C:\Users\hossein\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/WiFiClientSecure.h:36:21: note: WiFiClientSecure& WiFiClientSecure::operator=(const WiFiClientSecure&)

  WiFiClientSecure& operator=(const WiFiClientSecure&);

                    ^

C:\Users\hossein\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/WiFiClientSecure.h:36:21: note:   no known conversion for argument 1 from 'HTTPSRedirect*' to 'const WiFiClientSecure&'

Googlesheet_DHT_simple:141: error: base operand of '->' has non-pointer type 'WiFiClientSecure'

    client->setPrintResponseBody(true); // or false and use String getResponseBody();

          ^

Googlesheet_DHT_simple:142: error: base operand of '->' has non-pointer type 'WiFiClientSecure'

    client->setContentTypeHeader("application/json");  

          ^

Googlesheet_DHT_simple:143: error: base operand of '->' has non-pointer type 'WiFiClientSecure'

    if (!client->connected()) client->connect(host, httpsPort);

               ^

Googlesheet_DHT_simple:143: error: base operand of '->' has non-pointer type 'WiFiClientSecure'

    if (!client->connected()) client->connect(host, httpsPort);

                                    ^

Googlesheet_DHT_simple:150: error: no match for 'operator!=' (operand types are 'WiFiClientSecure' and 'std::nullptr_t')

    if (client != nullptr){

               ^

C:\Users\hossein\Videos\Googlesheet_DHT_simple-master\Googlesheet_DHT_simple\Googlesheet_DHT_simple.ino:150:16: note: candidates are:

In file included from C:\Users\hossein\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:13:0,

                from C:\Users\hossein\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:10,

                from C:\Users\hossein\Videos\Googlesheet_DHT_simple-master\Googlesheet_DHT_simple\Googlesheet_DHT_simple.ino:2:

C:\Users\hossein\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/JsonVariantComparisons.hpp:27:13: note: template<class TVariant, class TComparand> bool ArduinoJson::operator!=(const ArduinoJson::JsonVariantBase<T>&, TComparand)

inline bool operator!=(const JsonVariantBase<TVariant> &variant,

            ^

C:\Users\hossein\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/JsonVariantComparisons.hpp:27:13: note:   template argument deduction/substitution failed:

C:\Users\hossein\Videos\Googlesheet_DHT_simple-master\Googlesheet_DHT_simple\Googlesheet_DHT_simple.ino:150:19: note:   'WiFiClientSecure' is not derived from 'const ArduinoJson::JsonVariantBase<T>'

    if (client != nullptr){

                  ^

In file included from C:\Users\hossein\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:13:0,

                from C:\Users\hossein\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:10,

                from C:\Users\hossein\Videos\Googlesheet_DHT_simple-master\Googlesheet_DHT_simple\Googlesheet_DHT_simple.ino:2:

C:\Users\hossein\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/JsonVariantComparisons.hpp:36:1: note: template<class TVariant, class TComparand> typename ArduinoJson::TypeTraits::EnableIf<(! ArduinoJson::TypeTraits::IsVariant<TComparand>::value), bool>::type ArduinoJson::operator!=(TComparand, const ArduinoJson::JsonVariantBase<T>&)

operator!=(TComparand comparand, const JsonVariantBase<TVariant> &variant) {

^

C:\Users\hossein\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/JsonVariantComparisons.hpp:36:1: note:   template argument deduction/substitution failed:

C:\Users\hossein\Videos\Googlesheet_DHT_simple-master\Googlesheet_DHT_simple\Googlesheet_DHT_simple.ino:150:19: note:   mismatched types 'const ArduinoJson::JsonVariantBase<T>' and 'std::nullptr_t'

    if (client != nullptr){

                  ^

Googlesheet_DHT_simple:151: error: base operand of '->' has non-pointer type 'WiFiClientSecure'

      if (!client->connected()){

                 ^

Googlesheet_DHT_simple:152: error: base operand of '->' has non-pointer type 'WiFiClientSecure'

        client->connect(host, httpsPort);

              ^

Googlesheet_DHT_simple:161: error: base operand of '->' has non-pointer type 'WiFiClientSecure'

    if (client->GET(url + String("readrow=last"), host)){

              ^

Googlesheet_DHT_simple:163: error: base operand of '->' has non-pointer type 'WiFiClientSecure'

      JsonObject& json = jsonBuffer.parseObject(client->getResponseBody());

                                                      ^

Googlesheet_DHT_simple:254: error: type 'class WiFiClientSecure' argument given to 'delete', expected pointer

      delete client;

             ^

exit status 1
conflicting declaration 'HTTPSRedirect* client'

PaulS

So, use different names for the two instances. Joe having a brother named Joe is awfully confusing, don't you think?
The art of getting good answers lies in asking good questions.

irmecir

excuse me
i am Newcomer in programing  :smiley-confuse:
alredy changed the client name , and code ha been compiled, but in serial monitor , program crashed

i changed "HTTPSRedirect* client= nullptr;" to "HTTPSRedirect* test= nullptr;" and change every client in the code to test,
this is my code:

Code: [Select]
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include "HTTPSRedirect.h"




//======================From Telegram===============================
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>

#define BOTtoken "339475786:AAH7IjXu51xPom_sMx8IRnvQbcTD5FfO2Wc"  // your Bot Token (Get from Botfather)
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done
bool Start = false;

const int ledPin = 2;
int ledStatus = 0;

void handleNewMessages(int numNewMessages) {
  Serial.println("handleNewMessages");
  Serial.println(String(numNewMessages));

  for (int i=0; i<numNewMessages; i++) {
    String chat_id = String(bot.messages[i].chat_id);
    String text = bot.messages[i].text;

    String from_name = bot.messages[i].from_name;
    if (from_name == "") from_name = "Guest";

    if (text == "/ledon") {
      digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
      ledStatus = 1;
      bot.sendMessage(chat_id, "Led is ON", "");
    }

    if (text == "/ledoff") {
      ledStatus = 0;
      digitalWrite(ledPin, LOW);    // turn the LED off (LOW is the voltage level)
      bot.sendMessage(chat_id, "Led is OFF", "");
    }

    if (text == "/status") {
      if(ledStatus){
        bot.sendMessage(chat_id, "Led is ON", "");
      } else {
        bot.sendMessage(chat_id, "Led is OFF", "");
      }
    }

    if (text == "/start") {
      String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
      welcome += "This is Flash Led Bot example.\n\n";
      welcome += "/ledon : to switch the Led ON\n";
      welcome += "/ledoff : to switch the Led OFF\n";
      welcome += "/status : Returns current status of LED\n";
      bot.sendMessage(chat_id, welcome, "Markdown");
    }
  }
}
//***************************************************************************




#define WRITE_INTERVAL_MINITES 1

#define MAX_CONNECT 200 //reuse 2 times same clent
#define MAX_ERROR 100 //restart everything

const char *ssid =  "hooshmandsazan3";
const char *pass =  "!q@w#e4r5t6y";

const char* host = "script.google.com";
const int httpsPort = 443;

int seconds = (WRITE_INTERVAL_MINITES * 60) - 20; // schedule first sending to TS in 20 sec after start

char *GScriptId = "AKfycbxRzkMt87iyiyU9EDY6REoRDpl5C9oHdjVyCSF6A4QN7jkNMGHD";   // Put your  GScriptId   here

// Access to Google Spreadsheet
String url = String("/macros/s/") + GScriptId + "/exec?";


HTTPSRedirect* test = nullptr;


float hum;
float tem;

void setup() {
  Serial.begin(115200);
  Serial.println();
  delay(200);
  Serial.println("Starting ...");

  delay(200);
 
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  if (WiFi.status() != WL_CONNECTED) WiFi.begin(ssid, pass);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
  delay(10);
  digitalWrite(ledPin, LOW); // initialize pin as off
}

void loop() {
  
  //==============================From telegram=========================================
  if (millis() > Bot_lasttime + Bot_mtbs)  {
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

    while(numNewMessages) {
      Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }

    Bot_lasttime = millis();
  }
  //***********************************************************************
  
  static int error_count = 0;
  static int connect_count = 0;
  static bool flag = false;

  if (!flag){
    test = new HTTPSRedirect(httpsPort);
    flag = true;
    test->setPrintResponseBody(true); // or false and use String getResponseBody();
    test->setContentTypeHeader("application/json");  
    if (!test->connected()) test->connect(host, httpsPort);
    ++connect_count;
  }

   // 30 sec after writing
  

    if (test != nullptr){
      if (!test->connected()){
        test->connect(host, httpsPort);
      }
    }
    else{
      Serial.println("Error2 creating client object!");
      error_count = -10;
    }

    Serial.println("=========================");
    if (test->GET(url + String("readrow=last"), host)){
      DynamicJsonBuffer jsonBuffer;
      JsonObject& json = jsonBuffer.parseObject(test->getResponseBody());
      //json.printTo(Serial);
      String Timestamp = json["values"][0];
      int MaxT0        = json["values"][1];
      int minT0        = json["values"][2];
      String Con0      = json["values"][3];
      int Hu0          = json["values"][4];
      String WS0       = json["values"][5];
      String WD0       = json["values"][6];

      int MaxT1        = json["values"][7];
      int minT1        = json["values"][8];
      String Con1      = json["values"][9];
      int Hu1          = json["values"][10];
      String WS1       = json["values"][11];
      String WD1       = json["values"][12];

      int MaxT2        = json["values"][13];
      int minT2        = json["values"][14];
      String Con2      = json["values"][15];
      int Hu2          = json["values"][16];
      String WS2       = json["values"][17];
      String WD2       = json["values"][18];

      int MaxT3        = json["values"][19];
      int minT3        = json["values"][20];
      String Con3      = json["values"][21];
      int Hu3          = json["values"][22];
      String WS3       = json["values"][23];
      String WD3       = json["values"][24];
      
      float TEMP       = json["values"][25];
      float Hu         = json["values"][26];
      
      Serial.println(Timestamp);
      Serial.println(MaxT0);
      Serial.println(minT0);
      Serial.println(Con0);
      Serial.println(Hu0);
      Serial.println(WS0);
      Serial.println(WD0);

      Serial.println("");
      Serial.println(MaxT1);
      Serial.println(minT1);
      Serial.println(Con1);
      Serial.println(Hu1);
      Serial.println(WS1);
      Serial.println(WD1);

      Serial.println("");
      Serial.println(MaxT2);
      Serial.println(minT2);
      Serial.println(Con2);
      Serial.println(Hu2);
      Serial.println(WS2);
      Serial.println(WD2);

      Serial.println("");
      Serial.println(MaxT3);
      Serial.println(minT3);
      Serial.println(Con3);
      Serial.println(Hu3);
      Serial.println(WS3);
      Serial.println(WD3);

      Serial.println("");
      Serial.println(TEMP);
      Serial.println(Hu);      
      ++connect_count;
    } else {
      ++error_count;
      Serial.println("GET Last row val failed!");
      seconds = 10; // stage again in 10 sec
    }


   if (error_count > MAX_ERROR){
     Serial.println("Errors > MAX_ERROR...");
     //delete client;
     //client = nullptr;
     //connect_count = -1;
     //error_count = 0;
     //flag = false;
     ESP.restart();
   }

   if (connect_count > MAX_CONNECT){
      Serial.println("Connects > MAX_CONNECT... rebuild");
      connect_count = -1;
      flag = false;
      delete test;
    
      //return;  //where?
   }
  
   seconds++;
   delay(1000); //1 sec loop
}





irmecir

i also change below code, in the next change
Code: [Select]
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

 to :
Code: [Select]
WiFiClientSecure test;
UniversalTelegramBot bot(BOTtoken, test);


and you can see my Serial monitor:

Code: [Select]
Starting ...
Connecting to hooshmandsazan3
.

WiFi connected

Exception (29):
epc1=0x4000e1cc epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000204 depc=0x00000000

ctx: cont
sp: 3fff0fd0 end: 3fff18e0 offset: 01a0

>>>stack>>>
3fff1170:  00410000 3fffb59c 3fffb75c 40224e3f  
3fff1180:  3fffb63c 3fffb87c 00000081 40225aa1  
3fff1190:  3fff07cc 00001311 00001311 4010020c  
3fff11a0:  3fffbbc4 3fffba9c 00000040 00000000  
3fff11b0:  0000000c 3fffb59c 00000041 00000041  
3fff11c0:  00000000 00000001 00000001 0000007f  
3fff11d0:  3fffb87c 00000081 3fffb87c 402049ac  
3fff11e0:  3fffb63c 3fffb59c 3fffb5e4 0000007f  
3fff11f0:  3fffb87c 3fffb59c 3fffb59c 40225d5d  
3fff1200:  00000002 00000001 3fffb59c 40224ea4  
3fff1210:  00000100 00000100 3fffb494 3fffb60c  
3fff1220:  3fffb448 00000100 3fffb59c 40226dc8  
3fff1230:  3fffb494 3fffb0d4 00000003 4022aa78  
3fff1240:  3fff1614 0000001c 00000003 00000000  
3fff1250:  00000100 3fff8b82 3fff1614 4022af76  
3fff1260:  3fffb0d4 3fffb494 3fff1614 4022ae08  
3fff1270:  3fffb41c 0000001c 3fff1614 4022aca0  
3fff1280:  00000082 3fff53dc 3fff8b82 00000000  
3fff1290:  00000004 3fffb41c 3fff8b82 40223c74  
3fff12a0:  0000062b 00000000 e0a87a9c 947c398b  
3fff12b0:  c42faecc fecfedd6 1e2924c1 99241375  
3fff12c0:  10bb95c8 1ee787b1 30300202 1d550306  
3fff12d0:  3029041f a0253027 8621a023 7474681f  
3fff12e0:  2f2f3a70 2e696b70 676f6f67 632e656c  
3fff12f0:  472f6d6f 32474149 6c72632e 00000080  
3fff1300:  00000000 a0390000 b3749e67 ce8def77  
3fff1310:  a5386a7c 66e93cce 9d1bdeef 4a70d1b9  
3fff1320:  bd091071 81cfe8fd f2089fbd e709fe0c  
3fff1330:  49ef0502 29c343a7 84ff282b bcc7f914  
3fff1340:  3fa6f28f 2c820a61 b1072564 e197be74  
3fff1350:  ba9d77e0 68bb1769 8af4b182 9bcb6f61  
3fff1360:  3038d454 81615a25 2257a175 3ecbaf16  
3fff1370:  edd801d9 bfd0195f 1ecd8860 ccad3b9b  
3fff1380:  029235c0 a572cca0 cac190d5 6aea6797  
3fff1390:  f1861636 0cc3e305 9dd71443 4f0231d2  
3fff13a0:  387d47c8 0e1e5ba1 94980356 a7192c2d  
3fff13b0:  191b885c d64d852f 4d230b9c 7f8c9d6a  
3fff13c0:  4cc6cfe4 194bf615 a0a631bf 1becceb7  
3fff13d0:  d802f878 6a54cc8e e6cb2d41 cd241ec3  
3fff13e0:  14ee8fe9 ad0f59b0 c00348ed fcadd0b8  
3fff13f0:  426a4410 072d384c 37067302 d3126359  
3fff1400:  db6ec9b6 33bc101a 89bb72d4 60c2cf1f  
3fff1410:  3ffca094 3fff1440 c280023a 031bd2c3  
3fff1420:  3fff2ded 3fff4e3c 3fff2e3b 3fff1440  
3fff1430:  3fff4e3c 00000014 3fff2e3b 402263f0  
3fff1440:  37e4bff4 fae10b1f 81aca749 0d04b8ad  
3fff1450:  e304b8b0 00000000 00000000 00000000  
3fff1460:  00000000 00000000 00000000 00000000  
3fff1470:  00000008 00000000 00000020 40101ece  
3fff1480:  3ffeae18 40101b79 00000002 00000000  
3fff1490:  00000005 00000008 40101a2e 00000002  
3fff14a0:  00000002 4010182f 00000002 3ffeef60  
3fff14b0:  00000001 00000000 00000020 40101ece  
3fff14c0:  40105190 3ffee5a8 3ffeef60 00000001  
3fff14d0:  00000001 4010439f 3ffeefd8 00000008  
3fff14e0:  40104802 3ffee5a8 3fff22fc 00000001  
3fff14f0:  4020a4f6 3ffee5a8 3fff22fc 3ffee5a8  
3fff1500:  401042e6 00000033 7fffffff 00000002  
3fff1510:  00000133 40104115 00040000 3fff26ef  
3fff1520:  4010324b 00080000 40101a2e 00000002  
3fff1530:  00000000 4010182f 00002200 4000050c  
3fff1540:  3fffc278 40102f48 3fffc200 00000022  
3fff1550:  3fff1560 401051ab 3ffee8a0 9eba4342  
3fff1560:  40226592 00000030 00000019 ffffffff  
3fff1570:  579f048d 05e48839 129562e4 c7b4780e  
3fff1580:  c12d7281 00000000 00000000 00000000  
3fff1590:  00000000 00000000 00000000 00000000  
3fff15a0:  00000000 00000000 00000000 00000000  
3fff15b0:  00000000 00000000 00000000 00000000  
3fff15c0:  00000000 00000000 00000000 80230000  
3fff15d0:  9c7aa8e0 8b397c94 ccae2fc4 d6edcffe  
3fff15e0:  c124291e 75132499 c895bb10 b187e71e  
3fff15f0:  4b0ba00a a44888bd a063a4e9 7b0bc4c4  
3fff1600:  34160e78 5ff89332 5af00d8e b371d5d2  
3fff1610:  0000042c 00000203 00000318 b79bae50  
3fff1620:  3fff5414 0000062b 0000003c 00000000  
3fff1630:  3fffb308 000000ec 7f30e519 5f096c26  
3fff1640:  9724dbf1 3012c806 9516ed2f 3fff8329  
3fff1650:  3fff5414 0000042c 00000859 40222322  
3fff1660:  00001002 3fff530c 00001009 00820011  
3fff1670:  1ced0703 d1ff3fcb 4e2413a5 48ce7501  
3fff1680:  0bce8304 9a59558f 94bb81f0 00001009  
3fff1690:  00001009 3fff8329 3fff530c 40223559  
3fff16a0:  0d5e940a 6e44fc88 12afc308 34a4d314  
3fff16b0:  c1220d9d a9c45b57 590a2579 8bfa576c  
3fff16c0:  adb56113 3fff4964 3fff4924 00000f80  
3fff16d0:  00001009 3fff9313 0000001e 3fff4964  
3fff16e0:  3fff530c 3fff8329 00001009 00001009  
3fff16f0:  00001009 3fff8329 3fff530c 40222fd0  
3fff1700:  00000000 3fff8329 3fff530c 40223378  
3fff1710:  00000011 3ffe91b8 00000012 401004d8  
3fff1720:  3fff1770 0000000b 00000010 00000000  
3fff1730:  3fff2974 3ffe91b8 3fff530c 01000000  
3fff1740:  3fff1770 3fff2a24 3fff530c 40223128  
3fff1750:  40204288 00000000 3fff08c0 00001387  
3fff1760:  00000aa1 3fff2a24 3fff4e9c 40204849  
3fff1770:  000001bb 3fff2c4c 3fff2a24 40203d2e  
3fff1780:  4ecf3ad8 3ffea4c4 3fff2a78 3ffe839c  
3fff1790:  000001bb 3fff2a24 3ffe91b8 40204a59  
3fff17a0:  3ffe9ad8 4ecf3ad8 3ffe9ad8 4ecf3ad8  
3fff17b0:  3fff0604 3fff2a24 3fff07f0 40203245  
3fff17c0:  736f6f68 6e616d68 7a617364 00336e61  
3fff17d0:  efeffefe 01c200fe 00001c00 00000000  
3fff17e0:  77407121 72346523 79367435 00000100  
3fff17f0:  fea24100 20753c3f 00000040 00000e00  
3fff1800:  fe91ea00 ff08ac3f fe83a43f 00000f3f  
3fff1810:  ff07f000 2065313f 21f2de40 ff07f040  
3fff1820:  6b08ec00 684b12bc 68736f6f 646e616d  
3fff1830:  617a6173 fe00336e feefeffe 0001c200  
3fff1840:  0000001c 21000000 23774071 35723465  
3fff1850:  40105872 000570ed 3ffea241 4020753c  
3fff1860:  4010592e 3ffeffe8 000570ed 00000000  
3fff1870:  40105b00 000570ed 3fff072c 00000000  
3fff1880:  3fff0010 3fff072c 3fff08c0 3fff072c  
3fff1890:  3ffe9110 3fff08ac 4020710c 3fff08c0  
3fff18a0:  402010ae 0000000a 0000000a 402010a3  
3fff18b0:  3ffe83a4 3fff06d0 3fff07f0 3fff08ac  
3fff18c0:  3fffdad0 00000000 3fff08a4 40207158  
3fff18d0:  feefeffe feefeffe 3fff08c0 40100718  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld


please help me  :(

PaulS

Code: [Select]
  Serial.println(String(numNewMessages));
Do you REALLY think that println() doesn't know how to print an int without your resource-wasting, ham-fisted "help"?

Get a clue.

Code: [Select]
      delete test;
When you delete the memory used by the instance, and don't set the pointer back to NULL, what do you suppose is going to happen the next time you test that the pointer is not NULL? What is going to happen when you dereference the pointer?

You need to add more Serial.print() statements to the code to figure out exactly which part of the code is triggering the exception.
The art of getting good answers lies in asking good questions.

irmecir

#7
Oct 11, 2017, 09:46 pm Last Edit: Oct 11, 2017, 09:55 pm by irmecir
thanks for your reply

i add Serial.println() in the code for debugging

Code: [Select]
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include "HTTPSRedirect.h"




//======================From Telegram===============================
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>

#define BOTtoken "339475786:AAH7IjXu51xPom_sMx8IRnvQbcTD5FfO2Wc"  // your Bot Token (Get from Botfather)
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

int Bot_mtbs = 1000; //mean time between scan messages
long Bot_lasttime;   //last time messages' scan has been done
bool Start = false;

const int ledPin = 2;
int ledStatus = 0;

void handleNewMessages(int numNewMessages) {
  //Serial.println(F("handleNewMessages"));
  //Serial.println(String(numNewMessages));

  for (int i=0; i<numNewMessages; i++) {
    String chat_id = String(bot.messages[i].chat_id);
    String text = bot.messages[i].text;

    String from_name = bot.messages[i].from_name;
    if (from_name == "") from_name = "Guest";

    if (text == "/ledon") {
      digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
      ledStatus = 1;
      bot.sendMessage(chat_id, "Led is ON", "");
    }

    if (text == "/ledoff") {
      ledStatus = 0;
      digitalWrite(ledPin, LOW);    // turn the LED off (LOW is the voltage level)
      bot.sendMessage(chat_id, "Led is OFF", "");
    }

    if (text == "/status") {
      if(ledStatus){
        bot.sendMessage(chat_id, "Led is ON", "");
      } else {
        bot.sendMessage(chat_id, "Led is OFF", "");
      }
    }

    if (text == "/start") {
      String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
      welcome += "This is Flash Led Bot example.\n\n";
      welcome += "/ledon : to switch the Led ON\n";
      welcome += "/ledoff : to switch the Led OFF\n";
      welcome += "/status : Returns current status of LED\n";
      bot.sendMessage(chat_id, welcome, "Markdown");
    }
  }
}
//***************************************************************************




#define WRITE_INTERVAL_MINITES 1

#define MAX_CONNECT 200 //reuse 2 times same clent
#define MAX_ERROR 100 //restart everything

const char *ssid =  "sajjad";
const char *pass =  "1q2w3e4r5t6y";

const char* host = "script.google.com";
const int httpsPort = 443;

int seconds = (WRITE_INTERVAL_MINITES * 60) - 20; // schedule first sending to TS in 20 sec after start

char *GScriptId = "AKfycbxRzkMt87iyiyU9EDY6REoRDpl5C9oHdjVyCSF6A4QN7jkNMGHD";   // Put your  GScriptId   here

// Access to Google Spreadsheet
String url = String("/macros/s/") + GScriptId + "/exec?";


HTTPSRedirect* test = nullptr;


float hum;
float tem;

void setup() {
  Serial.begin(115200);
  Serial.println();
  delay(200);
  Serial.println(F("Starting ..."));

  delay(200);
 
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  if (WiFi.status() != WL_CONNECTED) WiFi.begin(ssid, pass);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println(F("."));
  }
  Serial.println("");
  Serial.println("WiFi connected");
  pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output.
  delay(10);
  digitalWrite(ledPin, LOW); // initialize pin as off
}

void loop() {
  Serial.println("1");
  
  //==============================From telegram=========================================
  if (millis() > Bot_lasttime + Bot_mtbs)  {
    Serial.println("2");
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    
    while(numNewMessages) {
      Serial.println("3");
      Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }
    Serial.println("4");
    Bot_lasttime = millis();
  }
  //***********************************************************************
  Serial.println("5");
  static int error_count = 0;
  static int connect_count = 0;
  static bool flag = false;

  if (!flag){
    Serial.println("6");
    test = new HTTPSRedirect(httpsPort);
    flag = true;
    test->setPrintResponseBody(true); // or false and use String getResponseBody();
    Serial.println("6a");
    test->setContentTypeHeader("application/json");  
    Serial.println("6b");
    if (!test->connected()) test->connect(host, httpsPort);
    Serial.println("6c");
    ++connect_count;
    Serial.println("6d");
  }

   // 30 sec after writing
  

    if (test != nullptr){
      Serial.println("7");
      if (!test->connected()){
        test->connect(host, httpsPort);
      }
    }
    else{
      Serial.println(F("Error2 creating client object!"));
      error_count = -10;
      Serial.println("7a");
    }
    Serial.println("7b");
    Serial.println(F("========================="));
    if (test->GET(url + String("readrow=last"), host)){
      Serial.println("8");
      DynamicJsonBuffer jsonBuffer;
      JsonObject& json = jsonBuffer.parseObject(test->getResponseBody());
      //json.printTo(Serial);
      String Timestamp = json["values"][0];
      int MaxT0        = json["values"][1];
      int minT0        = json["values"][2];
      String Con0      = json["values"][3];
      int Hu0          = json["values"][4];
      String WS0       = json["values"][5];
      String WD0       = json["values"][6];

      int MaxT1        = json["values"][7];
      int minT1        = json["values"][8];
      String Con1      = json["values"][9];
      int Hu1          = json["values"][10];
      String WS1       = json["values"][11];
      String WD1       = json["values"][12];

      int MaxT2        = json["values"][13];
      int minT2        = json["values"][14];
      String Con2      = json["values"][15];
      int Hu2          = json["values"][16];
      String WS2       = json["values"][17];
      String WD2       = json["values"][18];

      int MaxT3        = json["values"][19];
      int minT3        = json["values"][20];
      String Con3      = json["values"][21];
      int Hu3          = json["values"][22];
      String WS3       = json["values"][23];
      String WD3       = json["values"][24];
      
      float TEMP       = json["values"][25];
      float Hu         = json["values"][26];
      
      Serial.println(Timestamp);
      Serial.println(MaxT0);
      Serial.println(minT0);
      Serial.println(Con0);
      Serial.println(Hu0);
      Serial.println(WS0);
      Serial.println(WD0);

      Serial.println("");
      Serial.println(MaxT1);
      Serial.println(minT1);
      Serial.println(Con1);
      Serial.println(Hu1);
      Serial.println(WS1);
      Serial.println(WD1);

      Serial.println("");
      Serial.println(MaxT2);
      Serial.println(minT2);
      Serial.println(Con2);
      Serial.println(Hu2);
      Serial.println(WS2);
      Serial.println(WD2);

      Serial.println("");
      Serial.println(MaxT3);
      Serial.println(minT3);
      Serial.println(Con3);
      Serial.println(Hu3);
      Serial.println(WS3);
      Serial.println(WD3);

      Serial.println("");
      Serial.println(TEMP);
      Serial.println(Hu);      
      ++connect_count;
    } else {
      Serial.println("9");
      ++error_count;
      Serial.println(F("GET Last row val failed!"));
      seconds = 10; // stage again in 10 sec
    }


   if (error_count > MAX_ERROR){
    Serial.println("10");
     Serial.println(F("Errors > MAX_ERROR..."));
     //delete client;
     //client = nullptr;
     //connect_count = -1;
     //error_count = 0;
     //flag = false;
     ESP.restart();
   }

   if (connect_count > MAX_CONNECT){
      Serial.println("11");
      Serial.println(F("Connects > MAX_CONNECT... rebuild"));
      connect_count = -1;
      flag = false;
      delete test;
    
      //return;  //where?
   }
  
   seconds++;
   delay(1000); //1 sec loop
}


when the code arive to "6b" program go to hang,
when arive to :
Code: [Select]
if (!test->connected()) test->connect(host, httpsPort);
I'm confused  :(

this is my output:
Code: [Select]
Starting ...
Connecting to sajjad
.
.
.
.
.
.
.
.

WiFi connected
1
2
4
5
6
6a
6b

Exception (29):
epc1=0x4000dfd9 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont
sp: 3fff1000 end: 3fff1850 offset: 01a0

>>>stack>>>
3fff11a0:  3fff073c 000011c9 000011c9 4022ab8c  
3fff11b0:  3fff1584 00000012 00000003 00000000  
3fff11c0:  00000030 3fff8ea1 3fff1584 4022b06f  
3fff11d0:  00000000 00000000 3fff1584 4022af1c  

irmecir

i now use only below project without universal telegram bot , and change all client to test and work corectly but when merge whit telegram bot i give error

https://github.com/lorol/Googlesheet_DHT_simple


PaulS

Code: [Select]
    Serial.println("6b");
    if (!test->connected()) test->connect(host, httpsPort);
    Serial.println("6c");

You COULD get a lot more information here.

Code: [Select]
    Serial.println("6b");
    if (!test->connected())
    {
       Serial.print("host: [");
       Serial.print(host);
       Serial.println("]");
       Serial.print("httpsPort: [");
       Serial.print(httpsPort);
       Serial.println("]");
       test->connect(host, httpsPort);
    }
    Serial.println("6c");


This way, we learn whether you are connected, and, if not, as is probably the case, what host you are trying to connect to, on what port.

I'm curious as to why the HTTPSRedirect constructor takes a port number AND the connect() method takes a port number. One would think that the class would only need to be told once what the port number was.
The art of getting good answers lies in asking good questions.

irmecir

hi
thanks
i change thw seting that you told to me and this is result:
Code: [Select]

Starting ...
Connecting to sajjad
.
.

WiFi connected
1
2
4
5
6
6a
6b
host: [script.google.com]
httpsPort: [443]

Exception (29):
epc1=0x4000e1cc epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000204 depc=0x00000000

ctx: cont
sp: 3fff0f60 end: 3fff1870 offset: 01a0

>>>stack>>>
3fff1100:  00410000 3fffb4b4 3fffb674 40224fa3 
3fff1110:  3fffb554 3fffb794 00000081 40225c05 
3fff1120:  3fff075c 00001302 00001302 4010020c 
3fff1130:  3fffbadc 3fffb9b4 00000040 00000000 
3fff1140:  0000000c 3fffb4b4 00000041 00000041 




PaulS

So, the problem is that you have a test object that may, or may not, be valid (though odds are that it is), and that the object throws an exception in the connect() method.

Since HTTPSRedirect derives from WiFiClientSecure, I don't understand why you need a HTTPSRedirect instance AND a WiFiClientSecure instance in the same code. Just create a HTTPSRedirect instance, and it will be able to do everything that the WiFiClientSecure instance can do, plus more stuff.
The art of getting good answers lies in asking good questions.

irmecir

this is answer of my friend:
It looks like you have two WiFiClientSecure instances at the same time: one for telegram bot, another one for google sheets. That is not going to work, as single WiFiClientSecure instance needs around 25kB of heap (that is in current git version, and even more in release 2.3.0), and the total amount of heap at the start of the program is ~40kB. You need to refactor your program so it only uses one WiFiClientSecure at a time.


but how i do this?
in below is my compile information:

Sketch uses 303141 bytes (29%) of program storage space. Maximum is 1044464 bytes.
Global variables use 41360 bytes (50%) of dynamic memory, leaving 40560 bytes for local variables. Maximum is 81920 bytes

PaulS

Suppose that you have a friend that has a pickup truck. Suppose that you have another friend that has a car.

Can the friend with the pickup truck substitute for the friend with the car? Of course, he or she can.

Can the friend with the car substitute for the friend with the truck? Not if you need to haul a load of cinder blocks.

The HTTPSRequest class is like the friend with the truck - can do everything a truck can do and can do everything a car can do (except pass gas stations). The WiFiClientSecure class is like the friend with the car - can transport you but NOT the load of cinder blocks.

Since you have a friend with a truck, why do you need to catch a ride with the friend with the car, while the truck hauls the cinder blocks?
The art of getting good answers lies in asking good questions.

witnessmenow

Suppose that you have a friend that has a pickup truck. Suppose that you have another friend that has a car.

Can the friend with the pickup truck substitute for the friend with the car? Of course, he or she can.

Can the friend with the car substitute for the friend with the truck? Not if you need to haul a load of cinder blocks.

The HTTPSRequest class is like the friend with the truck - can do everything a truck can do and can do everything a car can do (except pass gas stations). The WiFiClientSecure class is like the friend with the car - can transport you but NOT the load of cinder blocks.

Since you have a friend with a truck, why do you need to catch a ride with the friend with the car, while the truck hauls the cinder blocks?
Nice explanation!

Go Up