Skip to content

Commit

Permalink
fixed manual timer
Browse files Browse the repository at this point in the history
  • Loading branch information
dimecho committed Jul 3, 2022
1 parent 86bdee5 commit 819a582
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 108 deletions.
208 changes: 154 additions & 54 deletions ESPTiny-Plant.ino
100644 → 100755

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ Sketch (Firmware)
4. Tools -> Boards -> NodeMCU 1.0 -> Flash Size -> 4M (3M SPIFFS)
5. Sketch -> Export compiled Binary

Additional Libraries

https://github.com/me-no-dev/ESPAsyncWebServer
https://github.com/devyte/ESPAsyncDNSServer
https://github.com/me-no-dev/ESPAsyncTCP
https://github.com/me-no-dev/ESPAsyncUDP
https://github.com/mobizt/ESP-Mail-Client


FileSystem (Web Interface)

1. Run "littlefs-build-mac" (Mac) to build LittleFS "/data"
Expand Down
15 changes: 5 additions & 10 deletions Web/css/bootstrap.css

Large diffs are not rendered by default.

27 changes: 23 additions & 4 deletions Web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
</head>
<body class="preloader">
<div id="preloader"></div>
<div aria-live="polite" aria-atomic="true" class="position-relative">
<div class="toast-container position-absolute top-0 end-0 p-3" id="notify"></div>
</div>
<div class="toast-container position-absolute top-0 end-0 p-3" id="notify" style="z-index:2000"></div>
<div class="container">
<div class="main row h-100">
<div id="svgInteractive" class="col-sm-12 svglayer bg-light">
<div id="captive-portal hidden" align="center">
<div id="captive-portal" align="center" class="hidden">
<h3>Visit from Web-Browser</h3>
<h1>http://192.168.8.8</h1>
</div>
Expand Down Expand Up @@ -97,6 +95,9 @@ <h5 class="modal-title">WiFi Settings</h5>
<li class="nav-item" role="presentation">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tabAlerts" type="button" role="tab" aria-selected="false">Alerts</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tabTest" type="button" role="tab" aria-selected="false">Test</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tabFirmware" type="button" role="tab" aria-selected="false">Firmware</button>
</li>
Expand Down Expand Up @@ -332,6 +333,24 @@ <h5 class="modal-title">WiFi Settings</h5>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-success" id="wireless-alerts-ok">Save</button>
</form>
</div>
<div class="tab-pane fade" id="tabTest" role="tabpanel">
<div class="container">
<div class="row">
<div class="col">
<button class="btn btn-success" type="button" id="testPump" onclick="testPump()">Test Pump</button>
<button class="btn btn-success" type="button" id="testSensor">Test Sensor</button>
<button class="btn btn-success" type="button" id="testSleep">Test Sleep/Wake</button>
</div>
</div>
<div class="row mt-4">
<div class="col">
<div class="progress progress-striped active">
<div class="progress-bar" style="width:0%"></div>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="tabFirmware" role="tabpanel">
<div class="container">
Expand Down
6 changes: 3 additions & 3 deletions Web/js/bootstrap.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Web/js/chart.js

Large diffs are not rendered by default.

103 changes: 74 additions & 29 deletions Web/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ function loadSVG(svgfile) {
svgfile = s[nvram.response['nvram'][20]]; //match index # to file name
}
}
}else if (svgfile == undefined) {
if(nvram.response['nvram'][9] == 1) {
notify('', 'Data collection is enabled.', 'info');
}
}
if (svgfile == undefined) {
svgfile = 'bonsai.svg';
}

