Skip to content

Commit

Permalink
Merge pull request #234 from boblemaire/staged
Browse files Browse the repository at this point in the history
Staged
  • Loading branch information
boblemaire authored Oct 12, 2019
2 parents 89b9fa2 + d73bc13 commit 844228e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Firmware/IotaWatt/CSVquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@ size_t CSVquery::readResult(uint8_t* buf, int len){
logReadKey(_newRec);
}

// Belt and suspenders,
// Make sure we are moving forward.

if(_newRec->UNIXtime <= _oldRec->UNIXtime){
_lastLine = true;
}

// If there is data or not skipping missing data,
// Generate a line.

Expand Down
2 changes: 2 additions & 0 deletions Firmware/IotaWatt/IotaWatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ extern IotaLog currLog;
extern IotaLog histLog;
extern RTC_PCF8523 rtc;
extern Ticker ticker;
extern Ticker logWDT;
extern messageLog msglog;

#define MS_PER_HOUR 3600000UL
Expand Down Expand Up @@ -309,6 +310,7 @@ void logTrace(void);
void NewService(uint32_t (*serviceFunction)(struct serviceBlock*), const uint8_t taskID=0);
void AddService(struct serviceBlock*);
uint32_t dataLog(struct serviceBlock*);
void datalogWDT();
uint32_t historyLog(struct serviceBlock*);
uint32_t statService(struct serviceBlock*);
uint32_t EmonService(struct serviceBlock*);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/IotaWatt/Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,4 @@ void setLedState(){
digitalWrite(redLed, HIGH);
}
}
}
}
1 change: 1 addition & 0 deletions Firmware/IotaWatt/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ IotaLog currLog(5,365); // current data log (1 year)
IotaLog histLog(60,3652); // history data log (10 years)
RTC_PCF8523 rtc; // Instance of RTC_PCF8523
Ticker ticker;
Ticker logWDT;
messageLog msglog; // Message log handler

// Define filename Strings of system files.
Expand Down
20 changes: 20 additions & 0 deletions Firmware/IotaWatt/dataLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@
// Write the record

currLog.write(logRecord);

// Logging data is the primary purpose of IoTaWatt.
// Set a WDT to make sure it continues.

logWDT.detach();
logWDT.attach(30, datalogWDT);

break;
}
}
Expand All @@ -156,6 +163,19 @@
return logRecord->UNIXtime;
}

/******************************************************************************
*
* The datalog WDT is set each time the datalog is updated. If it expires
* the datyalog is not being updated. The program may be stuck in a
* loop somewhere. Log a message and restart. The trace will provide
* diagnostic information.
*
* *****************************************************************************/

void datalogWDT(){
log("dataLog: datalog WDT - restarting");
ESP.restart();
}
/******************************************************************************
* logReadKey(iotaLogRecord) - read a keyed record from the combined log
*
Expand Down
2 changes: 1 addition & 1 deletion Firmware/IotaWatt/webServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ void handleQuery(){
int read = 0;
size_t size = 0;
trace(T_WEB,56);
while((read = query->readResult(buf+6, 1460-8)) && size < 32768){
while((read = query->readResult(buf+6, 1460-8)) && size < 100000){
trace(T_WEB,57);
sendChunk((char*)buf, read+6);
size += read;
Expand Down
1 change: 1 addition & 0 deletions SD/graph2.htm
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ <h3 id="title" class="text-left">Graph+</h3>
<option value="remove">Remove line</option>
</select>
<button id="copycsv" class="btn-default" title="Copy to clipboard"><span class="glyphicon glyphicon-copy"></span> Copy</button>
<button id="downloadcsv" class="btn-default" title="Download CSV file"><span class="glyphicon glyphicon-download"></span> Download</button>
</div>
<textarea readonly id="csv" rows=30></textarea>
</div>
Expand Down
17 changes: 14 additions & 3 deletions SD/graph2.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ function graph_resize() {
}

//********************************************************************************************
// CSV time-format, null-values, copy to clipboard
// CSV time-format, null-values, copy to clipboard, download
//********************************************************************************************

$("#csvtimeformat").change(function(){
Expand All @@ -445,6 +445,16 @@ $("#copycsv").click(function(){
document.execCommand("Copy");
});

$("#downloadcsv").click(function(){
var element = document.createElement("a");
element.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent($("#csv").html()));
element.setAttribute('download', "iotawatt_"+moment().format("YYYY-MM-DD_HHmm")+".csv");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
});

//********************************************************************************************
// Detail Lines - color, type(line/bar), fill, stack, decimals, scale
//********************************************************************************************
Expand Down Expand Up @@ -1119,7 +1129,6 @@ function build_CSV(){
}
}


//********************************************************************************************
// unitFormat - returns display string of val+units w/appropriate scaling and dp
// example 2406 Watts becomes "2.41 kW"
Expand Down Expand Up @@ -1164,6 +1173,7 @@ function unitFormat(val, unit)


$("#graph-select").change(function() {
loading = true;
var name = $(this).val();
$("graph-reset").click();

Expand Down Expand Up @@ -1202,7 +1212,8 @@ $("#graph-select").change(function() {
units[u].max = context.yaxes[y].max;
}
}


loading = false;
query();
});

Expand Down

0 comments on commit 844228e

Please sign in to comment.