Skip to content

Commit

Permalink
Version: 1.3.2 - 2018-07-02 by James Newton
Browse files Browse the repository at this point in the history
-DEBUG levels: 1 for serial only, 2 for serial and display.
-User config device baudrate, poweron initialization string, data extraction and display:
-- New /device.html page to configure all connected device options
-- Send config.pwronstr to device pwrondelay seconds after startup
-- Extract up to 3 data items returned from device for local display via scanf code:
   http://www.cplusplus.com/reference/cstdio/scanf/
-- Extracted values multiplied by slope plus offset and shown with name on the display
-global.h config load/save simplified with EEPROM.get / EEPROM.put.
-CONFIG_VER version number added. This update will clear prior config data to default!
-txbuf to hold data waiting to be sent to the device so we can send this in a debug message
-Support "hidden" /update page to upload web/js/css/etc files into SPIFFS for web server.
 This allows customization and rebranding for your solution without the need for Arduino code development.
 Put your own html/javascript in the device for user interface.
-Default web page is index.htm from SPIFFS. /root is handle_root from Page_Root.h
  i.e. http://ip/ will display nothing until index.htm is uploaded via http://ip/update.
  If you want to use the built in homepage, go to http://ip/root
  TODO: serve root automatically if no index.htm in SPIFFS
-Built in /root page converted from jquery to raw javascript for increased reliability and smaller size.
   This is critical when working in poor RF environments while directly connected to the device.
-Use template processor in ESPAsyncWebServer for config pages. There are problems with this, see:
-- me-no-dev/ESPAsyncWebServer#333 Must change TEMPLATE_PLACEHOLDER to '`'
    in \libraries\ESPAsyncWebServer\src\WebResponseImpl.h and trigger library re-compile
-- me-no-dev/ESPAsyncWebServer#374 Must use "AI-THINKER" ESP-12E units
-- Network setup /config.html NOT updated to templates for this reason.
-Moving to a single general tag processor function "send_tag_values"
-Moving to standard linking to .css and .js resources from config pages instead of the javascript window.onload functions.
-Add debugq macro to append to debugbuf for later output. This avoids delays when debugging web responses
-Increase max string length of ReadStringFromEEPROM from 60 to 65
-urldecode, avoids Strings, returns char*, expects length.
-urlencode, expects char* vs String (still returns String). Simplified via nibble2hex.
-HTMLencode added inorder to support all strings for scanf codes.
-Optional support for NeoPixel LEDs. NOT enabled by default.
-Start on a command processor language from server response or user input
BUGFIX:
IO pin 10 is NOT usable as SERIAL_ENABLE_PIN, back to IO5 D1
parseServer p1,p2 had not been initialized. Data returned from server for device could be lost.

Merge branch 'master' of https://github.com/JamesNewton/esp8266WebSerial

# Conflicts:
#	esp8266WebSerial.ino
#	global.h
  • Loading branch information
JamesNewton committed Jul 2, 2018
2 parents a164acc + f8445b4 commit 8d39a96
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 35 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ device data extraction / display via scanf codes, slope, and offset.
Notes:


