Current News

Moderator: Mmiscool

User avatar
By livetv
#56264 The good old TEMP() function has been upgraded. Now we can retrieve ROM codes from connected sensors and address sensors individually by their ROM codes (as well as by their positions in the chain of connected devices as before).

The same TEMP() function now behaves as follows:

- With no arguments: A string of space separated ROM codes of all connected sensors is returned.
- With a numeric argument: Temperature reading is returned from Nth connected sensor.
- With a 16 character ROM code (as a string): Reading is returned from the device of the given ROM code.

As you can see, the function is still backward compatible, so any code written with a single numeric argument will work as before.

Here is test code to demonstrate it:

Code: Select all[refresh]
cls
romcodes = temp()
wprint romcodes

t1 = temp(0)
t2 = temp(1)
t3 = temp(2)

c1 = temp("28ff101f731605e4")
c2 = temp("28ff4b0a7416031f")
c3 = temp("28ff8f5074160462")

wprint "<br><br>Reporting by device order:"
wprint "<br>1. " & t1
wprint "<br>2. " & t2
wprint "<br>3. " & t3

wprint "<br><br>Reporting by device ROM code:"
wprint "<br>1. " & c1
wprint "<br>2. " & c2
wprint "<br>3. " & c3

wprint "<br><br>"
button "Refresh", [refresh]
wait


The first time you run this, the queries reported by ROM code will fail (-127) because these are MY devices which I can assure you are not connected to your ESP8266. Simply copy the ROM codes that WERE returned and paste them into the queries and your sensors will be found. A ROM code should be exactly 16 characters.

If you hook up 3 sensors (like I did) and get the ROM codes set up right, you'll see roughly matching sets of temperature readings returned. However, if you disconnect one (like the middle one) you'll see that when the queries are done by device order (numeric argument) the list collapses by one and the last temperature reading does not correspond to the third sensor anymore. But in the second set where readings are reported by sensor ROM code, The list does not collapse, showing an error condition for the second sensor which is now missing.

If you are using only one sensor, just use TEMP(0) to get the job done. However, if you have multiple sensors and are worried about not knowing if one has failed (leaving you with readings from a different sensor), get a list of your ROM codes and use them. I recommend using the WRITE() and READ() functions to save ROM codes so that you don't have to change your program when changing sensors.
User avatar
By PhilTilson
#58743 Have only just seen this post while searching through the forums and documentation to update the Printed Reference.

I can't believe nobody has commented on this - it's a major improvement to the function!

Thanks for your efforts. :)

Phil