logo elektroda
logo elektroda
X
logo elektroda

Automatic light control via ESP8266 with temperature sensor

krzychu09pl 2295 2
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16013808
    krzychu09pl
    Level 2  
    Hello, I have a page on my ESP-01 with a button, with which I turn on / off the diode (ultimately it is to be an app for android - actually it already is) However, I would like to add a button, so that when it is turned on, the diode turns on and off depending on the temperature from the thermometer. Till now I had it done in style :
    if (client.readString.indexOf("/autom") !=-1 && temp1 <25 )
    włącz diodę 

    But after turning off the page in the browser, it stopped refreshing it- which is quite logical (and then what I want becomes meaningless because the temperature is not updated) I don't know if what I want is possible, surely it is, but somehow I have no idea :/

    code that controls the diode manually:
    Code: C / C++
    Log in, to see the code


    My idea was to make a module to control an electric heater, with the possibility of switching it on remotely via wifi and with the option of automatic switching on / off the heater at specific temperatures, as the heater "replaces" my diode and it is just an idea, that is why I wrote above about the diode ;)
  • ADVERTISEMENT
  • #2 16013875
    piotr411
    Level 22  
    If you are going to communicate with Android, then why in ESP a page?, the communication is done over TCP and you have all the data displayed in Android. Such a program design is a "garbage" superfluous.
  • #3 16031248
    krzbor
    Level 28  
    Not surprisingly, the state of the "digitalWrite" LED will not change when the page is switched off, it is inside "while(client.connected())". There are a couple of servers in Arduino (File->examples) - but they are built on a completely different principle. They are, however, worth a look. If you are thinking of building a "smart home" with many devices, I would advise against a solution based on the web server built into the ESP (fixed IP needed, problematic external access, security). I used a different solution - I have a traditional computer working as a web server along with PHP. I only connect to this machine, which is the 'contact box'. The various machines check in periodically to see if there is anything to do. They may then have different IP addresses and the ESPs always work as a client. Example - opening a gateway. Once the page has been loaded and authorised, I can select 'open gateway'. This will write the relevant contents of some file (via PHP). ESP calls periodically (e.g. every 1s) another page (PHP script) and if it learns that there is a command to open the gate, it will send the appropriate signal. This solution has a great advantage - all the key data is on one computer. So you can independently test the temperature and independently switch on the heater. You can programme the heater to switch on at a time (no need for an RTC in the system). You can turn off the heating when there is an active alarm, you can determine the advance of the radiator switching on based on the outside temperature, etc. The simplicity of ESP programming is also a big advantage - he's basically not 'smart', and I have the ease of changing the page in PHP - much more convenient than ESP programming
ADVERTISEMENT