[E][WiFiGeneric.cpp:739] hostByName(): DNS Failed for api.pushbullet.com

Viewed 15

Cheers I would like you to help me with a problem. I made a simple project of a doorbell using a ESP32 that works by push notification. And everything works fine until after several days these errors appear.The function of the project is that when you press a button. The ESP32 card sends via internet and an api, a notification to the user's cell phone that someone is at the door

I am using this code thanks for your help

#include<WiFi.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
unsigned long tiempo1=0;
unsigned long tiempo2=0;
unsigned long tiemposegundos=0;
const char* ssid="*****";
const char* password="*******";

int pinBoton=15;
int cont12=0;
const char* apiKey="*************";


void setup() {

Serial.begin(115200);
tiempo1=millis();
WiFi.begin(ssid,password);
Serial.print("Conectado");
while(WiFi.status() != WL_CONNECTED) {
  Serial.print(".");
  delay(100);
  cont12=cont12+1;
  Serial.print(cont12);
  if (cont12==140){
    ESP.restart();}
}
Serial.println("Conectado");
pinMode(pinBoton,INPUT_PULLUP);
}
void loop() {
  tiempo2 = millis();
  if(tiempo2 > (tiempo1+1000)){  //Si ha pasado 1 segundo ejecuta el IF
    tiempo1 = millis(); //Actualiza el tiempo actual
    tiemposegundos = tiempo1/1000;

  Serial.println(tiemposegundos);
  if(tiemposegundos> 104400){
    ESP.restart();
    }
  }
 if(digitalRead(pinBoton)== LOW){
  Serial.println("Presionado");
  enviarMensaje("Puerta ","Alguien ha tocado el timbre");
  delay(2000);
  }
  delay(100);
}
const char* host="api.pushbullet.com";
void enviarMensaje(String titulo,String mensaje) {
  WiFiClientSecure client;
  client.setInsecure();
  if(!client.connect(host,443)){
    Serial.println("No se pudo conectar con el servidor");
    return;
  }


  
String url = "/v2/pushes";
  String message = "{\"type\": \"note\", \"title\": \""+titulo+"\", \"body\": \""+mensaje+"\"}\r\n";
  Serial.print("requesting URL: ");
  Serial.println(url);
  //send a simple note
  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Authorization: Bearer " + apiKey + "\r\n" +
               "Content-Type: application/json\r\n" +
               "Content-Length: " +
               String(message.length()) + "\r\n\r\n");
  client.print(message);

  delay(2000);
  while (client.available() == 0);

  while (client.available()) {
    String line = client.readStringUntil('\n');
    Serial.println(line);
  }  

    }
0 Answers
Related