Skip to content

Commit c02c390

Browse files
authored
Replace github OTA update over MQTT with settings in user_config. (1technophile#976)
1 parent 329f7b8 commit c02c390

File tree

3 files changed

+49
-66
lines changed

3 files changed

+49
-66
lines changed

main/Ota_github.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

main/User_config.h

100755100644
Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,11 @@ const byte subnet[] = {255, 255, 255, 0};
7474

7575
#if defined(ESP8266) || defined(ESP32) // for nodemcu, weemos and esp8266
7676
//# define ESPWifiManualSetup true //uncomment you don't want to use wifimanager for your credential settings on ESP
77-
//# define MQTT_HTTPS_FW_UPDATE //uncomment to enable updating via mqtt message.
7877
#else // for arduino boards
7978
const byte ip[] = {192, 168, 1, 99};
8079
const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield mac adress
8180
#endif
8281

83-
#ifndef NTP_SERVER
84-
# define NTP_SERVER "pool.ntp.org"
85-
#endif
86-
87-
#ifdef MQTT_HTTPS_FW_UPDATE
88-
# if defined(ESP8266) || defined(ESP32)
89-
//If used, this should be set to the root CA certificate of the server hosting the firmware.
90-
// The certificate must be in PEM ascii format
91-
const char* https_fw_server_cert PROGMEM = R"EOF("
92-
-----BEGIN CERTIFICATE-----
93-
...
94-
-----END CERTIFICATE-----
95-
")EOF";
96-
# ifndef MQTT_HTTPS_FW_UPDATE_USE_PASSWORD
97-
# define MQTT_HTTPS_FW_UPDATE_USE_PASSWORD 1 // Set this to 0 if not using TLS connection to MQTT broker to prevent clear text passwords being sent.
98-
# endif
99-
# else
100-
# error "only ESP8266 and ESP32 support MQTT_HTTPS_FW_UPDATE"
101-
# endif
102-
#endif
103-
10482
//#define ESP32_ETHERNET=true // Uncomment to use Ethernet module on OLIMEX ESP32 Ethernet gateway
10583

10684
#if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266
@@ -157,9 +135,6 @@ const char* https_fw_server_cert PROGMEM = R"EOF("
157135
#ifndef MQTT_PORT
158136
# define MQTT_PORT "1883"
159137
#endif
160-
#ifndef MQTT_SECURE_DEFAULT
161-
# define MQTT_SECURE_DEFAULT false
162-
#endif
163138

164139
#if defined(ESP8266) || defined(ESP32)
165140
// The root ca certificate used for validating the MQTT broker
@@ -172,6 +147,51 @@ const char* certificate PROGMEM = R"EOF("
172147

173148
# define ATTEMPTS_BEFORE_BG 10 // Number of wifi connection attempts before going to BG protocol
174149
# define ATTEMPTS_BEFORE_B 20 // Number of wifi connection attempts before going to B protocol
150+
151+
# ifndef NTP_SERVER
152+
# define NTP_SERVER "pool.ntp.org"
153+
# endif
154+
155+
# ifndef MQTT_SECURE_DEFAULT
156+
# define MQTT_SECURE_DEFAULT false
157+
# endif
158+
159+
//# define MQTT_HTTPS_FW_UPDATE //uncomment to enable updating via mqtt message.
160+
161+
# ifdef MQTT_HTTPS_FW_UPDATE
162+
// If used, this should be set to the root CA certificate of the server hosting the firmware.
163+
// The certificate must be in PEM ascii format.
164+
// The default certificate is for github.
165+
const char* OTAserver_cert PROGMEM = R"EOF("
166+
-----BEGIN CERTIFICATE-----
167+
MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs
168+
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
169+
d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j
170+
ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL
171+
MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3
172+
LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug
173+
RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm
174+
+9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW
175+
PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM
176+
xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB
177+
Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3
178+
hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg
179+
EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF
180+
MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA
181+
FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec
182+
nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z
183+
eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF
184+
hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2
185+
Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
186+
vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep
187+
+OkuE6N36B9K
188+
-----END CERTIFICATE-----
189+
")EOF";
190+
191+
# ifndef MQTT_HTTPS_FW_UPDATE_USE_PASSWORD
192+
# define MQTT_HTTPS_FW_UPDATE_USE_PASSWORD 1 // Set this to 0 if not using TLS connection to MQTT broker to prevent clear text passwords being sent.
193+
# endif
194+
# endif
175195
#endif
176196

177197
/*------------------DEEP SLEEP parameters ------------------*/

main/main.ino

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ bool disc = true; // Auto discovery with Home Assistant convention
174174
#endif
175175
unsigned long timer_led_measures = 0;
176176
static void* eClient = nullptr;
177+
#if defined(ESP8266) || defined(ESP32)
177178
static bool mqtt_secure = MQTT_SECURE_DEFAULT;
178179
static String mqtt_cert = "";
180+
#endif
179181

180182
#ifdef ESP32
181183
# include <ArduinoOTA.h>
@@ -1660,10 +1662,6 @@ void receivingMQTT(char* topicOri, char* datacallback) {
16601662
}
16611663

16621664
#ifdef MQTT_HTTPS_FW_UPDATE
1663-
# include <WiFiClientSecure.h>
1664-
1665-
# include "Ota_github.h"
1666-
16671665
# ifdef ESP32
16681666
# include "zzHTTPUpdate.h"
16691667
# elif ESP8266
@@ -1739,22 +1737,12 @@ void MQTTHttpsFWUpdate(char* topicOri, JsonObject& HttpsFwUpdateData) {
17391737
}
17401738

17411739
# ifdef ESP32
1742-
if (strstr(url, "github") != 0) {
1743-
update_client.setCACert(_github_cert);
1744-
} else {
1745-
update_client.setCACert(https_fw_server_cert);
1746-
}
1747-
1740+
update_client.setCACert(OTAserver_cert);
17481741
update_client.setTimeout(12);
17491742
httpUpdate.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
17501743
result = httpUpdate.update(update_client, url);
17511744
# elif ESP8266
1752-
if (strstr(url, "github") != 0) {
1753-
caCert.append(_github_cert);
1754-
} else {
1755-
caCert.append(https_fw_server_cert);
1756-
}
1757-
1745+
caCert.append(OTAserver_cert);
17581746
update_client.setTrustAnchors(&caCert);
17591747
update_client.setTimeout(12000);
17601748
ESPhttpUpdate.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);

0 commit comments

Comments
 (0)