logo elektroda
logo elektroda
X
logo elektroda

Wi-Fi thermometer with ESP8266 and DS18B20 - an alternative programming approach

kantacki 963 21
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21192183
    kantacki
    Level 10  
    Hi,

    I am a programmer and have written a program to operate a DS18B20 digital thermometer on the ESP8266.
    More details here:
    https://kalamlacki.eu/esp8266_termo.php .

    Regards,
    Luke
  • ADVERTISEMENT
  • #2 21192338
    inot
    Level 37  
    This is nothing new. There are plenty of such programmes.
  • #3 21192380
    kantacki
    Level 10  
    >>21192338 .
    And what do you have on the web somewhere that does exactly the same thing?
  • #4 21192411
    robig
    Level 23  
    A whole lot of it, from know how tutorials to GitHubs, etc.
    A colleague seems to have woken up from a nap after a few years :) .
  • #5 21192415
    inot
    Level 37  
    Maybe not completely the same, but it's about using the same elements.
    Examples: Link , Link .
  • #6 21192502
    xury
    Automation specialist
    In fact, praise is due. A couple of comments:
    First and foremost - ditch the Arduino IDE style in favour of platformio. Try it and you will forget the mega inconvenient Arduino IDE and the lack of Intelisense.
    Which in turn breaks down into cpp and h files to not "litter" in one ino. Believe me it will come in handy later when you start to appreciate the classes
    Once you get through this you will find that writing adding new functions is a snap even when you completely forget the code after a while. I'm writing this because I've been through it myself and believe it's better to get into good habits from the start. Then it's harder to break away.
    Get rid of Delay - Yes, I sometimes use delay for a quick effect, but it has no right to be in the so-called production code. Try to write your own handling of the time wasted waiting in a delay loop. You may find that you can do something useful in that time. Watchdog also does not like this word :) .
  • ADVERTISEMENT
  • #7 21192513
    c2h5oh
    Moderator
    The AI also wrote me a very similar programme. Even the IP address is the same.
    As my thermometer hangs on the balcony and is recharged from the solar cell, in addition to the temperature I also get information about the voltage on the battery.
  • #8 21192563
    kantacki
    Level 10  
    I agree that it is something similar to what I have, but not the same. E.g. in that link you provided, it doesn't have the configuration that my program has and the rewiring from AP mode to client and the option to reset the settings from the console, in yours there is only AP mode as far as I can see.

    Added after 23 [minutes]: .

    >>21192513 .

    Well no, my program was created before the GPT hut era. I have been using it in my own project to control the temperature in the house for a good few years.

    Added after 15 [minutes]: .

    This is what the temperature check looked like in January at my house:
    Wi-Fi thermometer with ESP8266 and DS18B20 - an alternative programming approach .
    The sensor performed brilliantly.
  • #9 21193834
    xury
    Automation specialist
    I don't want to criticise you in any way, but a project like Tasmota, for example, has everything you write about available plus much more.
  • #10 21194005
    kantacki
    Level 10  
    >>21193834 .
    You see, when I watch videos about Tasmota on youtube.com, I see control of Sonoff devices or wi-fi smart plugs and I don't see anywhere a simple temperature display after http, maybe I searched poorly. For me Tasmota is such a combo and my program is for a much simpler purpose, it doesn't have as much documentation, I would compare it to a lawnmower. If you have a link somewhere on how to do temperature derivation after http in Tasmota, I'd love to read or see what you send.
  • #12 21360369
    kantacki
    Level 10  
    Welcome,

    Since Tasmote for esp8266 and ds18b20 has been mentioned, I decided that I would play with it. I go to the binary releases page, upload with esptoot.py the tasmote.bin firmware and nothing, the hardware cold. And so I loaded the firmware one by one and the hardware came to life. And it only came to life when uploading tasmot-4m.bin to my nodemcu. It even looks cool, more professional than mine, that's a plus. I plugged the ds18b20 into the nodemcu and configures via the admin panel and ok it works, reads a new value from the thermometer every few seconds and rest services Tasmota under the

    http://192.168.4.1/cm?cmnd=Status%208

    gives a more or less json like this in response:

    {
    "StatusSNS": {
    "Time": "2023-11-05T12:49:05",
    "DS18B20": {
    "Id": "3C530457A8AC",
    "Temperature": 23.7
    },
    "TempUnit": "C"
    }
    }

    i.e. it does what it does for me.

    The main difference with my software is that Tasmota samples the thermometer every few seconds and gives the stored data on request from resta. In my case, the reading of the thermometer is done at the resta request, i.e. if we query every 5 minutes, only the thermometer is sampled every 5 minutes.
    This is very important because if such a nodemcu with ds18b20 is to work non-stop, you need to take into account the number of ds18b20 thermometer reading cycles which is limited and after which the thermometer simply stops working.

    When I had a project that reads ds18b20 every second, such a gaggle of them lasted 2 years 24/7 and had to be replaced.

    Do you know how to change the sampling frequency of the thermometer in Tasmota? So that, for example, it only polls the thermometer every minute.

    Greetings,
    Luke
  • ADVERTISEMENT
  • #13 21360505
    xury
    Automation specialist
    kantacki wrote:
    This is of great importance because if such a nodemcu with ds18b20 is to run nonstop then you have to take into account the number of ds18b20 thermometer reading cycles which is limited and after which the thermometer simply stops working.

    It's a good thing my DS18B20s don't know this, because they would have stopped working long ago. :) Every 10 seconds since 2018. You just happened to get the wrong pieces, as fakes do happen.
  • #14 21360616
    roman106
    Level 26  
    I don't know why people insist on the DS18B20. I connected a BME280 (much more accurate, factory calibrated with pressure measurement) to the ESP8266 and got a temperature reading from Supel's direct link. I set myself a reading every 5 minutes, because why measure the temperature outside (or in the room) more often?

    The temperature is displayed on the TM1637 display, and if I want, I can in the browser via https. And sometimes I'll fire myself up on an ARGB LED Matrix 32x8 and have a big display and colour.
  • #15 21360656
    xury
    Automation specialist
    roman106 wrote:
    I don't know why people insist on the DS18B20. I connected a BME280 (much more accurate, factory calibrated with pressure measurement)
    to the ESP8266.
    And you give it on a cable of say 10 metres. Do you give it outside? On this small PCB with no protection from the outside conditions?How long will it measure pressure correctly in the so called harsh environment How many of these do you give on one bus? Everything has its advantages and disadvantages.
  • ADVERTISEMENT
  • #16 21360680
    roman106
    Level 26  
    Why the assumption that I need a 10m cable? I have an electrical socket on the outside wall that I use for my lawnmower. There's a 5V power supply (phone charger) plugged in there, with a NodeMCU in a sealed electrical enclosure. The sensor itself in another small enclosure of my own construction. I have no need to put more than one sensor on the bus, so what do I have to combine? Does it work? It works as I planned and I don't need anything else.

    I have with 5 BME280 sensors, because the price was such that it was a shame to take just one. I tested them and the difference in readings was.... I can't remember... 0.1 degrees? I also got one DS18B20. And here I already had to set an offset for temperature and humidity, because it was "cheating". Temperature -0.4 degrees and humidity - 10%.
  • #17 21360684
    Karaczan
    Level 42  
    roman106 wrote:
    I also have one DS18B20. And here I already had to set an offset for temperature and humidity, because it was "cheating". Temperature -0.4 degrees and humidity - 10%.
    .

    I think you have mixed up the sensors ;) .
    DS18B20 is just a temperature sensor

    Perhaps you were referring to DHTs? Because they were/are still popular.
    E.g. DHT11 have a huge spread of parameters. DHT22 already better, a few I use are +-0.2°C and +-5% RH differences. But price-wise they are not viable today. I used to get a big pack at a good price, BMPs were definitely more expensive.
    Today it is the other way around ;) .
  • #18 21360851
    kantacki
    Level 10  
    I don't know, maybe I'm unlucky, but in my project since 2017 I had two Edimax SP-1101w smart plugs, which after five years started squeaking and stopped working. I replaced them with TP-links HS110s, so far they work. Likewise after 6 years they stopped connecting to the Wi-Fi nodemcu with DS18B20 and I had to replace them, maybe they were too cheap from Alledrogo for 12 PLN.

    10 seconds is already a definite interval. As the temperature from the DS18B20 is read every second, there were 31 million read cycles after 2 years. The thermometer was original, because from Dallas-Maxim samples for free from Germany, 4 came in 2004.

    If someone wants to do stress tests of these thermometers, you could hook it up to a nodemcu and do the readings over and over so that there are 60 million cycles in some shorter time and I am curious to see if they survive that.
  • #19 21361028
    roman106
    Level 26  
    Karaczan wrote:
    I think you have mixed up the sensors
    .
    Well. I have a temperature and humidity sensor added to the Sonoff TH10/16 AM2301, and inside is a DHT22. The subject is measuring the temperature in the living room, so why a DS18B20?

    BME280s were expensive at one time, but now have normal prices In addition to temperature they measure humidity and pressure.

    kantacki wrote:
    I had two Edimax SP-1101w smart plugs which after five years started to squeak and stopped working
    .
    Mine also started squeaking and stopped working last year. The culprit turned out to be a swollen capacitor. After replacing it, it works again.
  • #20 21363950
    ex-or
    Level 28  
    >>21360616
    roman106 wrote:
    ... DS18B20. [...] BME280 (much more accurate, ...
    .
    A reading of the catalogue data by no means confirms this opinion. Both the absolute numbers in the temperature ranges, as well as the notes to the data and the general description of the BME280: "the temperature sensor readings are used to compensate for pressure and humidity readings and can also be used to ESTIMATE the ambient temperature" (translation and emphasis mine).
  • #21 21364050
    khoam
    Level 42  
    roman106 wrote:
    BME280 were expensive at one time, but now have normal prices
    .
    Do you mean the original ones at 25 PLN apiece, or the clones on ali at 3 PLN apiece?

    There are alternative sensors that will be as accurate or even better than the DS18B20 for temperature measurement:

    Comparison table of temperature sensors with accuracy, temperature range, and interface. .
  • #22 21364240
    roman106
    Level 26  
    ex-or wrote:
    The reading of the catalogue data by no means supports this opinion
    .
    My private temperature readings do not send data to the local weather station, so are not even subject to annual calibration ;) .
    I have quite a few different thermometers at home (such a hobby) from watches with a thermometer, to weather stations with external sensors. The difference in readings on these off-the-shelf devices can be more than 1° where some thermometers cost a few €, so no surprise there. A set of 3 sensors from a weather station also show a difference after "standing off" in the same place. I remember once taking these wireless sensors apart looking for some possible adjustment, but there was nothing like that.

    As I mentioned, I have less than 10pc of these BME280 sensors (at 3.3 and 5V), I tested a few of them (I didn't want to do all of them) and they showed the same temperatures. And that's enough for me. I also have about 3 sensors from Sonoff and here, after uploading the Supli, I had to offset the readings because they simply deviated from my patterns. And on the original software there is no possibility to enter an offset.

    The outdoor thermometer in the garden, the one I built myself, shows a temperature very close to the reading from the internet (local weather station). It can't be exactly the same because it is in a different location.

    khoam wrote:
    You mean the original ones at 25 PLN apiece, or the clones on ali at 3 PLN apiece?
    .
    You won't believe it, but they cost a few € apiece and meet my requirements. Their readings I did not offset i.e. the final temperature is the same as the original reading, which I cannot write about the others.

Topic summary

The discussion centers on programming a Wi-Fi thermometer using an ESP8266 microcontroller and a DS18B20 digital temperature sensor. The original program includes features such as switching between Access Point (AP) and client modes and resetting settings via a console, distinguishing it from many existing solutions. Suggestions include adopting PlatformIO over the Arduino IDE for better code organization and avoiding delay() functions to improve efficiency. Comparisons are made with Tasmota firmware, which supports DS18B20 sensors and provides JSON-formatted temperature data via HTTP, though it is considered more complex and multifunctional than the original simpler program. Alternative sensors like the BME280, which offers temperature, humidity, and pressure readings with factory calibration, are discussed, highlighting trade-offs in accuracy, cost, and environmental robustness. The longevity and reliability of DS18B20 sensors are debated, with some users reporting multi-year continuous operation, while others note failures possibly due to counterfeit units. The conversation also touches on practical deployment considerations such as sensor enclosure, cable length, and power supply. Overall, the thread provides insights into programming approaches, sensor selection, firmware options, and real-world application experiences for ESP8266-based temperature monitoring systems.
Summary generated by the language model.
ADVERTISEMENT