Due to a [bug / limitation in ESPAsyncWebServer's template system](https://github.com/me-no-dev/ESPAsyncWebServer/issues/333#issuecomment-370595466), and the fact that % is often used in the device configuration, you have to edit the /src/WebResponseImpl.h file in that library to change:
````
#define TEMPLATE_PLACEHOLDER '%'
````
to
````
#define TEMPLATE_PLACEHOLDER '`'
````

P.S. Don't even try to get this to work with an ESP-8266 module that wasn't made by AI-THINKER. [The knock offs will NOT work](https://github.com/me-no-dev/ESPAsyncWebServer/issues/374).

Due to a [bug / limitation in ESPAsyncWebServer's template system](https://github.com/me-no-dev/ESPAsyncWebServer/issues/333#issuecomment-370595466), and the fact that % is often used in the device configuration, you have to edit the /src/WebResponseImpl.h file in that library to change:
````
#define TEMPLATE_PLACEHOLDER '%'
Expand Down
141 changes: 106 additions & 35 deletions data/index.htm
Original file line number Diff line number Diff line change
@@ -1,47 +1,118 @@
<!doctype html>
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="microajax.js"></script>
<html>
<head>
<title>ESP8266 IOT Serial to Web</title>
<style>
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }
.units {font-size: large; color: black;}
.values {font-size: large; color: black;}
</style>
<meta charset="utf-8" />
</head>
<body>
<pre><div id='log'></div></pre>
<p>
<form id='msg' action='data' method='get'>
<input id='txt' name='text' type='text'></input><input id='crlf' type='checkbox' checked>+cr?</input>
</form></p>
<p><a href="/admin.html">Settings</a> <!-- <a href="/file?start=1">Stream</a> --> </p>
<script type='text/javascript' src='/jquery-3.3.1.min.js'></script>
<script>

var logger = {}
logger.channel = [{},{},{},{},{},{},{},{}] //array of 8 objects

function log(msg) {
console.log(msg);
}

<script type='text/javascript'>
$('#msg').submit(function(){
var clientmsg = $('#txt').val();
if ($('#crlf').is(':checked')) clientmsg+='\r';
var log=$('#log');
log.html(log.html()+'<b>'+clientmsg+'</b>');
$.get('data', {text: clientmsg}, function(html){
log.html(log.html()+html);
});
$('#txt').attr('value', '');
loadLog(); //instantly pick up any response.
return false;
});
function loadLog(){
var log=$('#log');
$.ajax({
url: 'data',
cache: false,
success: function(html){
log.html(log.html()+html);
},
function ajax(data, callback) {
var xhttp = new XMLHttpRequest()
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if ("?\n" == this.responseText) { //yike! Logger in bootloader?
ajax("/data?text=G%0D",function(){}); //send a G\
}
log("recv:"+escape(this.responseText))
callback(this.responseText)
}
}
xhttp.open("GET", data, true)
xhttp.send()
log("sent:"+data)
}

function getData() {
ajax("/data", function(reply) {
document.getElementById("log").innerHTML += reply;
});
logger.timeout = setTimeout(function(){getData()},1000);
}

function sendData(form) {
var msg = form.txt.value;
form.txt.value = "";
var response = "";
if (form.crlf.checked) msg+='\r';
//console.log(form.crlf.checked);
ajax("/data?text="+escape(msg), function(reply) {
document.getElementById("log").innerHTML += escape(reply);
});
};
setInterval (loadLog, 2500);
</script>
</body>
</html>
document.getElementById("log").innerHTML += "<b>"+msg+"</b>";
logger.timeout = setTimeout(function(){getData()},200);

function getLogger(state) {
log("State:"+state);
switch(state) {
case 0:
clearTimeout(logger.timeout) //no interruptions
getData();//ok to interrupt and clear any remaining data
break;
default:
return false;
}
}

function getReadings() {
function dispReadings(read) {
var data = read.split("_")
for (var i=0; i<3; i++) {
var ch = logger.channel[i]
var x = parseInt(data[i+1].substr(0,4),16)
var y = ch.slope * x + ch.offset
document.getElementById("channel"+i+"value").innerHTML = y.toPrecision(4)
//getData();//ok to interrupt and clear any remaining data
}
}

clearTimeout(logger.timeout) //no interruptions

ajax("/data?text=r%0D",function(read){
setTimeout(function(){ajax("/data",dispReadings)},500)

})
}

</script>
<input type="submit" value="Connect" onClick="getLogger(0);">
<div id='status'></div>
<div id='readings' style="display: none;">
<input type="submit" value="Read" onClick="getReadings();">
<table>
<tr>
<td><div id="channel0units" class="units"></div></td>
<td><div id="channel0value" class="values">...</div></td>
</tr>
<tr>
<td><div id="channel1units" class="units"></div></td>
<td><div id="channel1value" class="values">...</div></td>
</tr>
<tr>
<td><div id="channel2units" class="units"></div></td>
<td><div id="channel2value" class="values">...</div></td>
</tr>
</table>
</div>
<pre><div id='log'></div></pre>
<p>
<form id='msg' action='data' method='get' onSubmit="sendData(this);return false;">
<input id='txt' name='text' type='text'><input id='crlf' type='checkbox' checked><label for="crlf">+cr?</label>
</form>
<p><a href="/admin.html">Settings</a>

</body>
</html>

0 comments on commit 8d39a96

Please sign in to comment.