Ir ao conteúdo
  • Cadastre-se

Lorenzong

Membro Júnior
  • Posts

    1
  • Cadastrado em

  • Última visita

Reputação

0
  1. Olá, Pessoal, tudo bem? Estou tentando fazer um ESP-01 funcionar com a Alexa, usando as bibliotecas "ESP8266WiFi.h" <WiFiManager.h> <EEPROM.h> "fauxmoESP.h" , mas é o seguinte que acontece: Aparece o autoConnect então clico para conectar entra a tela de configuração onde coloco minha rede e senha e o nome do dispositivo. abro o aplicativo da Alexa ela reconhece novo dispositivo, mas quando entro na tela de controle diz que não está disponivel e não consigo acionar o relé. coloquei um botão para resetar e acionar o relé diretamente mas só funciona o reset. Desculpem mas eu tento fazer funcionar do jeito que quero juntando exemplos que acho na net. Agradeço muito pela ajuda e obrigado a todos. #include <Arduino.h> #ifdef ESP32 #include <WiFi.h> #else #include "ESP8266WiFi.h" #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager #include <EEPROM.h> #endif #include "fauxmoESP.h" #include <ESPAsyncTCP.h> //#define WIFI_SSID "Rede2" //Cambiar por tu WIFI SSID //#define WIFI_PASS "02584612345678joule" //Cambiar por tu WIFI password #define SERIAL_BAUDRATE 115200 #define BOT_TOKEN_LENGTH 10 #define D3 3 char NOME_ID[10]=""; /*const long debounce_delay = 30; long tempo_debounce = 0; int debounce_ok = 1; int leitura_anterior = 0; int leitura_anterior_db = 0; unsigned int currentMillis = 0;*/ long tempo_debounce2 = 0; int debounce_ok2 = 1; int leitura_anterior2 = 0; int leitura_anterior_db2 = 0; unsigned int currentMillis2 = 0; const long debounce_reset = 8000; char stado=0; fauxmoESP fauxmo; const int buttonPin = 2; #define RELAY_PIN 3 //flag for saving data bool shouldSaveConfig = false; //callback notifying us of the need to save config void saveConfigCallback () { Serial.println("Should save config"); shouldSaveConfig = true; } void readBotTokenFromEeprom(int offset){ for(int i = offset; i<BOT_TOKEN_LENGTH; i++ ){ NOME_ID[i] = EEPROM.read(i); } EEPROM.commit(); //setupSinricPro(); } void writeBotTokenToEeprom(int offset){ for(int i = offset; i<BOT_TOKEN_LENGTH; i++ ){ EEPROM.write(i, NOME_ID[i]); } EEPROM.commit(); } void setup() { pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); pinMode(buttonPin,INPUT); Serial.begin(SERIAL_BAUDRATE); EEPROM.begin(512); readBotTokenFromEeprom(0); Serial.println(NOME_ID); WiFiManager wifiManager; wifiManager.setSaveConfigCallback(saveConfigCallback); //Adding an additional config on the WIFI manager webpage for the bot token WiFiManagerParameter custom_bot_id("NOME", "NOME_ID",NOME_ID , 13); wifiManager.addParameter(&custom_bot_id); //If it fails to connect it will create a TELEGRAM-BOT access point wifiManager.autoConnect("LE-Connect"); strcpy(NOME_ID, custom_bot_id.getValue()); if (shouldSaveConfig) { writeBotTokenToEeprom(0); } fauxmo.createServer(true); // not needed, this is the default value fauxmo.setPort(80); // This is required for gen3 devices fauxmo.enable(true); // Fauxmo fauxmo.addDevice(NOME_ID); fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) { Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value); if ( (strcmp(device_name, NOME_ID) == 0) ) { Serial.println("RELAY 1 switched by Alexa"); //digitalWrite(RELAY_PIN, !digitalRead(RELAY_PIN)); if (state) { digitalWrite(RELAY_PIN, HIGH); } else { digitalWrite(RELAY_PIN, LOW); } } }); } void loop() { if (Serial.available() > 0) {///SE HOUVER DADOS NA SERIAL VAI PARA ROTINA DE TRATAMENTO //recebe_serial(); stado=Serial.read(); if(stado=='R'){// redefine para parametros inicias //Serial.println("Reset"); WiFi.disconnect(); //Serial.println("Dq"); delay(500); ESP.reset(); } } fauxmo.handle(); // pulso1(); pulso2(); } /*void pulso1() { int leitura_atual = digitalRead(buttonPin); if (leitura_atual != leitura_anterior) { tempo_debounce = millis(); debounce_ok = 1; } if (millis() - tempo_debounce > debounce_delay) { debounce_ok = 1; } if (debounce_ok == 1) { if (leitura_atual == 0 && leitura_anterior_db == 1) { digitalWrite(RELAY1, !digitalRead(RELAY1)); } leitura_anterior_db = leitura_atual; } leitura_anterior = leitura_atual; }*/ void pulso2() { int leitura_atual2 = digitalRead(buttonPin); if (leitura_atual2 != leitura_anterior2) { tempo_debounce2 = millis(); debounce_ok2 = 0; } if (millis() - tempo_debounce2 > debounce_reset) { debounce_ok2 = 1; } if (debounce_ok2 == 1) { if (leitura_atual2 == 0 && leitura_anterior_db2 == 1) { WiFi.disconnect(); delay(500); ESP.reset(); } leitura_anterior_db2 = leitura_atual2; } leitura_anterior2 = leitura_atual2; } RELE_ESP01_ALEXA.txt

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!