Testing SW from Espruino book #5817
Replies: 1 comment
-
Posted at 2017-09-30 by @allObjects Did you paste the code into the editor (right hand pane in Espruino Web IDE) and upload it to the board? It should work, because it responds to the form post... The "led" field parameter is either 0, 1, 2 or 3. Line 51 writes the bits of the value to both LEDs. if value 0 = 0b00 comes, it writes 0 to both LEDs, if value 2 = 0b10 comes, green LED turns on and red LED turns off. You can validate this by entering into the console (left hand pane in Espruino Web IDE): If you just upload the code, nothing is starting it... Espruino interprets the code and establishes just variables and functions. Therefore type into the console:
To make life easier while you develop and experiment with variations of the code, add as lasts lines to the code:
Posted at 2017-10-01 by L0cutus Yes, i'm uploading via the code editor panel, after uploading it i write to the console the onInit(); command and it does connect and show me the IP, the "GET" version of this code does work without problems but NOT the "POST" one. This code:
Line 1 (if ) never exeute the digitlWrite since it find always "GET" as the method and never the "POST" Thanks ! Posted at 2017-10-01 by @allObjects ...Ic And you may have just found some interesting thing, may be an issue in the I did some deep digging in the example, because it fooled me nicely... Below my 'console talkative', working code. The main changes and detections are:
In the next post is the 'chatty' console output, that shows that... Posted at 2017-10-01 by @allObjects 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).
Another point (about the code in previous post - lines 71..73) I would like to make is: The statement (line 72)
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),
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). Posted at 2017-10-02 by @gfwilliams I think your issue might just be how you copied the example code? In your code you have:
But the actual code is:
I think it'll work fine for you if you do that? Unfortuntely with these big bits of code it's hard to copy everything out without errors. If it's some help, I made the original code available online at https://github.com/espruino/making-things-smart - specifically I think https://github.com/espruino/making-things-smart/blob/master/experiment32.js is what you're after? Posted at 2017-10-02 by @allObjects ...in deed, that's how I got it working..., BUT, there seems to be an error in url.parse(): no matter what the method is - even if it is proven POST - the parsed object says for method: "GET". Posted at 2017-10-02 by Wilberforce
As Posted at 2017-10-02 by @allObjects @wilberforce, ooops... see THE point... then may be the url.parse(req,...) would be the right approach? I see no reason why not... As mentioned earlier, it is anyway funny that lower-case url is a global... Posted at 2017-10-02 by @gfwilliams global url? I'm not sure I follow... Sorry, I may have scanned through what you wrote a bit too quick. Posted at 2017-10-02 by @allObjects Regarding the Posted at 2017-10-03 by @gfwilliams It's available because it's built-in. I know it seems odd, but it's global in node.js, so that's what I do here for compatibility. Posted at 2017-10-03 by @allObjects Ic. ...and understand, because I'm more a client-side/browser then a a/vi-vid node.js JavaScript user. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-09-30 by L0cutus
Hello,
I'm trying some code from page 246 (Espruino Pico+ESP8266):
Unfortunately it doesn't work as it 'see' only GET as a method, not the POST, sorry for my english and my worst HTML knowledge ;-)
Beta Was this translation helpful? Give feedback.
All reactions