i want import myLine variable that is in cpp library into arduino sketch But not return a "line" value.
this is my cpp file:
void HTTPSRedirect::fetchData(bool disp, bool header){
String line;
pinMode(2, OUTPUT);
while (connected()) {
line = readStringUntil('\n');
if (disp)
Serial.println(line);
if(line == "On\r"){
//Serial.println("Led On");
digitalWrite(2, HIGH);
}
if(line == "Off\r"){
//Serial.println("Led Off");
digitalWrite(2, LOW);
}
if (line == "\r") {
if (disp){
if (header) DPRINTLN("END OF HEADER");
else DPRINTLN("END OF RESPONSE");
//DPRINTLN(line);
}
break;
}
}
myLine = line;
//Serial.println(client.myLine);
}
i only work with this function:
void HTTPSRedirect::fetchData(bool disp, bool header){
String line;
pinMode(2, OUTPUT);
while (connected()) {
line = readStringUntil('\n');
if (disp)
Serial.println(line);
if(line == "On\r"){
//Serial.println("Led On");
digitalWrite(2, HIGH);
}
if(line == "Off\r"){
//Serial.println("Led Off");
digitalWrite(2, LOW);
}
if (line == "\r") {
if (disp){
if (header) DPRINTLN("END OF HEADER");
else DPRINTLN("END OF RESPONSE");
//DPRINTLN(line);
}
break;
}
}
myLine = line;
//Serial.println(client.myLine);
}
this is my header file:
/* HTTPS with follow-redirect
* Created by Sujay S. Phadke, 2016
* All rights reserved.
*
*/
#include <WiFiClientSecure.h>
#include "Arduino.h"
class HTTPSRedirect : public WiFiClientSecure {
private:
const int httpsPort;
const char* redirFingerprint;
bool fpCheck = false;
bool keepAlive = true;
bool verboseInfo = false;
public:
String myLine="";
HTTPSRedirect(const int, const char*, bool);
HTTPSRedirect(const int);
~HTTPSRedirect();
bool printRedir(const char*, const char*, const char*);
bool printRedir(String&, const char*, const char*);
String createRequest(const char*, const char*);
void fetchData(bool, bool);
};
and this is my shetch:
/*
* HTTPS with follow-redirect example
* Created by Sujay S. Phadke, 2016
*
* Based on the WifiClientSecure example by
* Ivan Grokhotkov
*
*
* This example is in public domain.
*
* Modified by PDAControl
* http://pdacontrolenglish.blogspot.com.co
* http://pdacontrol.blogspot.com.co
* https://youtu.be/5f7wCeD4gB4 -- TUTORIAL
*/
#include <ESP8266WiFi.h>
#include "HTTPSRedirect.h"
// Replace with your network credentials
const char* ssid = "sajjad";
const char* password = "1q2w3e4r5t6y";
const char* host = "script.google.com";
const char* googleRedirHost = "script.googleusercontent.com";
const char *GScriptId = "AKfycbyOZ2agkz7Udy7L43aitJP0DgM1dlaAsAnJ7tudm9_wod7ZdNM";
const int httpsPort = 443;
// http://askubuntu.com/questions/156620/how-to-verify-the-ssl-fingerprint-by-command-line-wget-curl/
// echo | openssl s_client -connect script.google.com:443 |& openssl x509 -fingerprint -noout
// www.grc.com doesn't seem to get the right fingerprint
// SHA1 fingerprint of the certificate
//const char* fingerprint = "94 2F 19 F7 A8 B4 5B 09 90 34 36 B2 2A C4 7F 17 06 AC 6A 2E";
const char* fingerprint = "F0 5C 74 77 3F 6B 25 D7 3B 66 4D 43 2F 7E BC 5B E9 28 86 AD";
const char* fingerprint2 = "94 64 D8 75 DE 5D 3A E6 3B A7 B6 15 52 72 CC 51 7A BA 2B BE";
// Write to Google Spreadsheet
String url = String("/macros/s/") + GScriptId + "/exec?value=Hello";
// Fetch Google Calendar events for 1 week ahead
String url2 = String("/macros/s/") + GScriptId + "/exec?cal";
// Read from Google Spreadsheet
String url3 = String("/macros/s/") + GScriptId + "/exec?read";
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to wifi: ");
Serial.println(ssid);
// flush() is needed to print the above (connecting...) message reliably,
// in case the wireless connection doesn't go through
Serial.flush();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Use HTTPSRedirect class to create TLS connection
HTTPSRedirect client(httpsPort);
Serial.print("Connecting to ");
Serial.println(host);
bool flag = false;
for (int i=0; i<5; i++){
int retval = client.connect(host, httpsPort);
if (retval == 1) {
flag = true;
break;
}
else
Serial.println("Connection failed. Retrying...");
}
Serial.flush();
if (!flag){
Serial.print("Could not connect to server: ");
Serial.println(host);
Serial.println("Exiting...");
return;
}
Serial.flush();
if (client.verify(fingerprint, host)) {
Serial.println("Certificate match.");
} else {
Serial.println("Certificate mis-match");
}
// Note: setup() must finish within approx. 1s, or the the watchdog timer
// will reset the chip. Hence don't put too many requests in setup()
// ref: https://github.com/esp8266/Arduino/issues/34
//Serial.print("Requesting URL: ");
//Serial.println(url);
client.printRedir(url, host, googleRedirHost);
Serial.println("==============================================================================");
// client.printRedir(url2, host, googleRedirHost);
// Serial.println("==============================================================================");
}
void loop() {
HTTPSRedirect client(httpsPort);
if (!client.connected())
client.connect(host, httpsPort);
client.printRedir(url3, host, googleRedirHost);
// client.fetchData;
Serial.println("***");
Serial.println(client.myLine);
Serial.println("***");
// In my testing on a ESP-01, a delay of less than 1500 resulted
// in a crash and reboot after about 50 loop runs.
delay(1500);
}
i see in Serial monitor:
On <--- Serial.print(line) that is in cpp file
***
** <-- i dont see On :(**
***
please help me