some test edit
This commit is contained in:
parent
029d75cd33
commit
a8daa51413
@ -14,15 +14,10 @@ String apiToken = "";
|
|||||||
const char* host = "http://dev.steelants.cz";
|
const char* host = "http://dev.steelants.cz";
|
||||||
const char* url = "/vasek/home/api.php";
|
const char* url = "/vasek/home/api.php";
|
||||||
|
|
||||||
IPAddress staticIpAddress;
|
|
||||||
IPAddress gatewayIpAddress;
|
|
||||||
IPAddress subnetIpAddress;
|
|
||||||
|
|
||||||
String content;
|
String content;
|
||||||
bool conf = false;
|
bool conf = false;
|
||||||
bool buttonActive = false;
|
bool buttonActive = false;
|
||||||
int state = 0;
|
int state = 0;
|
||||||
int realState = 0;
|
|
||||||
String requestJson = "";
|
String requestJson = "";
|
||||||
int unsuccessfulRounds = 0; //Unsucesful atmpt counter
|
int unsuccessfulRounds = 0; //Unsucesful atmpt counter
|
||||||
|
|
||||||
@ -48,22 +43,19 @@ void setup() {
|
|||||||
pinMode(RELAY, OUTPUT);
|
pinMode(RELAY, OUTPUT);
|
||||||
state = EEPROM.read(0);
|
state = EEPROM.read(0);
|
||||||
digitalWrite(RELAY, state);
|
digitalWrite(RELAY, state);
|
||||||
realState = state;
|
detachInterrupt(digitalPinToInterrupt(SWITCH));
|
||||||
attachInterrupt(digitalPinToInterrupt(SWITCH), handleInterrupt, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(SWITCH), handleInterrupt, CHANGE);
|
||||||
//wifi
|
//wifi
|
||||||
if (ssid != "") {
|
if (ssid != "") {
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
//Serial.println(WiFi.localIP());
|
|
||||||
//Serial.println("IP nastaveny z hodnot.");
|
|
||||||
//WiFi.config(staticIpAddress, gatewayIpAddress, subnetIpAddress);
|
|
||||||
WiFi.begin(ssid, pasw);
|
WiFi.begin(ssid, pasw);
|
||||||
conf = wifiVerify(20);
|
conf = wifiVerify(20);
|
||||||
if (conf) {
|
if (conf) {
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
jsonContent = {};
|
jsonContent = {};
|
||||||
jsonContent["token"] = apiToken;
|
jsonContent["token"] = apiToken;
|
||||||
jsonContent["values"]["on/off"]["value"] = (String)realState;
|
jsonContent["values"]["on/off"]["value"] = (int)state;
|
||||||
sendDataToWeb();
|
sendDataToWeb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -78,13 +70,12 @@ void loop() {
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
if (buttonActive) {
|
if (buttonActive) {
|
||||||
delay (500);
|
|
||||||
jsonContent = {};
|
jsonContent = {};
|
||||||
jsonContent["token"] = apiToken;
|
jsonContent["token"] = apiToken;
|
||||||
requestJson = "";
|
requestJson = "";
|
||||||
jsonContent["values"]["on/off"]["value"] = (String)realState;
|
jsonContent["values"]["on/off"]["value"] = (int)state;
|
||||||
digitalWrite(RELAY, realState);
|
digitalWrite(RELAY, state);
|
||||||
EEPROM.write(0, realState);
|
EEPROM.write(0, state);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
sendDataToWeb();
|
sendDataToWeb();
|
||||||
buttonActive = false;
|
buttonActive = false;
|
||||||
@ -97,8 +88,8 @@ void loop() {
|
|||||||
|
|
||||||
void handleInterrupt() {
|
void handleInterrupt() {
|
||||||
buttonActive = true;
|
buttonActive = true;
|
||||||
realState = !state;
|
state = !state;
|
||||||
digitalWrite(RELAY, realState);
|
digitalWrite(RELAY, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wifiVerify(int t) {
|
bool wifiVerify(int t) {
|
||||||
@ -146,17 +137,15 @@ void loadDataFromWeb() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WiFi.hostname(hostName);
|
WiFi.hostname(hostName);
|
||||||
Serial.println("state: " + (String)state + ", realState: " + (String)realState);
|
Serial.println("state: " + (String)state;
|
||||||
if (state != realState && !buttonActive) {
|
if (!buttonActive) {
|
||||||
if (state == 1 && realState == 0) {
|
if (state == 1) {
|
||||||
Serial.println("ON state: " + (String)state + ", realState: " + (String)realState);
|
Serial.println("ON");
|
||||||
realState = 1;
|
} else if (state == 0) {
|
||||||
} else {
|
|
||||||
Serial.println("OFF");
|
Serial.println("OFF");
|
||||||
realState = 0;
|
|
||||||
}
|
}
|
||||||
digitalWrite(RELAY, realState);
|
digitalWrite(RELAY, state);
|
||||||
EEPROM.write(0, realState);
|
EEPROM.write(0, state);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user