fix shelly 1
This commit is contained in:
parent
b1b8c4925b
commit
b16766c65e
@ -18,7 +18,8 @@ const int httpsPort = 443;
|
|||||||
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";
|
||||||
|
|
||||||
const char* fingerprint = "a9 9b 91 f5 6b 8f da 18 d8 3b b3 99 91 5d f1 7e 96 00 e4 04";
|
const char* fingerprint = "";
|
||||||
|
const char* host2 = "dev.steelants.cz";
|
||||||
const char* url2 = "/vasek/home/update.php";
|
const char* url2 = "/vasek/home/update.php";
|
||||||
|
|
||||||
String content;
|
String content;
|
||||||
@ -50,7 +51,6 @@ void setup() {
|
|||||||
pinMode(RELAY, OUTPUT);
|
pinMode(RELAY, OUTPUT);
|
||||||
state = EEPROM.read(0);
|
state = EEPROM.read(0);
|
||||||
digitalWrite(RELAY, state);
|
digitalWrite(RELAY, state);
|
||||||
detachInterrupt(digitalPinToInterrupt(SWITCH));
|
|
||||||
attachInterrupt(digitalPinToInterrupt(SWITCH), handleInterrupt, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(SWITCH), handleInterrupt, CHANGE);
|
||||||
//wifi
|
//wifi
|
||||||
if (ssid != "") {
|
if (ssid != "") {
|
||||||
@ -59,15 +59,17 @@ void setup() {
|
|||||||
WiFi.begin(ssid, pasw);
|
WiFi.begin(ssid, pasw);
|
||||||
conf = wifiVerify(20);
|
conf = wifiVerify(20);
|
||||||
if (conf) {
|
if (conf) {
|
||||||
|
configTime(3 * 3600, 0, "pool.ntp.org");
|
||||||
WiFiClientSecure client;
|
WiFiClientSecure client;
|
||||||
Serial.print("connecting to ");
|
Serial.print("connecting to ");
|
||||||
Serial.println(host);
|
Serial.println(host2);
|
||||||
if (!client.connect(host, httpsPort)) {
|
client.setInsecure();
|
||||||
|
if (!client.connect(host2, httpsPort)) {
|
||||||
Serial.println("connection failed");
|
Serial.println("connection failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.verify(fingerprint, host)) {
|
if (client.verify(fingerprint, host2)) {
|
||||||
Serial.println("certificate matches");
|
Serial.println("certificate matches");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("certificate doesn't match");
|
Serial.println("certificate doesn't match");
|
||||||
@ -79,12 +81,35 @@ void setup() {
|
|||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
auto ret = ESPhttpUpdate.update(client, host, url2);
|
auto ret = ESPhttpUpdate.update(client, host2, url2);
|
||||||
|
delay(500);
|
||||||
|
switch(ret) {
|
||||||
|
case HTTP_UPDATE_FAILED:
|
||||||
|
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTTP_UPDATE_NO_UPDATES:
|
||||||
|
Serial.println("HTTP_UPDATE_NO_UPDATES");
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTTP_UPDATE_OK:
|
||||||
|
Serial.println("HTTP_UPDATE_OK");
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
delay(500);
|
||||||
|
Serial.println("Update proběhl!");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
jsonContent = {};
|
jsonContent = {};
|
||||||
jsonContent["token"] = apiToken;
|
jsonContent["token"] = apiToken;
|
||||||
jsonContent["values"]["on/off"]["value"] = (int)state;
|
jsonContent["values"]["on/off"]["value"] = (String)state;
|
||||||
sendDataToWeb();
|
sendDataToWeb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -102,12 +127,13 @@ void loop() {
|
|||||||
jsonContent = {};
|
jsonContent = {};
|
||||||
jsonContent["token"] = apiToken;
|
jsonContent["token"] = apiToken;
|
||||||
requestJson = "";
|
requestJson = "";
|
||||||
jsonContent["values"]["on/off"]["value"] = (int)state;
|
jsonContent["values"]["on/off"]["value"] = (String)state;
|
||||||
digitalWrite(RELAY, state);
|
digitalWrite(RELAY, state);
|
||||||
EEPROM.write(0, state);
|
EEPROM.write(0, state);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
sendDataToWeb();
|
sendDataToWeb();
|
||||||
buttonActive = false;
|
buttonActive = false;
|
||||||
|
delay(500);
|
||||||
} else {
|
} else {
|
||||||
loadDataFromWeb();
|
loadDataFromWeb();
|
||||||
}
|
}
|
||||||
@ -138,7 +164,6 @@ bool wifiVerify(int t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loadDataFromWeb() {
|
void loadDataFromWeb() {
|
||||||
delay(500);
|
|
||||||
jsonContent = {};
|
jsonContent = {};
|
||||||
jsonContent["token"] = apiToken;
|
jsonContent["token"] = apiToken;
|
||||||
requestJson = "";
|
requestJson = "";
|
||||||
@ -155,9 +180,13 @@ void loadDataFromWeb() {
|
|||||||
//configuration setup
|
//configuration setup
|
||||||
String hostName = jsonContent["device"]["hostname"];
|
String hostName = jsonContent["device"]["hostname"];
|
||||||
String requestState = jsonContent["state"];
|
String requestState = jsonContent["state"];
|
||||||
JsonObject object = jsonContent.as<JsonObject>();
|
if (!buttonActive) {
|
||||||
if (!object["value"].isNull()) {
|
|
||||||
state = (int)jsonContent["value"];
|
state = (int)jsonContent["value"];
|
||||||
|
Serial.println("state: " + (String)state);
|
||||||
|
digitalWrite(RELAY, state);
|
||||||
|
EEPROM.write(0, state);
|
||||||
|
EEPROM.commit();
|
||||||
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestState != "succes") {
|
if (requestState != "succes") {
|
||||||
@ -168,19 +197,6 @@ void loadDataFromWeb() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WiFi.hostname(hostName);
|
WiFi.hostname(hostName);
|
||||||
Serial.println("state: " + (String)state;
|
|
||||||
if (!buttonActive) {
|
|
||||||
if (state == 1) {
|
|
||||||
Serial.println("ON");
|
|
||||||
} else if (state == 0) {
|
|
||||||
Serial.println("OFF");
|
|
||||||
}
|
|
||||||
digitalWrite(RELAY, state);
|
|
||||||
EEPROM.write(0, state);
|
|
||||||
EEPROM.commit();
|
|
||||||
} else {
|
|
||||||
state = realState;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendDataToWeb() {
|
void sendDataToWeb() {
|
||||||
|
BIN
app/updater/3C71BF2BEA66.bin
Normal file
BIN
app/updater/3C71BF2BEA66.bin
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user