-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not trying to make the SDK into a real OS. #999
Comments
Yes. No. Maybe. Software is hard, there's no way around that. I can totally appreciate people wanting to be able to send what they want to send, and have it sent. Sticking the head in the sand with regard to buffering is rarely a good thing though, especially on a resource constrained device, and it's not like string concatenation in Lua is hard. Besides, the SDK does have buffering support for several-kilobytes worth of a single-send() payload. We have a lot of work to do just to get a whole bunch of espconn_disconnect() calls out of a recv callback into a proper task context. I'm not going near than until we have Terry's nice task abstraction stuff in though. I would at very least hold off with introducing more espconn stuff until we have gotten our house in order, unless the submission strictly adheres to the SDK constraints/directives. |
Hi, I currently own 24 ESP-12s, which I'm developing to automate my home in different ways. I'm not a firmware collaborator (yet), but I have wrestled quite a bit on the lua side (please see my nodemcu-platform repo). I'm also a hardcore R&D software engineer by profession (C/C++/embedded TCL) with a long trajectory and even a few software patents, and an electronics engineer by university studies. I mention all this only to explain that, while new to this repo, I'm not exactly a noobsauce on either hw or sw sides. Before I explain my experience and make some suggestions on how to look at this issue, I have some questions:
|
@devyte, this all really outside the scope of this issue but I'll answer your two main points:
We've had to jump through a few hoops to ensure that we have sufficient RAM and Flash resources left for the developer, and leaving this margin continues to be one of our greatest challenges. Note that since the initial development of the firmware, Espressif have engaged in a separate community-lead initiative to develop and RTOS-based framework as an alternative to the SDK. However, its footprint is larger and on the ESP8266 at least, this makes its use with a Lua firmware variant impractical. |
Reliability is my highest priority. There's little point in using the ESP8266 with NodeMCU if a properly written program which follows all the rules also crashes at random. That said, I also want it to be easy to program, because that will encourage more applications and more DIY electronics. So the rules should be as simple as possible consistent with reliability. If NodeMCU can successfully abstract the tricky parts of the SDK, it will be easier to program. It's got to be balanced against resource use though, and it has got to be reliable. |
Thank you for the explanation @TerryE . I've been tracking this project for quite a while, and I've done my homework with regard to reading up on the background. I'm very aware of the community efforts, and it is precisely this that has inspired me to step forward with my own contributions. I do hope to eventually contribute to the nodemcu firmware core. This issue #999 is to discuss whether the platform should behave more like a true OS. My answer to that is a resounding no, because it's not a true OS, but rather a (glorified) embedded system, and the development perspective is therefore different from developing for a true OS. Anyone developing for this platform, whether on the C or Lua sides, must keep aware of this. However, @nickandrew has more or less hit the nail on the head as to the reason behind #993. For that particular issue, I would suggest implementing a different interface, or at least one that is more predictable. Why? Most users want to do multiple conn:send()s in one way or another before returning execution control. Of course, this currently doesn't work, so users get frustrated, and an avalanche of related issues get opened up, which nobody wants. Let's think about this for a moment. A queued send interface on the C side, or a queued send interface on the Lua side. I don't think there's doubt about which would be easier to use. An implementation on the C side would allow Lua users to eliminate any queuing mechanism on their side, thereby reducing Lua code, which in turn reduces mem footprint, which is the second point: resources. So, is there any chance of a C implementation requiring more resources than a Lua implementation? I would expect the answer to that is no, but then again I haven't yet delved sufficiently into the ESP firmware or hw details, so please correct me if I'm wrong. So, my point of view is: * By buffered connection I mean the mechanism used here, where a buffered connection is used in conjunction with a coroutine to accumulate payloads up to a size threshold (less than one MTU), then concatenate and send. In this context, send means actually send the data and wait till done, as opposed to just calling sk:send(). As a result,* memory doesn't fill up* no matter how many times in a row you call buffconn:send() before returning from Lua. That's why the httpserver can serve html files of any size, even when the html comes from lua scripts generating the html on the fly. |
Just tossing something into the hat here: what if sock.send() accepted an array? Would that be better/worse/ugly/creater-y? |
@jmattsson I don't think it would really help much. The instinctive usage is to call send() several times before returning control, and expect the payloads to get handled and sent under the hood. Arrays as arguments to send() would still accumulate and use up the heap before really sending anything. All newer users would attempt this, and then scratch their heads wondering why it doesn't work as expected. I had to investigate the reasons myself, and was looking for a solution to the downside of a lua-side queue similar to what @TerryE proposed, when I came across httpserver and the mechanism there. |
In the interim, would it make sense to change the way the |
@jmattsson Absolutely. |
The error handling in the |
Terry, do you want to keep this open? The discussion turned (again) very quickly into pros and cons of a queuing I believe it's hard to disagree with your
statement. In specific cases though people would argue wether a particular implementation would make NodeMCU more like a "real OS", thereby violating this policy, or not. |
I am a bit concerned about the issues raised in #993. Here we have a inexperienced (Lua firmware) developer trying to make nodeMCU Lua look more like a procedural implementation of the Lua language. It's not; it is layered on top of the non-OS SDK and basically has to operate within the constraints that the SDK imposes.
One of these constraints is that a task can only initiate one async espconn function, such as a send or a close. In 0.9x this wasn't enforced, and so applications could queue up multiple requests within a task activation and so would often crater as a result of resource exhaustion, and so Epressiff deprecated this.
I am really concerned about any attempts of making nodeMCU behave as a really process-orientated OS, by adding layers of resource queuing etc. on top of the SDK. IMO, all this will do is add some partial obfuscation of the true underlying nature of the SDK. As an implementation, 993 is also flawed. IMO, this type of modification to the nodeMCU core will destabilise it, but I don't want to close this, without first airing the principle amongst the other committers.
The text was updated successfully, but these errors were encountered: