Chapter 3 - Temperature

Annex-Wifi Basic currently caters for Dallas 1-wire and DHT temperature sensors (but others may be added).
Using Dallas and DHT is eazy-peazy, and the following snippet shows how a DHT11 on pin 13 and multiple Dallas 1-wire sensors on pin 14 can all be used at the same time...
print tempr$(14)
dht.setup 13, 11: print dht.temp

But using them efficiently takes a little bit of thought.

NOTE:
  heat is generated by the movement of electrons, therefore every electronic device generates heat to some extent.
So if you wish to monitor ambient temperature you must ensure open-air access to avoid the sensor being affected by the build-up of internally-generated heat - because an enclosure with vents is still an enclosure which could retain a different temperature inside compared to outside.
Conversely, if you wish to monitor heat generated by a device then the sensor needs to be in good thermal contact with that device - possibly helped with the use of thermally conductive grease to reduce insulating air gaps.

In all cases, it requires hardware and software to interface with the sensor output to convert it into a usable format suitable for sending to some sort of display device - this chapter will focus on using the browser to display the temperature reading.

The system cannot be devoted to only sensing temperature, nor to only displaying a previous reading, because it must periodically do both.
Therefore an important system requirement is a timer to periodically keep reading the sensor output and displaying that reading.
The question then is... how frequently ?

That frequency will depend on what else is going on... if it is just being used as a thermometer then not a lot.
If it is used as a thermostat then it has to do comparisons with threshold temperature settings, control gpio's, and also to divert focus towards changing the threshold temperature settings (turning the thermostat up or down) whenever wished.
If being used as a timed temperature controller then it will need to maintain accurate time / date facilities as well as compare against a list of different temperature settings at different times / dates etc, plus the ability for user-adjustment of all settings - and ensure proper gpio control of relays and display outputs etc... quite a lot to do.

Annex-Wifi Basic has 2 timers available for use, but even just handling 1 timer properly needs some careful thought.
Timers work by interrupting whatever else the system is doing in order to service that timer interrupt before returning control back to the system to carry on with whatever it was doing before being interrupted.

Consider the situation where the previous interrupt has not yet had sufficient time to finish servicing that interrupt completely before another interrupt comes along to interrupt completion of the first. And that is just 1 timer that cannot keep pace with what it is required to do... so you can imagine the chaos of interrupting a busy timer with a second interrupting timer.
And that is without even considering any of the other event-driven interrupting facilities that might be in use.

Common-sense and compromise is required.
There is no point having a timer banging away every second if you are not displaying the seconds,
If you really need to count the seconds, it would be pointlessly impractical to also try to keep sampling the temperature at such a rapid rate,

TIP:  if you have different tasks to do at different frequencies, set the timer to handle the fastest, and have it keep decrementing one or more pres-set countdown variable until they eventually reach zero, whereupon they can process their less frequent tasks then pre-set their countdown variables ready to start another countdown delay again.

As an example - the timer could update a clock display every second, while decrementing a readtemp countdown variable from it's starting value of 30, which could be used to keep sampling and displaying the temperature at 30 second intervals.

The same principle can be used to carry out multiple different tasks at different rates, but perhaps take a leaf out of natures circadian rhythms and use prime numbers as countdown periods to reduce coincidences of them all happening at the same time.


CALIBRATION:  If accuracy is important you could use the 2 extremes of freezing and boiling points of water at your altitude as reference points.

Calibration is easier if you have a non-contact temperature gun available, which can be bought from places like ebay for less than a tenner:


I suggest one with a specified "Distance Spot Ratio" of 12:1 which will allow taking more pinpoint distance readings of hot-spot objects within the target area, ie: a specific cable that is getting hot, or an overheating transistor, or a circuit-breaker with high-resistance contacts, etc.

A non-contact gun makes it easy to check calibration of your sensor readings, which then offers opportunity to add an appropriate calibration offset bias to adjust results if required.