Skip to content

Commit

Permalink
Added available space on SPIFFS in status
Browse files Browse the repository at this point in the history
  • Loading branch information
rneurink committed Aug 8, 2017
1 parent 3431b78 commit 5b96253
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
11 changes: 9 additions & 2 deletions data/auth/settings.htm
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ <h6 class="text-muted">Type your Wi-Fi Network's SSID or Scan for nerby Wireless
</div>
</div></td>
</tr>
<tr>
<th>Free SPIFFS</th>
<td>
<div class='progress progress-striped' style="margin-bottom: 0 !important;">
<div id="spiffs" class="progress-bar progress-bar-warning" role="progressbar">
Progress
</div>
</div></td>
</tr>
</table>
</div>
</div>
Expand Down Expand Up @@ -228,10 +237,8 @@ <h6 class="text-muted">Click on links and choose your backup file to restore.</h
</div>
<div class="col-sm-6">
<legend>Clear Log</legend>
</div>
<div class="alert alert-danger"><strong>Warning!</strong> This will delete all logs.</div>
<button id="clearlog" type="button" class="btn btn-primary btn-xs" onclick="clearLog()">Clear Log</button>
</div>
<br>
</div>
<div class="col-sm-6">
Expand Down
12 changes: 12 additions & 0 deletions data/auth/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,13 @@ function listStats(obj) {
document.getElementById("cpu").innerHTML = obj.cpu + " Mhz";
document.getElementById("heap").innerHTML = obj.heap + " Bytes";
document.getElementById("heap").style.width = (obj.heap * 100) / 81920 + "%";
colorStatusbar(document.getElementById("heap"));
document.getElementById("flash").innerHTML = obj.availsize + " Bytes";
document.getElementById("flash").style.width = (obj.availsize * 100) / 1044464 + "%";
colorStatusbar(document.getElementById("flash"));
document.getElementById("spiffs").innerHTML = obj.availspiffs + " Bytes";
document.getElementById("spiffs").style.width = (obj.availspiffs *100) / obj.spiffssize + "%";
colorStatusbar(document.getElementById("spiffs"));
document.getElementById("ssidstat").innerHTML = obj.ssid;
document.getElementById("ip").innerHTML = obj.ip;
document.getElementById("gate").innerHTML = obj.gateway;
Expand All @@ -198,6 +203,13 @@ function listStats(obj) {
document.getElementById("mac").innerHTML = obj.mac;
}

function colorStatusbar(ref) {
var percentage = ref.style.width.slice(0,-1);
if (percentage > 50) ref.className = "progress-bar progress-bar-success";
else if (percentage > 25) ref.className = "progress-bar progress-bar-warning";
else ref.class="progress-bar progress-bar-danger";
}

function clearLog() {
websock.send("{\command\":\"clearlog\"}");
var x = confirm("This will remove all logs. Are you sure?");
Expand Down
9 changes: 8 additions & 1 deletion esp-rfid.ino
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,11 @@ void sendStatus() {
JsonObject& root = jsonBuffer.createObject();
int mode = WiFi.getMode(); //const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };

FSInfo fsinfo;
if (!SPIFFS.info(fsinfo)) {
Serial.print(F("[ WARN ] Error getting info on SPIFFS"));
}

struct ip_info info;

if (mode == 1) { //Station mode
Expand All @@ -810,7 +815,7 @@ void sendStatus() {
struct softap_config conf;
wifi_softap_get_config(&conf);
root["ssid"] = String(reinterpret_cast<char*>(conf.ssid));
root["dns"] = "";
root["dns"] = printIP(WiFi.softAPIP()); //TODO: Get dns from config or info

This comment has been minimized.

Copy link
@omersiar

omersiar Aug 9, 2017

inAPMode we are the only DNS Server in Network. It's safe to use WiFi.softAPIP() since this is the only DNS server to respond queries. Good work by the way

root["mac"] = WiFi.softAPmacAddress();
}
IPAddress ipaddr = IPAddress(info.ip.addr);
Expand All @@ -825,6 +830,8 @@ void sendStatus() {
root["chipid"] = String(ESP.getChipId(), HEX);
root["cpu"] = ESP.getCpuFreqMHz();
root["availsize"] = ESP.getFreeSketchSpace();
root["availspiffs"] = fsinfo.totalBytes - fsinfo.usedBytes;
root["spiffssize"] = fsinfo.totalBytes;

size_t len = root.measureLength();
AsyncWebSocketMessageBuffer * buffer = ws.makeBuffer(len); // creates a buffer (len + 1) for you.
Expand Down

0 comments on commit 5b96253

Please sign in to comment.