httpd alpha version - release

This commit is contained in:
Sebastien
2020-02-21 17:16:48 -05:00
parent d4576bbdd4
commit 168c15ce02
4 changed files with 64 additions and 52 deletions

View File

@@ -128,7 +128,7 @@ cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle){
size_t item_size; size_t item_size;
UBaseType_t uxItemsWaiting; UBaseType_t uxItemsWaiting;
vRingbufferGetInfo(buf_handle, NULL, NULL, NULL, NULL, &uxItemsWaiting); vRingbufferGetInfo(buf_handle, NULL, NULL, NULL, NULL, &uxItemsWaiting);
if(uxItemsWaiting>0){ for(int i = 0;i<uxItemsWaiting;i++){
message = (single_message_t *)xRingbufferReceive(buf_handle, &item_size, pdMS_TO_TICKS(50)); message = (single_message_t *)xRingbufferReceive(buf_handle, &item_size, pdMS_TO_TICKS(50));
//Check received data //Check received data
if (message== NULL) { if (message== NULL) {
@@ -179,7 +179,7 @@ esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_m
} }
vRingbufferGetInfo(subscriber->buf_handle,NULL,NULL,NULL,NULL,&uxItemsWaiting); vRingbufferGetInfo(subscriber->buf_handle,NULL,NULL,NULL,NULL,&uxItemsWaiting);
if(uxItemsWaiting>=subscriber->max_count){ if(uxItemsWaiting>=subscriber->max_count){
ESP_LOGW(tag,"messaged dropped for %s",str_or_unknown(subscriber->subscriber_name)); ESP_LOGD(tag,"messaged dropped for %s",str_or_unknown(subscriber->subscriber_name));
single_message_t * dummy = (single_message_t *)xRingbufferReceive(subscriber->buf_handle, &item_size, pdMS_TO_TICKS(50)); single_message_t * dummy = (single_message_t *)xRingbufferReceive(subscriber->buf_handle, &item_size, pdMS_TO_TICKS(50));
if (dummy== NULL) { if (dummy== NULL) {
ESP_LOGE(tag,"receive from buffer failed"); ESP_LOGE(tag,"receive from buffer failed");

View File

@@ -211,7 +211,7 @@ $(document).ready(function(){
} }
showMessage('please wait for the ESP32 to reboot', 'WARNING'); showMessage('please wait for the ESP32 to reboot', 'MESSAGING_WARNING');
$.ajax({ $.ajax({
url: '/config.json', url: '/config.json',
dataType: 'text', dataType: 'text',
@@ -224,7 +224,7 @@ $(document).ready(function(){
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
}, },
complete: function(response) { complete: function(response) {
//var returnedResponse = JSON.parse(response.responseText); //var returnedResponse = JSON.parse(response.responseText);
@@ -241,7 +241,7 @@ $(document).ready(function(){
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
}, },
complete: function(response) { complete: function(response) {
console.log('reboot call completed'); console.log('reboot call completed');
@@ -273,7 +273,7 @@ $(document).ready(function(){
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
} }
}); });
console.log('sent config JSON with headers:', autoexec1); console.log('sent config JSON with headers:', autoexec1);
@@ -306,7 +306,7 @@ $(document).ready(function(){
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
} }
}); });
console.log('sent config JSON with headers:', JSON.stringify(headers)); console.log('sent config JSON with headers:', JSON.stringify(headers));
@@ -361,7 +361,7 @@ $(document).ready(function(){
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
} }
}); });
console.log('sent config JSON with headers:', JSON.stringify(headers)); console.log('sent config JSON with headers:', JSON.stringify(headers));
@@ -378,11 +378,11 @@ $(document).ready(function(){
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) { if (xhttp.readyState == 4) {
if (xhttp.status == 200) { if (xhttp.status == 200) {
showMessage(xhttp.responseText, 'INFO') showMessage(xhttp.responseText, 'MESSAGING_INFO')
} else if (xhttp.status == 0) { } else if (xhttp.status == 0) {
showMessage("Upload connection was closed abruptly!", 'ERROR'); showMessage("Upload connection was closed abruptly!", 'MESSAGING_ERROR');
} else { } else {
showMessage(xhttp.status + " Error!\n" + xhttp.responseText, 'ERROR'); showMessage(xhttp.status + " Error!\n" + xhttp.responseText, 'MESSAGING_ERROR');
} }
} }
}; };
@@ -414,7 +414,7 @@ $(document).ready(function(){
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
} }
}); });
enableStatusTimer = true; enableStatusTimer = true;
@@ -597,7 +597,7 @@ function performConnect(conntype){
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
} }
}); });
@@ -645,18 +645,44 @@ function refreshAPHTML(data){
$( "#wifi-list" ).html(h) $( "#wifi-list" ).html(h)
} }
function getMessages() {
$.getJSON("/messages.json", function(data) {
data.forEach(function(msg) {
message: "{"ota_dsc":"Erasing flash complete","ota_pct":0}"
});
}) function getMessages() {
.fail(function(xhr, ajaxOptions, thrownError) { $.getJSON("/messages.json", function(data) {
console.log(xhr.status); data.forEach(function(msg) {
console.log(thrownError); var msg_age = msg["current_time"] - msg["sent_time"];
if (thrownError != '') showMessage(thrownError, 'ERROR'); switch (msg["class"]) {
}); case "MESSAGING_CLASS_OTA":
//message: "{"ota_dsc":"Erasing flash complete","ota_pct":0}"
var ota_data = JSON.parse(msg["message"]);
if (ota_data.hasOwnProperty('ota_pct') && ota_data['ota_pct'] != 0){
otapct = ota_data['ota_pct'];
$('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct);
$('.progress-bar').html(otapct+'%');
}
if (ota_data.hasOwnProperty('ota_dsc') && ota_data['ota_dsc'] != ''){
otadsc = ota_data['ota_dsc'];
$("span#flash-status").html(otadsc);
if (otadsc.match(/Error:/) || otapct > 95) {
blockFlashButton = false;
enableStatusTimer = true;
}
}
break;
case "MESSAGING_CLASS_SYSTEM":
showMessage(msg["message"], msg["type"],msg_age);
lastMsg = msg;
break;
default:
break;
}
});
})
.fail(function(xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
});
} }
function checkStatus(){ function checkStatus(){
RepeatCheckStatusInterval(); RepeatCheckStatusInterval();
@@ -780,29 +806,10 @@ function checkStatus(){
ver = data['version']; ver = data['version'];
$("span#foot-fw").html("fw: <strong>"+ver+"</strong>, mode: <strong>"+pname+"</strong>"); $("span#foot-fw").html("fw: <strong>"+ver+"</strong>, mode: <strong>"+pname+"</strong>");
} }
if (data.hasOwnProperty('ota_pct') && data['ota_pct'] != 0){ else {
otapct = data['ota_pct'];
$('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct);
$('.progress-bar').html(otapct+'%');
}
if (data.hasOwnProperty('ota_dsc') && data['ota_dsc'] != ''){
otadsc = data['ota_dsc'];
$("span#flash-status").html(otadsc);
if (otadsc.match(/Error:/) || otapct > 95) {
blockFlashButton = false;
enableStatusTimer = true;
}
} else {
$("span#flash-status").html(''); $("span#flash-status").html('');
} }
if (data.hasOwnProperty('message') && data['message'] != ''){
var msg = data['message'].text;
var severity = data['message'].severity;
if (msg != lastMsg) {
showMessage(msg, severity);
lastMsg = msg;
}
}
if (data.hasOwnProperty('Voltage')) { if (data.hasOwnProperty('Voltage')) {
var voltage = data['Voltage']; var voltage = data['Voltage'];
var layer; var layer;
@@ -832,7 +839,7 @@ function checkStatus(){
.fail(function(xhr, ajaxOptions, thrownError) { .fail(function(xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
blockAjax = false; blockAjax = false;
}); });
} }
@@ -888,20 +895,25 @@ function getConfig() {
.fail(function(xhr, ajaxOptions, thrownError) { .fail(function(xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
if (thrownError != '') showMessage(thrownError, 'ERROR'); if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
blockAjax = false; blockAjax = false;
}); });
} }
function showMessage(message, severity) { function showMessage(message, severity, age=0) {
if (severity == 'INFO') {
if (severity == 'MESSAGING_INFO') {
$('#message').css('background', '#6af'); $('#message').css('background', '#6af');
} else if (severity == 'WARNING') { } else if (severity == 'MESSAGING_WARNING') {
$('#message').css('background', '#ff0'); $('#message').css('background', '#ff0');
} else if (severity == 'MESSAGING_ERROR' ) {
$('#message').css('background', '#f00');
} else { } else {
$('#message').css('background', '#f00'); $('#message').css('background', '#f00');
} }
$('#message').html(message); $('#message').html(message);
$("#content").fadeTo("slow", 0.3, function() { $("#content").fadeTo("slow", 0.3, function() {
$("#message").show(500).delay(5000).hide(500, function() { $("#message").show(500).delay(5000).hide(500, function() {

View File

@@ -17,7 +17,7 @@
<script src="/res/test/bootstrap.min.js"></script> <!-- TODO delete --> <script src="/res/test/bootstrap.min.js"></script> <!-- TODO delete -->
<script src="/res/code.js"></script> <script src="/res/code.js"></script>
<script src="code.js"></script> <!-- TODO delete -->
<title>esp32-wifi-manager</title> <title>esp32-wifi-manager</title>