You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Here is the 'chatty' console output, that shows that the method in parsed request / url / or what ever is a "GET" (line 18) and NOT a "POST" as in req.method (line 13..15).... Lines 13..15 were 'progressively' figuring out of req.method returns really must the method as trimmed and as string... (because the logical expression - in original, first post's code line 50 and in my code 66 - just never made it to true).

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v94 Copyright 2016 G.Williams
    >
    =undefined
    Connecting to WiFi...
    Connected
    ip info: {"ip":"192.168.0.101","mac":"5c:cf:7f:c0:10:63"}
     1) Serving:         /?led=2
     2) method:          POST
     3) method:          "POST"
     4) typeof method:   string
     5) upd (url parsed:
    {
      "method": "GET",
      "host": "",
      "path": "/?led=2",
      "pathname": "/",
      "search": "?led=2",
      "port": null,
      "query": {
        "led": "2"
       }
     }
     6) query:           {"led":"2"}
     7) upd.query b:     true
     8) upd.query.led b: true
     9) (req.method == "POST"):
          true
    10) (req.method === "POST"):
          true
    11) (req.method === "POST" && upd.query && upd.query.led):
          true
     1) Serving:         /getTemp
     2) method:          GET
     3) method:          "GET"
     4) typeof method:   string
     5) upd (url parsed:
    {
      "method": "GET",
      "host": "",
      "path": "/getTemp",
      "pathname": "/getTemp",
      "search": null, "port": null, "query": null }
     6) query:           null
     7) upd.query b:     false
     9) (req.method == "POST"):
          false
    10) (req.method === "POST"):
          false
    

    Another point (about the code in previous post - lines 71..73) I would like to make is:

    The statement (line 72)

          digitalWrite([LED2,LED1], upd.query.led);
    

    gets lucky just because of the fact that the characters 0, 1, 2 have the same two least significant bits in combination on and of as the integer values 0,1,2,3. With a different coding that ASCII, this fails, and even with ASCII* encoding, it fails for more than 4 output lines / LED's in the array. Therefore (line 73),

          digitalWrite([LED2,LED1], parseInt(upd.query.led));
    

    makes it clear, and works up to 31 output lines LEDs... again, a comment, such as: // "0..3..9" have same bits on in LNIB as 0..3..9 saves everyone's day - LNIB being Least significant NIBble (half-byte).

About

Avatar for allObjects @allObjects started