electronicsguy/ESP8266

is this working with ESP32?

Behzad-6-1 opened this issue · 3 comments

I have tried a few things and got the working however it stops after 1st try, it seems there is no response from GS.

It is simply in a loop. works 1st run then stops

Welcome to HTTPSRedirect! Please provide enough info to debug the issue.

HTTPSRedirect works well with ESP8266 quite reliably. ESP32 works ok and connects to Google sheet script (GSS) however it can only receive response from GSS once and activating relay, then it just stops. I have traced the fault and appeared to be in HTTPSRedirect (see Below). I have added "Serial.println("GET3161 :: " + line);" to monitor line. 1st round I receive 302... then 200 OK. the 2nd round it just blank and and keep in looping endlessly.

`unsigned int HTTPSRedirect::getResponseStatus(void){
// Read response status line
// ref: https://www.tutorialspoint.com/http/http_responses.htm

unsigned int statusCode;
String reasonPhrase;
String line;

unsigned int pos = -1;
unsigned int pos2 = -1;

// Skip any empty lines
do{
line = readStringUntil('\n');
Serial.println("GET3161 :: " + line);
}while(line.length() == 0);`

My loop sketch is same as the one I use for with ESP8266 and it works fine

`void loop() {
static int error_count = 0;
static int connect_count = 0;
const unsigned int MAX_CONNECT = 20;
static bool flag = false;
static int GateCount = 0;
Serial.println("start of the loop -- ");

//digitalWrite(ledPin1, HIGH);
if (!flag){
Serial.println("!flag ");
free_heap_before = ESP.getFreeHeap();
//free_stack_before = ESP.getFreeContStack();
client = new HTTPSRedirect(httpsPort);
//client->setInsecure();
flag = true;
client->setPrintResponseBody(true);
client->setContentTypeHeader("application/json");
}

if (client != nullptr){
//if (!client->connected()){
Serial.println("-- client != nullptr--");
client->connect(host, httpsPort);
//digitalWrite(ledPin1, HIGH);

}
else{
//digitalWrite(LED_BUILTIN, LOW);
DPRINTLN("Error creating client object!");
error_count = 5;
}

if (connect_count > MAX_CONNECT){
//digitalWrite(ledPin1, HIGH);
connect_count = 0;
flag = false;
delete client;
return;
}

//Serial.println("GET Data from cell 'C':");
Serial.println("Form responce ");
Serial.print("url ::");
Serial.println(url);
Serial.print("host ::");
Serial.print(host);
if (client->GET(url, host)){ //change this to url2 from url3
String GateStatus = client->getResponseBody();
String SGateStatus = GateStatus.substring(12, 13);
Serial.println("writing to pin12 --- " + SGateStatus);
//delete client;
//client = nullptr;

if (SGateStatus == "1") {
      Val =1;
      Serial.println(SGateStatus + ": writing to " +ledPin);
      digitalWrite(ledPin, HIGH);
      
      delay(4000);
      digitalWrite(ledPin, LOW);
      Val =0;
      
      }
else{ 
  Val = 0;
  //digitalWrite(ledPin, LOW);
  }`

Your help would be much appreciated

Problem solved,
ESP32 doesn't like open client
Client must be reset and closed and fresh one starts