logo elektroda
logo elektroda
X
logo elektroda

TERMOSTAT program structure for ESP8266 in C++ with multiple sensors

Grzesiek_nowy 1263 8
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18990400
    Grzesiek_nowy
    Level 11  
    Hello, I am writing a TERMOSTAT program for ESP8266 in C++. The assumption is that it is to handle several temperature sensors. Each sensor is one thermostat. The thermostats are to be quite advanced, i.e. I am to be able to define for each day of the week (Monday, Tuesday, Wednesday, etc.) several time thresholds (e.g. 6:00, 10:00, 15:30, etc.) and in each threshold define a different temperature (e.g. 6:00 - 20 deg C, 10:00 - 22 deg C, 15:30 - 24 deg C). For now, these are preliminary assumptions and I am wondering about the structure of the program. Should I use an array, a structure or maybe a class and invoke objects e.g. thermostat1, thermostat2, thermostat3 etc. which will contain the above assumptions. I can't really think of a program skeleton. It seems to me that classes would be best for this. Please give me some suggestions.
  • ADVERTISEMENT
  • #2 18990471
    khoam
    Level 42  
    Is this to be an AVR (as in the title) or an ESP8266 (as in the post)?
  • #3 18990494
    Grzesiek_nowy
    Level 11  
    ESP8266 but written in C++ so could also be on AVR arduino. I am already correcting the title
  • ADVERTISEMENT
  • #4 18990518
    khoam
    Level 42  
    The ESP8266 is a bit hard to write in C++ without Arduino Core. There are quite a few examples on the web for operating thermostats via ESP8266, but using Arduino Core. For example:
    https://randomnerdtutorials.com/esp32-multiple-ds18b20-temperature-sensors/
    https://www.instructables.com/ESP8266-and-Multiple-Temperature-Sensors-DS18b20-W/
    https://mattala.com.au/2016/08/14/esp8266-multiple-ds18b20-temperature-sensor/
  • ADVERTISEMENT
  • #5 18991407
    Grzesiek_nowy
    Level 11  
    I use Arduino as much as possible. I currently use VS Code + Platformio as an IDE. Reading from several DS18B20s is not a problem but I am thinking about a code in which for each sensor there will be a base in which the days of the week will be defined and for each day a schedule divided into say 6 time intervals with different temperatures for each interval. In addition each DS should have its own schedule settings. I am wondering about the way to save this data in the program. An array of ? (quantitative), Structure? Objects ?
  • #6 18991961
    khoam
    Level 42  
    I'll write how I do it myself, but that doesn't mean it's the only or best way ;) .

    Each sensor has a representation in the form of an object that only has knowledge of what to measure and how often. It is the controller object that decides when the sensor object (sensor) will be queried for measured values - based on this, it is the controller that makes the decision, which it communicates to the actuator object, which represents, for example, a relay. In other words, the knowledge of the reading schedule is contained in the controller object. Whether such a schedule is made in the form of an array or a structure is a secondary matter - what is important is that it is easily adjustable from the user's point of view. I would probably first define a structure defining the time intervals in conjunction with the temperatures in those intervals, and then an array of days of the week, the elements of which would be those structures. There would be one such array for each sensor, which could also in turn be an array element of length equal to the number of sensors.

    When I write "array" I don't just mean specifically static [] arrays, but could also be dynamic containers e.g. std::vector, std::list, std::map etc. - it all depends on whether there will be a rigidly predetermined number of intervals or number of sensors.

    In C++ struct or class are practically the same thing, so structures too can contain functions that will be responsible for reading/writing a given structure along with error detection/correction.
  • ADVERTISEMENT
  • #7 18992040
    Grzesiek_nowy
    Level 11  
    Ok thanks for the hint. I am just starting to play with structures and objects. I'm maybe a bit more than a beginner - I've already written a program on ESP which is the gateway between my alarm and domoticz. Every second or so I use the MODBUS TCP protocol to ask my alarm (ROPAM) about the status of the inputs and outputs, then if anything has changed I send the status (JSON) to domoticz. I can also control certain outputs of the control panel from domoticz. There's also a simple server on ESP for configuration - assigning the right IDX to a specific control panel input or output (for domoticz). It works well for me, but when writing the program I was only using functions and I see a lot of potential in the structures.
    Can you provide an example of your solution?
  • #8 18992080
    khoam
    Level 42  
    Grzesiek_nowy wrote:
    Can you send some example of your solution?
    .
    Old and unfinished project: https://github.com/teuthid/eq
    Applies to AVR, but the sensor polling and actuator control mechanism I wrote about above is implemented.
  • #9 18992190
    Grzesiek_nowy
    Level 11  
    OK. Thank you. I'm trying to analyse it but I don't think I have enough knowledge yet.

Topic summary

The discussion revolves around developing a TERMOSTAT program for the ESP8266 using C++, designed to manage multiple temperature sensors (DS18B20). The user seeks advice on structuring the program to accommodate advanced thermostat functionalities, including daily schedules with multiple time thresholds and corresponding temperature settings. Suggestions include using classes to represent each sensor and a controller object to manage reading schedules and actuator controls. The importance of user-friendly data management is emphasized, with recommendations to utilize structures for time intervals and temperatures, and arrays for organizing schedules. Examples of existing projects and resources for ESP8266 thermostat implementations are also shared.
Summary generated by the language model.
ADVERTISEMENT