Skip to content

Commit

Permalink
SPIFFS OTA added
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbig committed May 27, 2016
1 parent 51f71b3 commit eafc8f7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
4 changes: 3 additions & 1 deletion converter/convertkml.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@
$output = fopen($_SERVER['argv'][2], 'w');
writePois($output, $pois);
fclose($output);
echo 'done';
echo 'done', "\n";

$version = time() - strtotime('2000-01-01 00:00:00');

$output = fopen(dirname($_SERVER['argv'][2]).'/version.dat', 'w');
fwrite($output, pack('L', $version));
fclose($output);

echo 'New version is: 0x', dechex($version), "\n";

exit();

/**
Expand Down
1 change: 1 addition & 0 deletions data/version.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
)��
21 changes: 17 additions & 4 deletions ota/index.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

$file = 'tiveda.ino.nodemcu.bin';
$fileSketch = 'tiveda.ino.nodemcu.bin';
$fileSpiffs = 'tiveda.spiffs.bin';
$version = "1.2";
$mapVersion = 0x1edba629;

file_put_contents('/tmp/esp_debug.txt', print_r($_SERVER, true));

if (
empty($_SERVER['HTTP_X_ESP8266_VERSION']) ||
empty($_SERVER['HTTP_X_ESP8266_MODE']) ||
empty($_GET['id'])
)
{
Expand All @@ -17,9 +20,19 @@
}


if (version_compare($_SERVER['HTTP_X_ESP8266_VERSION'], $version) >=0 || !is_readable($file)) {
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
exit();
if ($_SERVER['HTTP_X_ESP8266_MODE'] == 'spiffs') {
$file = $fileSpiffs;
if ($mapVersion <= hexdec($_SERVER['HTTP_X_ESP8266_VERSION']) || !is_readable($file)) {
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
exit();
}
} else {
$file = $fileSketch;
if (version_compare($_SERVER['HTTP_X_ESP8266_VERSION'], $version) >=0 || !is_readable($file)) {
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
exit();
}

}

header('Content-Type: application/octet-stream');
Expand Down
32 changes: 24 additions & 8 deletions tiveda.ino
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,33 @@ void performOTA() {

#ifdef DEBUG
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(F("WiFi connected"));
Serial.println(F("IP address: "));
Serial.println(WiFi.localIP());

Serial.print("Starting OTA...");
Serial.print(F("Starting OTA..."));
#endif

// Update application code
t_httpUpdate_return ret = ESPhttpUpdate.update(url, FPSTR(VERSION));
checkErrors(ret);

#ifdef DEBUG
Serial.print(F("Updating map..."));
#endif
// Update application SPIFFS
ret = ESPhttpUpdate.updateSpiffs(url, String(mapVersion, HEX));
checkErrors(ret);



WiFi.mode(WIFI_OFF); // Turn off wifi to save on power
}

/**
* Parse errors from httpupdate
*/
void checkErrors(t_httpUpdate_return ret) {
switch (ret) {
case HTTP_UPDATE_FAILED:
#ifdef DEBUG
Expand All @@ -295,17 +313,15 @@ void performOTA() {

case HTTP_UPDATE_NO_UPDATES:
#ifdef DEBUG
Serial.println("no update found");
Serial.println(F("no update found"));
#endif
break;

case HTTP_UPDATE_OK:
#ifdef DEBUG
Serial.println("update successfull");
Serial.println(F("update successfull"));
#endif
break;
}

WiFi.mode(WIFI_OFF); // Turn off wifi to save on power
}
}

0 comments on commit eafc8f7

Please sign in to comment.