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

User avatar
By flagtrax
#60743
alex_g wrote:My apologies if I'm prattling on about stuff you already know....

Thanks Alex. I don't consider any offered information prattling. For me there is so much information to absorb it can be said there is just as much to be missed. Especially when one is trying to see something productive happen. Sometimes I feel that I read 10 hours to accomplish 10 minutes of progress. Add to that the fact that most of us new to a particular discipline don't even know what to ask or how to ask it. The IoT world is advancing faster than any techlology I've ever been involved in, and quite frankly it's sometimes hard for an old guy who keeps forgetting where his keys are, :? to remember what was learned yesterday :lol: Short version, I appreciate any and all information.
Cheers
User avatar
By alex_g
#60752 Cool! Glad I'm not barking up the totally wrong tree then.

The only reason I'm writing about this stuff is that this is what I'm actually figuring out myself at the moment. I see you're an Arduino/C man. I'm working with Lua, I know I'll eventually have to move to C to do more heavyweight stuff, but the rapid prototyping of ideas in Lua works very well for me, for now. I've never as much as seen an Arduino board close up. they sound cool, though....

This is the gist of what I've discovered so far: Mainly through trial and error. :lol:
If you're going to do any serious programming on the ESP, forget about loops. Yes, that's right, chuck 'em out, bye-bye, not going to be needing those...

You may think the above is an extreme statement, and OK, maybe it is, you're still allowed ikkle local fast loops to do your neat stuff. What you are NOT going to be seeing is large synchronous control loops with time delays for doing stuff. No siree. If you're using Lua you can kiss the neat coroutine system goodbye, too.

If you think you are going to get an array of LEDs to flash by looping through them and lighting each one on and off for a bit, forget it, ain't going to happen. Well, not if you want the rest of the system to be working, too...

The point is that the ESP controls all its own asynch scheduling, and if you try to interfere in this basically you will only end up hogging the system and locking everything up, since your loops will stop other things from working, e.g. minor things like wifi, UART, etc.

So the thing to do is run everything off system events, provided by the internal timer - Instead of YOUR loop controlling the flow of events, you rely on the timer (the timer.alarm() function in Lua is the most convenient, there should be some C equivalent).

If you want to imagine this graphically, think of the pace-drummer in a Roman slave galley, on every beat which he provides the slaves must perform their actions. They most definitely cannot go off and do their own scheduling, :lol: Or just think of it as a clock driving the operations, if you're that way inclined.

I've found I'm making a fair bit of progress now that I've grasped this concept, I may put up some tutorial/blog/whatchamacallit up later when I have enough material. I think most of the introductory tutorials don't really touch on this sufficiently.

HTH
Best Regards