jnsdbr / esp32-ota-update-mqtt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question]: Is it possible to send bin via mqtt-payload?

OllisGit opened this issue · comments

Did you think it is possible to send the bin-file via a base64 encoded payload and then the update mechanism works.
Maybe you tried this before, do you have expirences on that?

BR
Olli

commented

This is something I haven't actually tried (but considered). I know that the ESP32 SDK features base64 decoding, but I don't know if it can handle such large strings (e.g. the blink example .bin is about 138kb in size).

bool canBegin = Update.begin(size);
		Serial.println("Can Begin");
		if (canBegin) {
			Serial.println("Begin OTA. This may take 2 - 5 mins to complete. Things might be quite for a while.. Patience!");
			size_t written = Update.writeStream(*pub.payload_stream());

			if (written == size) {
				Serial.println("Written : " + String(written) + " successfully");
			}
			else {
				Serial.println("Written only : " + String(written) + "/" + String(size) + ". Retry?");
				// retry??
			}

			if (Update.end()) {
				Serial.println("OTA done!");
				if (Update.isFinished()) {
					Serial.println("Update successfully completed. Rebooting.");
					ESP.restart();
					delay(10000);
				}
				else {
					Serial.println("Update not finished? Something went wrong!");
				}
			}
			else {
				Serial.println("Error Occurred. Error #: " + String(Update.getError()));
			}
		}
		else {
			// not enough space to begin OTA
			// Understand the partitions and
			// space availability
			Serial.println("Not enough space to begin OTA");
		}