Expand All @@ -90,25 +94,22 @@ function loadSVG(svgfile) {
adc.send();
adc.onloadend = function() {
if(xhr.status == 200) {
var a = adc.responseText;
//console.log(adc.responseText);
var a = parseInt(adc.responseText);

if(Number.isInteger(a)) {
if(a > 1010 && a < 1024)
{
notify('', 'Detecting Excess Moisture!', 'danger');
if(nvram.response['nvram'][14] > 12) {
notify('', 'Lower Pot Size value', 'info');
notify('', 'Adjust sensor to soil height', 'info');
}else{
notify('', 'Compact soil water channels', 'info');
notify('', 'Move sensor away from water', 'info');
}
//}else{
//notify('', 'Current Moisture: ' + a, 'info');
}
document.getElementById('moisture-adc').textContent = a;
}
if(a > 1010 && a < 1024)
{
notify('', 'Detecting Excess Moisture!', 'danger');
if(nvram.response['nvram'][14] > 12) {
notify('', 'Lower Pot Size value', 'info');
notify('', 'Adjust sensor to soil height', 'info');
}else{
notify('', 'Compact soil water channels', 'info');
notify('', 'Move sensor away from water', 'info');
}
//}else{
//notify('', 'Current Moisture: ' + a, 'info');
}
document.getElementById('moisture-adc').textContent = a;
}
}

Expand Down Expand Up @@ -418,7 +419,7 @@ function loadSVG(svgfile) {

saveSetting(20, loginterval);
notify('','Deep Sleep is longer than Graph Interval', 'danger');
notify('','Adjusting Deep Sleep ...', 'sucess');
notify('','Adjusting Deep Sleep ...', 'success');
}
}
document.getElementById('wirelessSettingsForm').submit();
Expand All @@ -433,13 +434,13 @@ function loadSVG(svgfile) {

$('#fileLittleFS').change(function() {
$('#formLittleFS').attr('action', 'http://' + window.location.hostname + "/update"); //force HTTP
progressTimer(80);
progressTimer(80, 1);
document.getElementById('formLittleFS').submit();
})

$('#fileFirmware').change(function() {
$('#formFirmware').attr('action', 'http://' + window.location.hostname + "/update"); //force HTTP
progressTimer(20);
progressTimer(20, 1);
document.getElementById('formFirmware').submit();
})

Expand All @@ -464,7 +465,7 @@ function saveSetting(offset, value, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'nvram?offset=' + offset + '&value=' + value, true);
xhr.send();
xhr.onload = function(e) {
xhr.onloadend = function(e) {
if(callback) callback(e);
}
//notify('',request.responseText, 'danger');
Expand All @@ -487,7 +488,23 @@ function HiddenCheck(id, element) {
document.getElementById(id).value = 0;
}

if(id == 'WiFiDHCP') {
if(id == 'WiFiHidden') {
if(element.checked) {
saveSetting(2, 1);
notify('','WiFi SSID is now Hidden', 'danger');
}else{
saveSetting(2, 0);
notify('','WiFi SSID is now Broadcasting', 'success');
}
}else if(id == 'EnableLOG') {
if(element.checked) {
saveSetting(9, 1);
notify('','Graph & Log Collection is ON', 'info');
}else{
saveSetting(9, 0);
notify('','Graph & Log Collection is OFF', 'success');
}
}else if(id == 'WiFiDHCP') {
var b = false;

if(element.checked){
Expand Down Expand Up @@ -541,7 +558,7 @@ function formValidate() {
function notify(messageHeader, messageBody, bg, id) {

var toast = document.createElement('div');
toast.className = 'toast fade show text-white zindex-popover bg-' + bg;
toast.className = 'toast fade show text-white bg-' + bg;
toast.setAttribute('role', 'alert');
toast.setAttribute('aria-live', 'assertive');
toast.setAttribute('aria-atomic', 'true');
Expand Down Expand Up @@ -582,7 +599,31 @@ function sleep(ms) {

function testPump()
{

var xhr = new XMLHttpRequest();
xhr.open('GET', 'pump', true);
xhr.send();
xhr.onload = function() {
if (xhr.status == 200) {
notify('', 'Running Pump ...', 'warning');
progressTimer(32,0,function() {
//Check data log to confirm
var log = new XMLHttpRequest();
log.open('GET', 'data.log', true);
log.send();
log.onload = function() {
if (log.status == 200) {
var s = log.responseText.split('\n');
if (s[s.length-2].indexOf('M:') != -1)
{
notify('', 'Pump OK', 'success');
}
}
};
});
}else{
notify('', 'Pump Test Failed', 'danger');
}
};
};

function calcNextWaterCycle(start, stop, size)
Expand Down Expand Up @@ -664,12 +705,16 @@ function checkFirmwareUpdates(v)
*/
};

function progressTimer(speed) {
var timer = setInterval(function(){
function progressTimer(speed, bar, callback) {

timerUploadCounter = 0;

var timer = setInterval(function() {
timerUploadCounter++;
if(timerUploadCounter == 100) {
clearInterval(timer);
if(callback) callback(timerUploadCounter);
}
document.getElementsByClassName('progress-bar')[0].style.width = timerUploadCounter + '%';
document.getElementsByClassName('progress-bar')[bar].style.width = timerUploadCounter + '%';
}, speed);
};
6 changes: 3 additions & 3 deletions littlefs-build-win.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ cd $PSScriptRoot
#Copy Files
#==============
Remove-Item -Recurse -Force .\data -ErrorAction SilentlyContinue
New-Item -ItemType directory -Path .\data
Copy-Item .\Web -Filter *.* -Destination .\data -Recurse
Copy-Item -Path .\Web\ -Filter *.* -Destination .\data\ -Recurse -Force
Remove-Item -Recurse -Force .\data\img -ErrorAction SilentlyContinue

#====================
#Download Compressors
Expand Down Expand Up @@ -69,4 +69,4 @@ if(!(Test-Path .\build -PathType Container)) {
New-Item -ItemType directory -Path .\build
}
#Start-Process .\tools\mklittlefs.exe -ArgumentList "-c .\data -b 8192 -p 256 -s 643072 flash-littlefs.bin" -NoNewWindow -PassThru -Wait
Start-Process .\tools\mklittlefs.exe -ArgumentList "-c .\data -b 8192 -p 256 -s 750000 .\build\flash-littlefs.bin" -NoNewWindow -PassThru -Wait
Start-Process .\tools\mklittlefs.exe -ArgumentList "-c .\data -b 8192 -p 256 -s 680000 .\build\flash-littlefs.bin" -NoNewWindow -PassThru -Wait

0 comments on commit 819a582

Please sign in to comment.