Fix mostly comments

This commit is contained in:
sqozz 2018-11-17 21:59:00 +01:00
parent 9468622c3e
commit f0cf258ebd

View file

@ -9,6 +9,9 @@
#include <CertStoreBearSSL.h> #include <CertStoreBearSSL.h>
#include <FS.h> #include <FS.h>
// TODO: figure out how these freakin summertime works
// best would be some kind of automatic change
#define DEVICE_NAME "OTA TEST DEVICE" #define DEVICE_NAME "OTA TEST DEVICE"
#define TZ 1 // (utc+) TZ in hours #define TZ 1 // (utc+) TZ in hours
#define DST_MN 0 // use 60mn for summer time in some countries #define DST_MN 0 // use 60mn for summer time in some countries
@ -21,6 +24,7 @@ BearSSL::CertStore certStore;
WiFiManager wifiManager; WiFiManager wifiManager;
String config_password; String config_password;
// Copy&Pasted code from the esp core example based on BeadSSL
class SPIFFSCertStoreFile : public BearSSL::CertStoreFile { class SPIFFSCertStoreFile : public BearSSL::CertStoreFile {
public: public:
SPIFFSCertStoreFile(const char *name) { SPIFFSCertStoreFile(const char *name) {
@ -94,8 +98,7 @@ void setup() {
int numCerts = certStore.initCertStore(&certs_idx, &certs_ar); int numCerts = certStore.initCertStore(&certs_idx, &certs_ar);
Serial.print(F("Number of CA certs read: ")); Serial.println(numCerts); Serial.print(F("Number of CA certs read: ")); Serial.println(numCerts);
if (numCerts == 0) { if (numCerts == 0) {
Serial.println(F("No certs found. Did you run certs-from-mozill.py and upload the SPIFFS directory before running?")); Serial.println(F("No certs found. HTTPS requests will most likely fail."));
// TODO: bailout?
} }
if (SPIFFS.exists("/config_password.txt")) { if (SPIFFS.exists("/config_password.txt")) {
@ -108,13 +111,12 @@ void setup() {
} }
wifiManager.autoConnect(DEVICE_NAME, config_password.c_str()); wifiManager.autoConnect(DEVICE_NAME, config_password.c_str());
} else { } else {
Serial.println(F("Failed to find file. Upload config_password.txt with the configuration password included")); Serial.println(F("Failed to find AP password file in SPIFFS. Refusing to set up the wifi manager in an usecure way. Upload config_password.txt with the configuration password included"));
// TODO: bailout?
} }
} }
void loop() { void loop() {
checkUpdate(); checkUpdate(); // Checks for updates and applies it if available
delay(10000); delay(10000);
} }
@ -140,9 +142,6 @@ void checkUpdate() {
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW); ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, "https://iotupdates.companioncu.be/update"); t_httpUpdate_return ret = ESPhttpUpdate.update(client, "https://iotupdates.companioncu.be/update");
// Or:
//t_httpUpdate_return ret = ESPhttpUpdate.update(client, "server", 443, "file.bin");
switch (ret) { switch (ret) {
case HTTP_UPDATE_FAILED: case HTTP_UPDATE_FAILED: