So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By flagtrax
#60638
martinayotte wrote:But what is you original question ?
If your sketch doesn't work as expected, maybe it is the way you are defining your buttons.
Personally, I would rather use microajax from https://code.google.com/archive/p/microajax/ and define the button as follow :
Code: Select all<input type="button" value="On" onClick="microAjax('/socket1On', function(res) { } );" />


Hi Martin, thanks for the reply, it's hard to put my question into words I think, because it's not a "specific" how to. I found a way around my problem by placing an operation in the loop along with what was in there originally. In this case what I was trying to accomplish was to have an led to a fade repetitively when an "on" button was pressed at the browser end, continue that fade, until an "off" button was pressed. The only line that was in the loop was
Code: Select allserver.handleClient();
so I added the lines I needed to create the fade action. obviously one step would be done on each loop and still allow servicing of an incoming command (IE off button) when needed. I'm not sure if this is the proper way to do it but it worked and since precise timing is not needed in this case. it seemed to be the easiest solution for now. Also I see where you're going with the statement you provided. I'm not familiar with microajax yet, but I'll for sure put that on my "explore" list. Obviously I have a long way to go, thanks to you and the rest of the members for helping us through the frustrating parts :lol: Cheers
User avatar
By martinayotte
#60645 The microAjax is only used here to trigger the action. But in your new case, instead of using "onClick", you will need to use "onmousedown" and "onmouseup" and handle two different actions, one to start the fade and one to stop it.
http://www.w3resource.com/javascript/ev ... sedown.php
User avatar
By alex_g
#60699 HI,

I am a total newbie here, so don't take my answer as authoritative by any means, but it sounds to me like you need to get your head around "event-based" programming on the ESP (just as I do). This is an interesting model and certainly diverges a bit a bit from "old-school" simplistic programming with loops and functions, etc, as you described it.

Loops and functions are always there, of course, they won't suddenly go away, but they have to be used in a very particular way and in a strictly predefined context, so that they respond to events, rather than just run sequentially in some "main" routine, and also so that they do not violate some of the unusual ESP timing requirements, whereby they must all return within a set time.

I don't know if you've read this document, https://nodemcu.readthedocs.io/en/maste ... ork-in-lua. but it's all explained there. There's actually a copy on this site too, but it's suffered a formatting accident, so you may have missed it. And even if you're not coding in Lua, but in C, same principles apply.

My apologies if I'm prattling on about stuff you already know....