nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.64k stars 3.12k forks source link

ow: add alarm scans and timing tweaking #3461

Closed stromnet closed 3 years ago

stromnet commented 3 years ago

This PR has two features:

  1. Adding support for 1-wire ALARM scan, which only returns devices in ALARM condition. Basically just using a different command during search.
  2. Add support to tweak the bit-banging timings.

While working with a AVR based 1-wire slave device (based on the https://github.com/stromnet/moat-owslave project), I had some timeouts & CRC issues when communicating with it from the NodeMCU, that I never had when using a PC-based LinkUSB interface with owfs. After some debugging it was revealed that the LinkUSB had much longer delays between each bit (or if it was byte? Don't remember now). Since my custom slave was a bit too slow to react in some cases, this caused issues. By adding ow.timings method, it is now possible to adjust these timings a bit, if necessary.

Note: I have tested these commits on top of 3.0-release_20201107 and not really dev, since I did not have time to verify the changes in newer releases at the moment. But nothing have happened in this module since that release, so should work equally fine on dev.

marcelstoer commented 3 years ago

Looks like a useful addition, thanks.

stromnet commented 3 years ago

Thanks!

TerryE commented 2 years ago

@stromnet Johan, thanks doe this contribution. I use OW in some of my systems -- and with up to a dozen DS18B20s on each. This has been rock solid for four years now, and I am keen that these timing adjustments haven't broken OW for me. I am abroad and away from my systems for the next 3 weeks. I will review these changes and test this out, then raise an issue if needed.

TerryE commented 2 years ago

@joysfera Petr, you might be interested in this as well. I know from #1995 that you were still working on OW + DS18B20s a year ago.

joysfera commented 2 years ago

@joysfera Petr, you might be interested in this as well. I know from #1995 that you were still working on OW + DS18B20s a year ago.

@TerryE thank you for the heads up but it's been two years since I rewrote my whole project (2600 LOC) from Lua to C. The final straw that forced me to give farewell to Lua after five years was the Lua source level incompatibility between ESP8266 and ESP32. In C (Arduino core) it is 100% "portable" and I can develop and run single source on both ESP (now possibily on four - including S2 and C3). My OneWire issues got resolved along that way as well.

stromnet commented 2 years ago

Always good with more testers, but I'm quite confident you will not notice any issues. The defaults are the same values as before, so the only potential impact I foresee would be the additional cycles to fetch the values from RAM instead of using constants. But when we're talking busylooping several (or even tens of) microseconds, that microscopic difference is most likely not an issue. Not sure about how many cycles a typical instruction is on the ESP8266, but my guess is that we're talking nanoseconds.

I have tested it with DS18B20's as well, although only a few on the same bus.