Wifi thermometer in STA / AP mode with ESP8266

  • The thermometer uses the wifi chip ESP8266 in version 12E on the development board NodeMCU v3 Lolin. The Wifi chip, in addition to acquiring the data from the temperature sensors, also holds the web server where it reads the measured data. Data is always measured when loading the page. Inactivity data is not recorded. The web server allows you to run HTML + CSS code, which allows you to somehow make a nice graphical interface for rendering the temperature to the user, for example in a table.
  • There are two versions of this project, and the functionality of the website is the same. In both cases, the ESP8266 runs a webserver that renders temperatures to the table. Versions distinguish connectivity. In one case, it is possible to use the already existing LAN network to which the board connects and maintains a webserver on a static or dynamic IP address. When you enter the IP into the browser window, the user can access the desired page from the ESP with temperatures, or even the hostname - domain name can also be used when using mDNS.
  • In the latter case, the board sends its own SSID in AP mode as an access point. The user accesses the board by entering the password into the network (included in ESP8266). The board transmits a SSID with WPA / WPA2 PSK encryption or an open wifi network. Data is accessible only within the reach of this wifi network outside the LAN of the home network. The ESP also runs a DHCP server that, after successful user authentication, assigns an IP address from the range. The web page is located on the gateway IP address - ESP.
  • Temperature data is recorded from a pair of DS18B20 temperature sensors that are connected to a OneWire bus that allows one-wire data collection with the possibility of pulling the driver to ten to hundreds of meters. DS18B20 are manufactured in two main versions - an interior sensor in a transistor package, or a waterproof - exterior design in an aluminum tube. The OneWire bus is suitable for interference environments and up to 2 56 sensors can be connected to it. The individual sensors are divided by their factory address - the serial number. There are 2 main options for connecting the sensors. Normal connection and parasitic, in both can be powered to 3.3 - 5.5V. With normal wiring, the result is more reliable for longer distances.
  • Differences are already evident from schemes:
    Project parameters:
  • NodeMCU in an Access Point (AP) task or as a client on your LAN
  • Custom SSID and WPA2 PSK encryption, or without encryption
  • Custom IP (static), expand DNS flag
  • A secure web accessible through the ESP network and its reach with a responsive design
  • When the page loads the current info
  • Other possible variations:

    Source code for ESP8266 - open wifi network - AP

    #include <ESP8266WiFi.h>
    #include <ESP8266WebServer.h>
    #include <OneWire.h>                 
    #include <DallasTemperature.h>       
    #define ONE_WIRE_BUS 2               
    OneWire oneWire(ONE_WIRE_BUS);       
    DallasTemperature sensors(&oneWire);
    const char *ssid = "MojaOtvorenaESPsiet";
    ESP8266WebServer server(80);
    void handleRoot() {
      server.send(200, "text/html", "<head><meta charset='UTF-8'><meta name='author' content='Martin Chlebovec'><meta name='viewport' content='width=device-width, initial-scale=1.0'></head><style>body{  display: table;width: 100%;background: #dedede;text-align: center;}*{ -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */-moz-box-sizing: border-box;    /* Firefox, other Gecko */box-sizing: border-box;         /* Opera/IE 8+ */}.aa_h2{  font:100 5rem/1 Roboto;  text-transform: uppercase;}table{   background: #fff;}table,thead,tbody,tfoot,tr, td,th{  text-align: center;  margin: auto;  border:1px solid #dedede;  padding: 1rem;  width: 50%;}.table    { display: table; width: 50%; }.tr       { display: table-row;  }.thead    { display: table-header-group }.tbody    { display: table-row-group }.tfoot    { display: table-footer-group }.col      { display: table-column }.colgroup { display: table-column-group }.td, .th   { display: table-cell; width: 50%; }.caption  { display: table-caption }.table,.thead,.tbody,.tfoot,.tr,.td,.th{ text-align: center; margin: auto; padding: 1rem;}.table{  background: #fff;  margin: auto;  border:none;  padding: 0; margin-bottom: 5rem;}.th{font-weight: 700;border:1px solid #dedede;&:nth-child(odd){border-right:none;}}.td{font-weight: 300;border:1px solid #dedede;border-top:none;&:nth-child(odd){border-right:none;}}.aa_htmlTable{background: tomato;padding: 5rem;display: table;width: 100%;height: 100vh;vertical-align: middle;}.aa_css{background: skyblue;padding: 5rem;display: table;width: 100%;height: 100vh;vertical-align: middle;}.aa_ahmadawais{display: table;width: 100%;font: 100 1.2rem/2 Roboto;margin: 5rem auto;}</style><div class='aa_htmlTable'><table width=100%><thead><tr><th>Teplota</th><th>Hodnota</th></tr></thead><tbody><tr><td>Dnu</td><td>"+(String)sensors.getTempCByIndex(0)+" °C</td></tr><tr><td>Von</td><td>"+(String)sensors.getTempCByIndex(1)+" °C</td></tr></tbody></table></div>");
    void setup() {
      Serial.print("Konfigurujem access point...");
      IPAddress myIP = WiFi.softAPIP();
      Serial.print("IP adresa pristupoveho bodu je: ");
      server.on("/", handleRoot);
      Serial.println("Webserver bezi.");
      Serial.println("Vysiela SSID:");
      Serial.println("Bez hesla - otvoreny hotspot");
    void loop() {