Topic: Пример выключателя - где ошибся?
Здравствуйте. Сделал все по примеру с сайта, кнопка реле включает, но не выключает. Не подскажете где ошибка?
ESP8266 12F
/*
-- New project --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 2.3.1 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.0.1 or later version;
- for iOS 1.1.0 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// определение режима соединения и подключение библиотеки RemoteXY
#define REMOTEXY_MODE__ESP8266WIFI_LIB
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <RemoteXY.h>
// NETWORK: Static IP details...
IPAddress ip(192, 168, 0, 100);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
// настройки соединения
#define REMOTEXY_WIFI_SSID "NETGEAR"
#define REMOTEXY_WIFI_PASSWORD "zorg1498prost12ant498"
#define REMOTEXY_SERVER_PORT 6377
// конфигурация интерфейса
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,4,0,0,0,87,0,6,4,1,
2,0,4,7,55,14,1,208,146,208,
186,208,187,46,32,49,0,79,70,70,
0,2,0,4,30,55,14,1,208,146,
208,186,208,187,46,32,50,0,79,70,
70,0,2,0,4,53,55,15,1,208,
146,208,186,208,187,46,32,51,0,79,
70,70,0,2,0,5,77,54,15,1,
208,146,208,186,208,187,46,32,52,0,
79,70,70,0 };
// структура определяет все переменные вашего интерфейса управления
struct {
// input variable
uint8_t switch_3; // =1 если переключатель включен и =0 если отключен
uint8_t switch_4; // =1 если переключатель включен и =0 если отключен
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
// Подключаем реле к ногам:
#define BUTTON_1 14 //Pin for knopka 1
#define BUTTON_2 5 //Pin for knopkay2
#define rele3 12 //Pin for reley3
#define rele4 13 //Pin for reley4
int currentValue1, prevValue1;
int currentValue2, prevValue2;
const char* host = "Doom1-webupdate";
const char* ssid = "NETGEAR";
const char* password = "zorg1498prost12ant498";
ESP8266WebServer server(80);
const char* serverIndex = "<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>";
void setup()
{
// Начало серверной части
Serial.begin(115200);
Serial.println();
Serial.println("Booting Sketch...");
WiFi.mode(WIFI_AP_STA);
// Static IP Setup Info Here...
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
if(WiFi.waitForConnectResult() == WL_CONNECTED){
MDNS.begin(host);
server.on("/", HTTP_GET, [](){
server.sendHeader("Connection", "close");
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(200, "text/html", serverIndex);
});
server.on("/update", HTTP_POST, [](){
server.sendHeader("Connection", "close");
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(200, "text/plain", (Update.hasError())?"FAIL":"OK");
ESP.restart();
},[](){
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START){
Serial.setDebugOutput(true);
WiFiUDP::stopAll();
Serial.printf("Update: %s\n", upload.filename.c_str());
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if(!Update.begin(maxSketchSpace)){//start with max available size
Update.printError(Serial);
}
} else if(upload.status == UPLOAD_FILE_WRITE){
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize){
Update.printError(Serial);
}
} else if(upload.status == UPLOAD_FILE_END){
if(Update.end(true)){ //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
Serial.setDebugOutput(false);
}
yield();
});
server.begin();
MDNS.addService("http", "tcp", 80);
Serial.printf("Прошивка завершена.Наш IP", host);
Serial.println(WiFi.localIP());
} else {
Serial.println("WiFi Failed");
}
// Конец серверной части
RemoteXY_Init (); // Мои данные
pinMode(rele3, OUTPUT);
pinMode(rele4, OUTPUT);
pinMode(BUTTON_1, INPUT);
pinMode(BUTTON_2, INPUT);
RemoteXY.switch_3=0;
RemoteXY.switch_4=0;
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
/*Защита от дребезга кнопок*/
currentValue1 = digitalRead(BUTTON_1);
if (currentValue1 != prevValue1) {
// Что-то изменилось, здесь возможна зона неопределенности
// Делаем задержку
delay(10);
// А вот теперь спокойно считываем значение, считая, что нестабильность исчезла
currentValue1 = digitalRead(BUTTON_1);
}
prevValue1 = currentValue1;
currentValue2 = digitalRead(BUTTON_2);
if (currentValue2 != prevValue2) {
// Что-то изменилось, здесь возможна зона неопределенности
// Делаем задержку
delay(10);
// А вот теперь спокойно считываем значение, считая, что нестабильность исчезла
currentValue2 = digitalRead(BUTTON_2);
}
prevValue2 = currentValue2;
/*Управление реле через функцию RemoteXY*/
if (currentValue1==HIGH&&(RemoteXY.switch_3==1)) { //если нажата кнопка и поле структуры RemoteXY.switch_3 равно 1,
//то выключаем освещение присвоив полю структуры RemoteXY.switch_3 значение 0
RemoteXY.switch_3=0;
}
if (currentValue1==HIGH&&(RemoteXY.switch_3==0)) { //тут наоборот, если нажата кнопка, а реле выключено,
//то включаем реле посредством присваивания полю структуры RemoteXY.switch_3 значения 1
RemoteXY.switch_3=1;
}
digitalWrite(rele3, (RemoteXY.switch_3==0)?LOW:HIGH); //если поле структуры RemoteXY.switch_1 равно нулю, то свет выключен, если 1, то включен
if (currentValue2==HIGH&&(RemoteXY.switch_4==1)) { //если нажата кнопка и поле структуры RemoteXY.switch_1 равно 1,
//то выключаем освещение присвоив полю структуры RemoteXY.switch_4 значение 0
RemoteXY.switch_4=0;
}
if (currentValue2==HIGH&&(RemoteXY.switch_4==0)) { //тут наоборот, если нажата кнопка, а реле выключено,
//то включаем реле посредством присваивания полю структуры RemoteXY.switch_4 значения 1
RemoteXY.switch_4=1;
}
digitalWrite(rele4, (RemoteXY.switch_4==0)?LOW:HIGH);//если поле структуры RemoteXY.switch_1 равно нулю, то свет выключен, если 1, то включен
}