Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By DaveEvans
#57462 Regarding your error message - I have no idea, but to help others help you, suggest you first debug so you know where the error occurs, and then post the entire code here.

Regarding posting your code: IMHO, using code tags is preferred. Posting it as a text attachment is ok but adds one more step for your helpers here, and posting as a RAR is definitely not preferred...yet another step.
User avatar
By ChenBH
#57565
martinayotte wrote:
ChenBH wrote:Is there a better one out of the two?
I see that server.send and .on are way shorter methods when trying to parse a request from the client. But what will happen when I'll need to basic-authenticate the client? server.on only takes the first line of the request header.


You still confuse between ESP8266WiFi and ESP8266WebServer.
The first one is plain socket while the second is really WebServer built on top of the first one.
For basic-authenticate, simply look at the ESP8266WebServer/examples/HttpBasicAuth example.
If you still use ESP8266WiFi, then you will have to re-invent the wheel for every things.

For the exception, you need to install EspExceptionDecoder to get more meaningful details :
https://github.com/me-no-dev/EspExceptionDecoder


Thank you for the replay.
I'm trying to migrate my code to the ESP8266WebServer library.
I have this javascript:
Code: Select all  function GetArduinoIO()
      {
         nocache = "&nocache=" + Math.random() * 1000000;
         var request = new XMLHttpRequest();
         request.onreadystatechange = function()
         {
                var name, pin, on;
            if (this.readyState == 4) {
               if (this.status == 200) {
                            var myArr = JSON.parse(this.responseText);
                            for (var i=0; i<10 ; i++){
                                name = myArr[i].NAME;
                                pin = myArr[i].pin;
                                enable = myArr[i].enable;
                                on = myArr[i].ON;
                                document.getElementsByClassName("device")[i].innerHTML = name;
                                document.getElementsByClassName("pin")[i].innerHTML = pin;
                                document.getElementsByClassName("enable")[i].innerHTML = enable;
                                document.getElementsByClassName("on")[i].innerHTML = on;
                                if (enable == 0) {
                                    document.getElementsByClassName("IO_box")[i].style.background = "red";
                                }
                                else {
                                document.getElementsByClassName("IO_box")[i].style.background = "green";
                            }
                                document.getElementsByTagName("h1")[0].innerHTML = "Arduino Smart Home V0.0.200";
                     }         
               }
                    document.getElementsByTagName("h1")[0].innerHTML = "Arduino Smart Home V0.0.200";
                    document.getElementsByClassName("wrapper")[0].style.visibility = "visible";
            }
         }
            [b][u]request.open("GET", "jsoninputs" + nocache, true);[/u][/b]
            request.send();
           // setTimeout('GetArduinoIO()', 5000);
        }


I'm using no-cache argument after the /jsoninputs to prevent the browser from usin cached version of the request.
my server has this line of code to handle the request:
Code: Select allserver.on("/jsoninputs", handleJson);

The server keeps going to "handleNotFound" function.
What's wrong with my code?
Thanks :)

**
I'm currently trying to build the code from scratch, no errors so far. but thanks for the advices, I'll use them if necessary.