1

fatal error timeout and unable to connect to thingspeak for fetching data sent via google assistant (ifttt)

#include <LiquidCrystal.h> 
#include <SoftwareSerial.h> 

//ESP is connected to 12 and 13 pin of Arduino
SoftwareSerial ESP(2,3); 
LiquidCrystal lcd(13,12,11,10,9,8);

String sendData = "GET /channels/ 863136/fields /1/last.json?api_key=IZ0FK39UJ9MBXHME&results=2";

// Initialize a null string variable 
String output = ""; 
#define Relay1 6
#define Relay2 7

void setup() 
{
  pinMode(Relay1,OUTPUT);
  pinMode(Relay2,OUTPUT);

  //Initialise 16*2 LCD
  lcd.begin(16, 2);
  lcd.print(" Google assist  ");  
  lcd.setCursor(0, 1);
  lcd.print("using ESP8266-01");  
  delay(2000);

  Serial.begin (9600);
  delay(100);
  ESP.begin(9600);

  ESP_talk("AT",1000);
  ESP_talk("AT+RST",1000);
  ESP_talk("AT+CWMODE=1",5000);

  lcd.clear();
  lcd.print("connecting WiFi..");

  ESP_talk("AT+CWJAP=\"AntO\",\"2231anto\"",10000);

  lcd.print("Wifi Connected");
  Serial.println("Wifi Connected"); 
  delay(1000);  

  lcd.clear();
}

void loop() 
{
  // Establishing TCP connection
  String cmd = "AT+CIPSTART=\"TCP\",\"";   
  // AT+CIPSTART=4,"TCP","google.com",80

  cmd += "184.106.153.149";   //  api.thingspeak.com
  cmd += "\",80";   // port 80
  ESP_talk(cmd,1000);
  delay(100); 

  ESP_talk("AT+CIPSEND=76",1000);  
  delay(100);

  output = "";
  ESP_talk(sendData,1000);
  delay(100);

  char incoming_value=output[126];
  Serial.print("incoming_value is : ");   
  Serial.println(incoming_value);
  lcd.clear();
  lcd.print("Listning...."); //Intro Message line 1
  lcd.setCursor(0, 1);

  if (incoming_value == '0') //light should be off
  {
    lcd.print("Light is ON :-( " ); 
    digitalWrite(Relay1,LOW);
  }
  if (incoming_value == '1') //light should be off
  {
    lcd.print(":-) Light is OFF"); 
    digitalWrite(Relay1,HIGH);
  }

  if (incoming_value == '2') //light should be off
  {
    lcd.print("FAN is ON:-(    " ); 
    digitalWrite(Relay2,HIGH);
  }

  if (incoming_value == '3') //light should be off
  {
    lcd.print(":-) Fan is OFF  "); 
    digitalWrite(Relay2,LOW);
  } 
}

void ESP_talk(String AT_cmd, const int timeout)
{
  Serial.print("Sent: ");
  Serial.print(AT_cmd);
  ESP.println(AT_cmd); //print to ESP through software serial 
  Serial.println("");//Move to next line 

  long int time = millis();

  output=""; //clear the string

  while ( (time + timeout) > millis())
  {
    while (ESP.available())
    {
      char i = ESP.read(); // read one char 
      output += i; //Combine char to string 
    }
  }

  Serial.println("Received: ");
  Serial.print(output);

}

error :Arduino: 1.8.7 (Windows 7), Board: "Generic ESP8266 Module, 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), ck, 26 MHz, 40MHz, DOUT (compatible), 512K (no SPIFFS), 2, nonos-sdk 2.2.1 (legacy), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Sketch uses 269556 bytes (53%) of program storage space. Maximum is 499696 bytes. Global variables use 27764 bytes (33%) of dynamic memory, leaving 54156 bytes for local variables. Maximum is 81920 bytes. esptool.py v2.6 2.6 esptool.py v2.6 Serial port COM8 Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last): raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error)) esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

  • thanks for reminding and it is updated now – Supreet Nov 4 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.