-
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
add ds18b20 module #2003
add ds18b20 module #2003
Conversation
I guess you'll want to drop |
TBH, I don't understand the desire to use C and write C libraries where Lua ones work fine. Lua developers can always tweak a Lua module if their needs aren't 100% aligned to the current module implementation -- and can do so without having to get into C or rebuild the firmware. In this case the core One-wire C library encapsulates everything that needs to be done in C. So why reimplement DS18B20 in C? |
My main problem is just the lack of available memory if I'll run all my scripts in pure Lua, so I try to off-load the most to C. |
I've been told that almost nothing needs to be running in memory - most if not all code can be loaded on demand, like using The DS18B20 is actually a good example of a code that might not be simple to keep out of memory: it needs one timer to wait those 750+ milliseconds between decoding and reading the temperature, and usually another timer to measure temperatures say every minute. How to write the |
If the code is linear, as in just a single pass through and no functions,
then that is true: nothing is kept in mem.
If there are functions declared, then each of those gets loaded into memory
first, then they get called whenever. I have no idea what happens to the
loaded functions after the dofile returns.
Also, is it possible to pass arguments to a dofile call? If not, then
parameter passing must be through some global variable scheme, which is
rather fragile.
Finally, if a callback needs to be setup for something, which is quite
common, then you'll probably need a closure of some kind. I found that in
most cases that is not viable to do, unless the code loaded with dofile is
itself an entire function that gets loaded.
Of course, I'm not a lua expert, so please take my comments with a grain of
salt, but that has been my experience.
…On Jun 11, 2017 7:52 PM, "Petr Stehlík" ***@***.***> wrote:
I've been told that almost nothing needs to be running in memory - most if
not all code can be loaded on demand, like dofile("ds18b20.lc"). The
available NodeMCU documentation covers 'require()' use only, though. No
detailed word about 'dofile()', IIRC. I think it would be great if NodeMCU
beginners could see some large-ish example programs that would show how to
keep only the necessary minimum of Lua code in memory. Then the need for
offloading Lua code to C modules would disappear, perhaps.
The DS18B20 is actually a good example of a code that might not be simple
to keep out of memory: it needs one timer to wait those 750+ milliseconds
between decoding and reading the temperature, and usually another timer to
measure temperatures say every minute. How to write the dofile() or
require() in a way that ensures the memory is indeed freed immediately and
completely?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2003 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQC6BkzvXnVT_pHLdp9mGtjDfGL5XarTks5sDH3LgaJpZM4N2byy>
.
|
@marcelstoer Marcel, thanks for the prompt. I am coming to a checkpoint in my Lua 5.3 work -- time to migrate into the Xtensa build environment -- so I will do this refresh first. 😄 |
app/modules/ds18b20.c
Outdated
} | ||
|
||
// no change to th and tl setting | ||
ds18b20_device_conf[0] = 0x4B; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put the magic numbers into #defines?
docs/en/modules/ds18b20.md
Outdated
- `RES` temperature resolution | ||
- `TEMP` temperature | ||
- `TEMP_DEC` temperature decimals for integer firmware | ||
- `PAR` sensor parasitc flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
docs/en/modules/ds18b20.md
Outdated
end | ||
end); | ||
|
||
-- print if temperature is greater or less then a defined value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
Can we have a quick voting among the maintainers as to whether to include this module? Terry already voted against it I understand. |
@marcelstoer, my vote is more of an abstain rather than a 👎 It's just that I personally don't see the point of doing this one in C and wouldn't personally use it, but I wouldn't wish to block its inclusion if other committers think that there is value in having it. |
My experience with this sensor is that people use it in many different ways. I guess that neither a C nor a Lua module would cover all. I regarded the old Lua module more like a template to start from and adapt to one's needs. The C module has a more "official" character and need more support effort on the long run. |
The argument against a C module is that it needs to be compiled-in. Arguments for are that it may use less memory, and be faster - which is good to ensure that any timing constraints on the 1wire bus are met. I believe the timing in this module is not critical (as it uses the onewire lib). I'd probably use this module in my devices. All up I give it a weak thumbs-up; merge it and if problems are reported in future then reconsider. |
How about we merge both #1996 and this one but cross-reference them in the documentation (I could do that after the merge)? |
OK, I've had a look at this code. I accept that this might be a good approach for @fetchbot 's specific requirements, but it is very functionally limited and I really don't see the point of doing this in C as it will run a lot slower than my or @vsky279 Lukas' Lua version. Why? and other points:
I still will register an abstain rather than a 👎 -- so long as we get resolution / consensus on the first 3 points. @nickandrew Nick what are your thoughts? Am I being too pedantic? |
@TerryE I think those are fair comments. My temp code treats the device IDs as a string or array rather than individual bytes (I also munge the byte order in a way that suits me). How much slower is the discovery algorithm than reading only a specified sensor? My temp code always does a select-all; convert; then goes through the algorithm to process all responses. I need to spend more time looking at this 😬 |
BTW,
I for one will stick a Lua version. It's faster and easier to tailor. As to the OW enumeration algo, it's pretty slow. |
I believe that sometimes making the wrong decision is "less bad" than not making a decision at all. I cross-linked the C/Lua module docs: http://nodemcu.readthedocs.io/en/latest/en/modules/ds18b20/ |
* add ds18b20 module * add intitial eeprom value definition * adjust read() function and address handling
Missing leading zero of decimal part? |
Guess you need to format tdec with leading zeros: print(string.format("%d,%04d", temp, tdec)) |
Strange behaviour at 0,0 C? Never show zero C temp- temp+tdec show -1 C when I expect zero. ` dstimer = tmr.create()
dstimer:start()` /Fisherman |
After a cold night the same effect occurs at all negative x.0 temps from -2.0, -3.0 to -9.0 |
@Fisherman48, have tried extending the wait time Line 188 out to 800 or 900 mSec. 760 is only 10mSec over the datasheet minimum, and the code might just be jumping in too early before the reading is complete in cold weather. I use 1sec in my Lua version but then again I do all of my device converts in parallel then loop around the devices to do the read, so it still works out a lot faster. |
dev
branch rather than formaster
.docs/en/*
.DS18B20 module in C rather than Lua #1996, #1883, #1820.