mirror of https://github.com/jeelabs/esp-link.git
parent
965b70a408
commit
b7dd0b180f
@ -0,0 +1,72 @@ |
||||
function fetchText(delay, repeat) { |
||||
var el = $("#console"); |
||||
if (el.textEnd == undefined) { |
||||
el.textEnd = 0; |
||||
el.innerHTML = ""; |
||||
} |
||||
window.setTimeout(function() { |
||||
ajaxJson('GET', console_url + "?start=" + el.textEnd, |
||||
function(resp) { |
||||
var dly = updateText(resp); |
||||
if (repeat) fetchText(dly, repeat); |
||||
}, |
||||
function() { retryLoad(repeat); }); |
||||
}, delay); |
||||
} |
||||
|
||||
function updateText(resp) { |
||||
var el = $("#console"); |
||||
|
||||
var delay = 3000; |
||||
if (resp != null && resp.len > 0) { |
||||
console.log("updateText got", resp.len, "chars at", resp.start); |
||||
if (resp.start > el.textEnd) { |
||||
el.innerHTML = el.innerHTML.concat("\r\n<missing lines\r\n"); |
||||
} |
||||
el.innerHTML = el.innerHTML.concat(resp.text); |
||||
el.textEnd = resp.start + resp.len; |
||||
delay = 500; |
||||
} |
||||
return delay; |
||||
} |
||||
|
||||
function retryLoad(repeat) { |
||||
fetchText(1000, repeat); |
||||
} |
||||
|
||||
//===== Console page
|
||||
|
||||
function showRate(rate) { |
||||
rates.forEach(function(r) { |
||||
var el = $("#"+r+"-button"); |
||||
el.className = el.className.replace(" button-selected", ""); |
||||
}); |
||||
|
||||
var el = $("#"+rate+"-button"); |
||||
if (el != null) el.className += " button-selected"; |
||||
} |
||||
|
||||
function baudButton(baud) { |
||||
$("#baud-btns").appendChild(m( |
||||
' <a id="'+baud+'-button" href="#" class="pure-button">'+baud+'</a>')); |
||||
|
||||
$("#"+baud+"-button").addEventListener("click", function(e) { |
||||
e.preventDefault(); |
||||
ajaxSpin('POST', "/console/baud?rate="+baud, |
||||
function(resp) { showNotification("" + baud + " baud set"); showRate(baud); }, |
||||
function(s, st) { showWarning("Error setting baud rate: " + st); } |
||||
); |
||||
}); |
||||
} |
||||
|
||||
//===== Log page
|
||||
|
||||
function showDbgMode(mode) { |
||||
var btns = $('.dbg-btn'); |
||||
for (var i=0; i < btns.length; i++) { |
||||
if (btns[i].id === "dbg-"+mode) |
||||
addClass(btns[i], "button-selected"); |
||||
else |
||||
removeClass(btns[i], "button-selected"); |
||||
} |
||||
} |
After Width: | Height: | Size: 498 B |
@ -0,0 +1,10 @@ |
||||
<!doctype html> |
||||
<html><head> |
||||
<title>esp-link</title> |
||||
<link rel="stylesheet" href="/pure.css"> |
||||
<link rel="stylesheet" href="/style.css"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
<script src="/ui.js"></script> |
||||
</head> |
||||
<body> |
||||
<div id="layout"> |
@ -1 +1,87 @@ |
||||
<!DOCTYPE html><script src='http://linux-ws/esplink/home.js'></script> |
||||
<div id="main"> |
||||
<div class="header"> |
||||
<div><img src="favicon.ico" height="64"><span class="jl">JEELABS</span></div> |
||||
<h1 style="margin-top:0"><span class="esp">esp</span>-link</h1> |
||||
<h2 id="version"></h2> |
||||
</div> |
||||
|
||||
<div class="content"> |
||||
<div class="pure-g"> |
||||
<div class="pure-u-1"><div class="card"> |
||||
<p>The JeeLabs esp-link firmware bridges the ESP8266 serial port to Wifi and can |
||||
program microcontrollers over the serial port, in particular Arduinos, AVRs, and |
||||
NXP's LPC800 and other ARM processors.</p> |
||||
<p style="margin-bottom:0;">Program an Arduino/AVR using avrdude using a command |
||||
line similar to:</p> |
||||
<div class="tt">/home/arduino-1.0.5/hardware/tools/avrdude \<br> |
||||
-DV -patmega328p -Pnet:esp-link.local:23 -carduino -b115200 -U \<br> |
||||
-C /home/arduino-1.0.5/hardware/tools/avrdude.conf flash:w:my_sketch.hex:i |
||||
</div> |
||||
<p>where <tt>-Pnet:esp-link.local:23</tt> tells avrdude to connect to port 23 of esp-link. |
||||
You can substitute the IP address of your esp-link for esp-link.local if necessary.</p> |
||||
<p>Please refer to |
||||
<a href="https://github.com/jeelabs/esp-link/blob/master/README.md">the online README</a> |
||||
for up-to-date help and to the forthcoming |
||||
<a href="http://jeelabs.org">JeeLabs blog</a> for an intro to the codebase.</p> |
||||
</div></div> |
||||
</div> |
||||
<div class="pure-g"> |
||||
<div class="pure-u-1 pure-u-md-1-2"> |
||||
<div class="card"> |
||||
<h1>Wifi summary</h1> |
||||
<div id="wifi-spinner" class="spinner spinner-small"></div> |
||||
<table id="wifi-table" class="pure-table pure-table-horizontal" hidden><tbody> |
||||
<tr><td>WiFi mode</td><td id="wifi-mode"></td></tr> |
||||
<tr><td>Configured network</td><td id="wifi-ssid"></td></tr> |
||||
<tr><td>Wifi channel</td><td id="wifi-chan"></td></tr> |
||||
<tr><td>Wifi status</td><td id="wifi-status"></td></tr> |
||||
<tr><td>Wifi address</td><td id="wifi-ip"></td></tr> |
||||
<tr><td>Configured hostname</td><td id="wifi-hostname"></td></tr> |
||||
</tbody> </table> |
||||
</div> |
||||
<div class="card"> |
||||
<h1>TCP client</h1> |
||||
<form action="#" id="tcpform" class="pure-form"> |
||||
<legend>TCP client support in esp-link</legend> |
||||
<div class="form-horizontal"> |
||||
<input type="checkbox" name="tcp_enable"/> |
||||
<label>Enable serial port TCP client</label> |
||||
</div> |
||||
<br> |
||||
<legend>Grovestreams data push</legend> |
||||
<div class="form-horizontal"> |
||||
<input type="checkbox" name="rssi_enable"/> |
||||
<label>Send RSSI</label> |
||||
</div> |
||||
<div class="pure-form-stacked"> |
||||
<label>API key/passwd</label> |
||||
<input type="password" name="api_key"/> |
||||
</div> |
||||
<button id="tcp-button" type="submit" |
||||
class="pure-button button-primary">Change!</button> |
||||
</form> |
||||
</div> |
||||
</div> |
||||
<div class="pure-u-1 pure-u-md-1-2"><div class="card"> |
||||
<h1>Pin assignment</h1> |
||||
<legend>Select one of the following signal/pin assignments to match your hardware</legend> |
||||
<fieldset class='radios' id='pin-mux'> |
||||
<div class="spinner spinner-small"></div> |
||||
</fieldset> |
||||
</div></div> |
||||
</div> |
||||
<div class="pure-g"> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<script type="text/javascript"> |
||||
onLoad(function() { |
||||
fetchPins(); |
||||
getWifiInfo(); |
||||
fetchTcpClient(); |
||||
bnd($("#tcpform"), "submit", changeTcpClient); |
||||
}); |
||||
</script> |
||||
</body></html> |
||||
|
@ -1 +1,48 @@ |
||||
<!DOCTYPE html><script src='http://linux-ws/esplink/log.js'></script> |
||||
<div id="main"> |
||||
<div class="header"> |
||||
<h1>Debug Log</h1> |
||||
</div> |
||||
|
||||
<div class="content"> |
||||
<p>The debug log shows the most recent characters printed by the esp-link software itself to |
||||
its own debug log.</p> |
||||
<div class="pure-g"> |
||||
<p class="pure-u-1-4"> |
||||
<a id="refresh-button" class="pure-button button-primary" href="#">Refresh</a> |
||||
</p> |
||||
<p class="pure-u-3-4" style="vertical-align: baseline"> |
||||
UART debug log: |
||||
<a id="dbg-auto" class="dbg-btn pure-button" href="#">auto</a> |
||||
<a id="dbg-off" class="dbg-btn pure-button" href="#">off</a> |
||||
<a id="dbg-on" class="dbg-btn pure-button" href="#">on</a> |
||||
</p> |
||||
</div> |
||||
<pre id="console" class="console" style="margin-top: 0px;"></pre> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<script type="text/javascript">console_url = "/log/text"</script> |
||||
<script src="console.js"></script> |
||||
<script type="text/javascript"> |
||||
onLoad(function() { |
||||
fetchText(100, false); |
||||
|
||||
$("#refresh-button").addEventListener("click", function(e) { |
||||
e.preventDefault(); |
||||
fetchText(100, false); |
||||
}); |
||||
|
||||
["auto", "off", "on"].forEach(function(mode) { |
||||
bnd($('#dbg-'+mode), "click", function(el) { |
||||
ajaxJsonSpin('POST', "/log/dbg?mode="+mode, |
||||
function(data) { showNotification("UART mode " + data.mode); showDbgMode(data.mode); }, |
||||
function(s, st) { showWarning("Error setting UART mode: " + st); } |
||||
); |
||||
}); |
||||
}); |
||||
|
||||
ajaxJson('GET', "/log/dbg", function(data) { showDbgMode(data.mode); }, function() {}); |
||||
}); |
||||
</script> |
||||
</body></html> |
||||
|
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 425 B |
@ -1 +1,84 @@ |
||||
<!DOCTYPE html><script src='http://linux-ws/esplink/wifi/wifi.js'></script> |
||||
<div id="main"> |
||||
<div class="header"> |
||||
<h1>Wifi Configuration</h1> |
||||
</div> |
||||
|
||||
<div class="content"> |
||||
<div class="pure-g"> |
||||
<div class="pure-u-1 pure-u-md-1-2"><div class="card"> |
||||
<h1>Wifi State</h1> |
||||
<div id="wifi-spinner" class="spinner spinner-small"></div> |
||||
<table id="wifi-table" class="pure-table pure-table-horizontal" hidden><tbody> |
||||
<tr><td>WiFi mode</td><td id="wifi-mode"></td></tr> |
||||
<tr><td>Wifi channel</td><td id="wifi-chan"></td></tr> |
||||
<tr><td>Configured network</td><td id="wifi-ssid"></td></tr> |
||||
<tr><td>Wifi status</td><td id="wifi-status"></td></tr> |
||||
<tr><td>Wifi address</td><td id="wifi-ip"></td></tr> |
||||
<tr><td>Wifi rssi</td><td id="wifi-rssi"></td></tr> |
||||
<tr><td>Wifi phy</td><td id="wifi-phy"></td></tr> |
||||
<tr><td>Wifi MAC</td><td id="wifi-mac"></td></tr> |
||||
<tr><td colspan="2" id="wifi-warn"></td></tr> |
||||
</tbody> </table> |
||||
</div></div> |
||||
<div class="pure-u-1 pure-u-md-1-2"><div class="card"> |
||||
<h1>Wifi Association</h1> |
||||
<p id="reconnect" style="color: #600" hidden></p> |
||||
<form action="#" id="wifiform" class="pure-form pure-form-stacked"> |
||||
<legend>To connect to a WiFi network, please select one of the detected networks, |
||||
enter the password, and hit the connect button...</legend> |
||||
<label>Network SSID</label> |
||||
<div id="aps">Scanning... <div class="spinner spinner-small"></div></div> |
||||
<label>WiFi password, if applicable:</label> |
||||
<input id="wifi-passwd" type="password" name="passwd" placeholder="password"> |
||||
<button id="connect-button" type="submit" class="pure-button button-primary">Connect!</button> |
||||
</form> |
||||
</div></div> |
||||
</div> |
||||
<div class="pure-g"> |
||||
<div class="pure-u-1 pure-u-md-1-2"><div class="card"> |
||||
<h1>Special Settings</h1> |
||||
<form action="#" id="specform" class="pure-form"> |
||||
<legend>Special settings, use with care!</legend> |
||||
<div class="form-horizontal"> |
||||
<label for="dhcp-ron" style="margin-right:1em"> |
||||
<input type="radio" name="dhcp" value="on" id="dhcp-ron"/> |
||||
DHCP</label> |
||||
<label for="dhcp-roff"> |
||||
<input type="radio" name="dhcp" value="off" id="dhcp-roff"/> |
||||
Static IP</label> |
||||
</div> |
||||
<div id="dhcp-on" class="pure-form-stacked"> |
||||
<label>Hostname when requesting DHCP lease</label> |
||||
<input id="wifi-hostname" type="text" name="hostname"/> |
||||
</div> |
||||
<div id="dhcp-off" class="pure-form-stacked"> |
||||
<label>Static IP address</label> |
||||
<input id="wifi-staticip" type="text" name="staticip"/> |
||||
<label>Netmask (for static IP)</label> |
||||
<input id="wifi-netmask" type="text" name="netmask"/> |
||||
<label>Gateway (for static IP)</label> |
||||
<input id="wifi-gateway" type="text" name="gateway"/> |
||||
</div> |
||||
<button id="special-button" type="submit" |
||||
class="pure-button button-primary">Change!</button> |
||||
</form> |
||||
</div></div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<script type="text/javascript"> |
||||
</script> |
||||
<script src="wifi.js"></script> |
||||
<script type="text/javascript"> |
||||
onLoad(function() { |
||||
getWifiInfo(); |
||||
bnd($("#wifiform"), "submit", changeWifiAp); |
||||
bnd($("#specform"), "submit", changeSpecial); |
||||
bnd($("#dhcp-ron"), "click", doDhcp); |
||||
bnd($("#dhcp-roff"), "click", doStatic); |
||||
scanTimeout = window.setTimeout(scanAPs, 500); |
||||
}); |
||||
</script> |
||||
</body></html> |
||||
|
@ -0,0 +1,200 @@ |
||||
var currAp = ""; |
||||
var blockScan = 0; |
||||
|
||||
function createInputForAp(ap) { |
||||
if (ap.essid=="" && ap.rssi==0) return; |
||||
|
||||
var input = e("input"); |
||||
input.type = "radio"; |
||||
input.name = "essid"; |
||||
input.value=ap.essid; |
||||
input.id = "opt-" + ap.essid; |
||||
if (currAp == ap.essid) input.checked = "1"; |
||||
|
||||
var bars = e("div"); |
||||
var rssiVal = -Math.floor(ap.rssi/51)*32; |
||||
bars.className = "lock-icon"; |
||||
bars.style.backgroundPosition = "0px "+rssiVal+"px"; |
||||
|
||||
var rssi = e("div"); |
||||
rssi.innerHTML = "" + ap.rssi +"dB"; |
||||
|
||||
var encrypt = e("div"); |
||||
var encVal = "-64"; //assume wpa/wpa2
|
||||
if (ap.enc == "0") encVal = "0"; //open
|
||||
if (ap.enc == "1") encVal = "-32"; //wep
|
||||
encrypt.className = "lock-icon"; |
||||
encrypt.style.backgroundPosition = "-32px "+encVal+"px"; |
||||
|
||||
var label = e("div"); |
||||
label.innerHTML = ap.essid; |
||||
|
||||
var div = m('<label for=\"opt-' + ap.essid + '"></label>').childNodes[0]; |
||||
div.appendChild(input); |
||||
div.appendChild(encrypt); |
||||
div.appendChild(bars); |
||||
div.appendChild(rssi); |
||||
div.appendChild(label); |
||||
return div; |
||||
} |
||||
|
||||
function getSelectedEssid() { |
||||
var e = document.forms.wifiform.elements; |
||||
for (var i=0; i<e.length; i++) { |
||||
if (e[i].type == "radio" && e[i].checked) return e[i].value; |
||||
} |
||||
return currAp; |
||||
} |
||||
|
||||
var scanTimeout = null; |
||||
var scanReqCnt = 0; |
||||
|
||||
function scanResult() { |
||||
if (scanReqCnt > 60) { |
||||
return scanAPs(); |
||||
} |
||||
scanReqCnt += 1; |
||||
ajaxJson('GET', "scan", function(data) { |
||||
currAp = getSelectedEssid(); |
||||
if (data.result.inProgress == "0" && data.result.APs.length > 1) { |
||||
$("#aps").innerHTML = ""; |
||||
var n = 0; |
||||
for (var i=0; i<data.result.APs.length; i++) { |
||||
if (data.result.APs[i].essid == "" && data.result.APs[i].rssi == 0) continue; |
||||
$("#aps").appendChild(createInputForAp(data.result.APs[i])); |
||||
n = n+1; |
||||
} |
||||
showNotification("Scan found " + n + " networks"); |
||||
var cb = $("#connect-button"); |
||||
cb.className = cb.className.replace(" pure-button-disabled", ""); |
||||
if (scanTimeout != null) clearTimeout(scanTimeout); |
||||
scanTimeout = window.setTimeout(scanAPs, 20000); |
||||
} else { |
||||
window.setTimeout(scanResult, 1000); |
||||
} |
||||
}, function(s, st) { |
||||
window.setTimeout(scanResult, 5000); |
||||
}); |
||||
} |
||||
|
||||
function scanAPs() { |
||||
console.log("scanning now"); |
||||
if (blockScan) { |
||||
scanTimeout = window.setTimeout(scanAPs, 1000); |
||||
return; |
||||
} |
||||
scanTimeout = null; |
||||
scanReqCnt = 0; |
||||
ajaxReq('POST', "scan", function(data) { |
||||
//showNotification("Wifi scan started");
|
||||
window.setTimeout(scanResult, 1000); |
||||
}, function(s, st) { |
||||
//showNotification("Wifi scan may have started?");
|
||||
window.setTimeout(scanResult, 1000); |
||||
}); |
||||
} |
||||
|
||||
function getStatus() { |
||||
ajaxJsonSpin("GET", "connstatus", function(data) { |
||||
if (data.status == "idle" || data.status == "connecting") { |
||||
$("#aps").innerHTML = "Connecting..."; |
||||
showNotification("Connecting..."); |
||||
window.setTimeout(getStatus, 1000); |
||||
} else if (data.status == "got IP address") { |
||||
var txt = "Connected! Got IP "+data.ip; |
||||
showNotification(txt); |
||||
showWifiInfo(data); |
||||
blockScan = 0; |
||||
|
||||
if (data.modechange == "yes") { |
||||
var txt2 = "esp-link will switch to STA-only mode in a few seconds"; |
||||
window.setTimeout(function() { showNotification(txt2); }, 4000); |
||||
} |
||||
|
||||
$("#reconnect").removeAttribute("hidden"); |
||||
$("#reconnect").innerHTML = |
||||
"If you are in the same network, go to <a href=\"http://"+data.ip+ |
||||
"/\">"+data.ip+"</a>, else connect to network "+data.ssid+" first."; |
||||
} else { |
||||
blockScan = 0; |
||||
showWarning("Connection failed: " + data.status + ", " + data.reason); |
||||
$("#aps").innerHTML = |
||||
"Check password and selected AP. <a href=\"wifi.tpl\">Go Back</a>"; |
||||
} |
||||
}, function(s, st) { |
||||
//showWarning("Can't get status: " + st);
|
||||
window.setTimeout(getStatus, 2000); |
||||
}); |
||||
} |
||||
|
||||
function changeWifiMode(m) { |
||||
blockScan = 1; |
||||
hideWarning(); |
||||
ajaxSpin("POST", "setmode?mode=" + m, function(resp) { |
||||
showNotification("Mode changed"); |
||||
window.setTimeout(getWifiInfo, 100); |
||||
blockScan = 0; |
||||
}, function(s, st) { |
||||
showWarning("Error changing mode: " + st); |
||||
window.setTimeout(getWifiInfo, 100); |
||||
blockScan = 0; |
||||
}); |
||||
} |
||||
|
||||
function changeWifiAp(e) { |
||||
e.preventDefault(); |
||||
var passwd = $("#wifi-passwd").value; |
||||
var essid = getSelectedEssid(); |
||||
showNotification("Connecting to " + essid); |
||||
var url = "connect?essid="+encodeURIComponent(essid)+"&passwd="+encodeURIComponent(passwd); |
||||
|
||||
hideWarning(); |
||||
$("#reconnect").setAttribute("hidden", ""); |
||||
$("#wifi-passwd").value = ""; |
||||
var cb = $("#connect-button"); |
||||
var cn = cb.className; |
||||
cb.className += ' pure-button-disabled'; |
||||
blockScan = 1; |
||||
ajaxSpin("POST", url, function(resp) { |
||||
$("#spinner").removeAttribute('hidden'); // hack
|
||||
showNotification("Waiting for network change..."); |
||||
window.scrollTo(0, 0); |
||||
window.setTimeout(getStatus, 2000); |
||||
}, function(s, st) { |
||||
showWarning("Error switching network: "+st); |
||||
cb.className = cn; |
||||
window.setTimeout(scanAPs, 1000); |
||||
}); |
||||
} |
||||
|
||||
function changeSpecial(e) { |
||||
e.preventDefault(); |
||||
var url = "special"; |
||||
url += "?dhcp=" + document.querySelector('input[name="dhcp"]:checked').value; |
||||
url += "&hostname=" + encodeURIComponent($("#wifi-hostname").value); |
||||
url += "&staticip=" + encodeURIComponent($("#wifi-staticip").value); |
||||
url += "&netmask=" + encodeURIComponent($("#wifi-netmask").value); |
||||
url += "&gateway=" + encodeURIComponent($("#wifi-gateway").value); |
||||
|
||||
hideWarning(); |
||||
var cb = $("#special-button"); |
||||
addClass(cb, 'pure-button-disabled'); |
||||
ajaxSpin("POST", url, function(resp) { |
||||
removeClass(cb, 'pure-button-disabled'); |
||||
getWifiInfo(); |
||||
}, function(s, st) { |
||||
showWarning("Error: "+st); |
||||
removeClass(cb, 'pure-button-disabled'); |
||||
getWifiInfo(); |
||||
}); |
||||
} |
||||
|
||||
function doDhcp() { |
||||
$('#dhcp-on').removeAttribute('hidden'); |
||||
$('#dhcp-off').setAttribute('hidden', ''); |
||||
} |
||||
|
||||
function doStatic() { |
||||
$('#dhcp-off').removeAttribute('hidden'); |
||||
$('#dhcp-on').setAttribute('hidden', ''); |
||||
} |
@ -0,0 +1,64 @@ |
||||
#include "latch_json.h" |
||||
#include "user_funcs.h" |
||||
#include <json/jsontree.h> |
||||
#include <json/jsonparse.h> |
||||
#include <cmd.h> |
||||
|
||||
static LatchState latch; |
||||
|
||||
static void ICACHE_FLASH_ATTR |
||||
updateLatch() { |
||||
os_printf("ESP: Latch Callback\n"); |
||||
cmdCallback* latchCb = CMD_GetCbByName("Latch"); |
||||
if (latchCb->callback != -1) { |
||||
uint16_t crc = CMD_ResponseStart(CMD_CB_EVENTS, (uint32_t)&latchCb->callback, 0, 1); |
||||
crc = CMD_ResponseBody(crc, (uint8_t*)&latch, sizeof(LatchState)); |
||||
CMD_ResponseEnd(crc); |
||||
} |
||||
} |
||||
|
||||
static int ICACHE_FLASH_ATTR |
||||
latchGet(struct jsontree_context *js_ctx) { |
||||
return 0; |
||||
} |
||||
|
||||
static int ICACHE_FLASH_ATTR |
||||
latchSet(struct jsontree_context *js_ctx, struct jsonparse_state *parser) { |
||||
int type; |
||||
int ix = -1; |
||||
while ((type = jsonparse_next(parser)) != 0) { |
||||
if (type == JSON_TYPE_ARRAY) { |
||||
ix = -1; |
||||
} |
||||
else if (type == JSON_TYPE_OBJECT) { |
||||
ix++; |
||||
} |
||||
else if (type == JSON_TYPE_PAIR_NAME) { |
||||
if (jsonparse_strcmp_value(parser, "states") == 0) { |
||||
char latchStates[9]; |
||||
jsonparse_next(parser); jsonparse_next(parser); |
||||
jsonparse_copy_value(parser, latchStates, sizeof(latchStates)); |
||||
os_printf("latch states %s\n", latchStates); |
||||
uint8_t states = binToByte(latchStates); |
||||
latch.stateBits = states; |
||||
} |
||||
else if (jsonparse_strcmp_value(parser, "fallbackstates") == 0) { |
||||
char fallbackStates[9]; |
||||
jsonparse_next(parser); jsonparse_next(parser); |
||||
jsonparse_copy_value(parser, fallbackStates, sizeof(fallbackStates)); |
||||
os_printf("latch states %s\n", fallbackStates); |
||||
uint8_t fbstates = binToByte(fallbackStates); |
||||
latch.fallbackStateBits = fbstates; |
||||
} |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static struct jsontree_callback latchCallback = JSONTREE_CALLBACK(latchGet, latchSet); |
||||
static char* latchQueueName; |
||||
|
||||
JSONTREE_OBJECT(latchJsonObj, |
||||
JSONTREE_PAIR("states", &latchCallback), |
||||
JSONTREE_PAIR("fallbackstates", &latchCallback)); |
||||
|
@ -0,0 +1,12 @@ |
||||
#ifndef _LATCH_JSON_H_ |
||||
#define _LATCH_JSON_H_ |
||||
#include <esp8266.h> |
||||
|
||||
typedef struct { |
||||
uint8_t fallbackStateBits; |
||||
uint8_t stateBits; |
||||
uint8_t init; |
||||
uint8_t fallbackSecondsForBits[8]; |
||||
} LatchState; |
||||
|
||||
#endif // _LATCH_JSON_H_
|
Loading…
Reference in new issue