NOT WORKING

tried hex response implementation

ROLLBACK
This commit is contained in:
cschwinne 2016-10-20 20:20:38 +02:00
parent 6f8ff7b02e
commit c05b88a0f4
4 changed files with 53 additions and 108 deletions

View File

@ -1,4 +1,8 @@
toolbar preparation
color cycle
sequence
fade transition
simple slide transition
add toolbar conf in settings
additional color picker field
change slider height to relative values
@ -7,8 +11,12 @@ implement all settings setters
implement OTA lock / security
implement button
implement HSB slider option
implement ranges
implement discrete range color setter
implement discrete single color setter
change color submit from get to post, rewrite with args, requires no buffer
change color submit from rgb to hex
do not reboot after settings set -> add reboot button
svg icons in html
(get rid of spiffs, use progmem for html??)

View File

@ -9,12 +9,11 @@
function Startup()
{
setInterval('GetArduinoIO()', 5000);
GetArduinoIO();
setInterval('GetColor()', 5000);
GetColor();
}
function GetArduinoIO()
function GetColor()
{
nocache = "&nocache=" + Math.random() * 1000000;
var request = new XMLHttpRequest();
request.onreadystatechange = function()
{
@ -31,23 +30,13 @@
}
}
// send HTTP request
request.open("GET", "ajax_in/" + strA + strR + strG + strB + nocache, true);
request.open("GET", "/get", true);
request.send(null);
strA = "";
strR = "";
strG = "";
strB = "";
}
function GetCheck()
{
strA = "&A=" + Ctrl_form.SA.value;
strR = "&R=" + Ctrl_form.SR.value;
strG = "&G=" + Ctrl_form.SG.value;
strB = "&B=" + Ctrl_form.SB.value;
{
UpdateVals();
GetArduinoIO();
post('/set', {'COL': rgb2hex(Ctrl_form.SR.value, Ctrl_form.SG.value, Ctrl_form.SB.value)});
}
function rgb2hex(red, green, blue) {
var rgb = blue | (green << 8) | (red << 16);
@ -64,6 +53,26 @@
{
window.open("/settings","_self");
}
function post(path, params, method) { //http://stackoverflow.com/questions/133925/
method = method || "post"; // Set method to post by default.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
</script>
<style>
.ctrl_box {

View File

@ -6,7 +6,6 @@
<script>
function GetCurrent()
{
nocache = "&nocache=" + Math.random() * 1000000;
var request = new XMLHttpRequest();
request.onreadystatechange = function()
{
@ -47,7 +46,7 @@
}
}
// send HTTP request
request.open("GET", "get-settings/" + nocache, true);
request.open("GET", "/get-settings", true);
request.send(null);
}
function OpenMain()

View File

@ -36,8 +36,6 @@ boolean only_ap = false;
int led_amount = 16;
int nopwrled = 1;
char HTTP_req[150];
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;
@ -298,48 +296,6 @@ void XML_response_settings()
server.send(200, "text/xml", resp);
}
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return index;
}
}
else {
found = 0;
}
index++;
}
return 0;
}
uint8_t getNumberAfterStringPos(char str[], char spos)
{
String op;
boolean no_n = false;
int i = 0;
while (!no_n) {
if (str[spos + i + 1] > 47 && str[spos + i + 1] < 58)
{
op += str[spos + i + 1];
}
else {no_n = true;}
i++;
}
return op.toInt();
}
void handleSettingsSet()
{
if (server.hasArg("CSSID")) clientssid = server.arg("CSSID");
@ -438,41 +394,19 @@ void handleSettingsSet()
saveSettingsToEEPROM();
}
boolean handleSet(String req)
void handleSet()
{
Serial.println("handleSet:");
Serial.println(req);
req.toCharArray(HTTP_req, 150, 0);
if (!StrContains(HTTP_req, "ajax_in")) {
if (StrContains(HTTP_req, "get-settings"))
{
XML_response_settings();
return true;
}
return false;
}
int pos = 0;
pos = StrContains(HTTP_req, "A=");
if (pos > 0) {
bri = getNumberAfterStringPos(HTTP_req, pos);
}
pos = StrContains(HTTP_req, "R=");
if (pos > 0) {
col[0] = getNumberAfterStringPos(HTTP_req, pos);
}
pos = StrContains(HTTP_req, "G=");
if (pos > 0) {
col[1] = getNumberAfterStringPos(HTTP_req, pos);
}
pos = StrContains(HTTP_req, "B=");
if (pos > 0) {
col[2] = getNumberAfterStringPos(HTTP_req, pos);
}
Serial.println(col[0]);
XML_response();
setLeds();
return true;
if (server.hasArg("COL"))
{
String in = server.arg("COL");
// Get rid of '#' and convert it to integer
int num = (int) strtol( &in[1], NULL, 16);
col[0] = num >> 16;
col[1] = num >> 8 & 0xFF;
col[2] = num & 0xFF;
}
server.send(204);
setLeds();
}
//format bytes
@ -688,31 +622,26 @@ void setup() {
server.send(200, "text/plain", "Settings saved. Please wait for light to turn back on, then go to main page...");
reset();
});
server.on("/set", HTTP_POST, handleSet);
server.on("/get-settings", HTTP_GET, XML_response_settings);
if (!ota_lock){
//load editor
server.on("/edit", HTTP_GET, [](){
if(!handleFileRead("/edit.htm")) server.send(404, "text/plain", "FileNotFound");
});
//create file
server.on("/edit", HTTP_PUT, handleFileCreate);
//delete file
server.on("/edit", HTTP_DELETE, handleFileDelete);
//first callback is called after the request has ended with all parsed arguments
//second callback handles file uploads at that location
server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload);
//list directory
server.on("/list", HTTP_GET, handleFileList);
//kill module
server.on("/down", HTTP_GET, down);
//clear eeprom
server.on("/cleareeprom", HTTP_GET, clearEEPROM);
//init ota page
httpUpdater.setup(&server);
}
//called when the url is not defined here, ajax-in; get-settings
//called when the url is not defined
server.onNotFound([](){
if(!handleSet(server.uri())){
if(server.uri().indexOf("get")<0){
server.send(404, "text/plain", "FileNotFound");
} else {
XML_response();
}
});