ESP8266 NodeMCU Web Server With BME680
ESP8266 NodeMCU Web Server With BME680
espan class="reading™> &de You can see that the XTEMPERATUREX placeholder is surrounded by tags, The HTML 4d attribute Is used to specify a unique id for an HTML element. Itis used to point to a specific style or it can be used by JavaScript to access and manipulate the element with that specific i. ‘That's what we're going to do. itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino!7/002 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, For instance, when the web server receives a new event with the latest temperature reading, we'll update the HTML element with the id * temp with the new reading, A similar process is done to update the other readings. Handle Events Create anew EventSource object and specify the URL of the page sending the updates. In our case, its events 5 (1Iwandow.evenssousce) ( ource("/events"); Once you've instantiated an event source, you can start listening for messages from the server with addEventListener() ‘These are the default event listeners, as shown here in the AsyncWebServer documentation. source. addtventListener(‘ open" console log( "events Connected"): , false); source.addtventListener("error', function(e) { AF (estarget.readyState | EventSource. OPEN) console, Tog( "Events Disconnected"); > dy false); source. addtventListener(‘nessage', function(e) { console-log("eesszge", e.data); , false): Then, add the event listener for “temperature” source. addtventlistenes(“tenpersture’, Funetion(e) ( When a new temperature reading Is available, the ESP#266 sends an event (" tenperature”) to the client, The following lines handle what happens when the browser receives that event. console. Log("tenperatur + e.cata); document .getElenentByd("tenp")-AnneratM ~ e.data; Basically, print the new readings on the browser console, and put the received data into the element with the corresponding id (*tenp") on the web page. A similar processor is done for humidity, pressure and gas resistance. source, addtventli oner(‘hunicity’, function(e) ¢ console Jog("hunicity", e.data)s snentyls( hun") SnnerTAL = e. data; documento ), False); source.addtventListener(‘pressure', function(e) { itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino!7/002 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, console Log(“pressure", eadat 3 sment8ya("pres*) AnnerWTH document ge dy false); source. addtventListener(’gas', function(e) { console. Tog("g35", e.¢ata); document gc 13s") AnerdTML = e.data; dy false); mente setup() Inthe setup() initialize the Serial Monitor, serial. begin(115200); Connect the £SP8266 to your local network and print the ESP8266 IP address. 11 Set device as 2 WI-FI Station WIFI bopin(ssid, password): while (MEFL.status() [= Wh_CONMECTED) ( etay(s080); Sertal.printin("Setting as a Mi-Fi station.” > Sertal.print(“station 1P Address: °); rinhn(WFA20c3110()); serial.printin(); serial. Intialize the BME680 sensor. 11 Tok BHESO sensor 4S (ome. begin) ¢ Sertal.orintin(F(*Covlé not Find 3 valid avEsa@ sensor, check wirdng!*))s wile (1)5 ) 11 Set up oversampling and Filter initializes bee setTenperatureoversanping(BHE680_05_08); be settuniatyOversanpl.ng(BHESEE_OS_2K); be setPrassurcoversanping (BHESEO_OS_4x); be seUTTRF{terSize(QME68O_FILTER_SIZE_3); ne setcastieater(s28, 150); // 320% for 150 as Handle Requests When you access the ESP8266 IP address on the root / URL, send the text that is stored on the index html variable to build the web page and pass the processor as argument, so that all placeholders are replaced with the latest sensor readings. server.on("/", HTTP_GET, [](AsyncnebserverRequest. “request)( rrequest->send_P(208, "text/nen", index neml, processor); ye itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino! 10207/002 Server Event Source Set up the eve source on the server, 11 Handle Web Server Everts events. onconnect([](AsynetventSourceclient “client)( ie(chient-stastTa(y){ Serial printf("Chient reconnected! Last message TD that it got Ls: Au\n", eLlent->tastId(D)s > 11 Send event with nessag 11 and set ceconnect delay to 1 second elent->send(*nelio!", MULL, mitlis(), 18000); me server. addhandler(tevents); Finally, start the server, server.begin(): loop() In the 100p(). get new sensor readings: setanesaoneadings()s Print the new readings in the Serial Monitor. Serial. po (Temperature = 26 & \n", Kemperature); Serial peintf(*Hunidity = 1.26% \n", humtatty); Serial printf(“Pressure = X.24 nPa \o", pressure): sertal.prv (G86 Resistance = %.26 KOhn \o", gasReststance); serial. prineins Finally, send events to the browser with the newest sensor readings to update the web page 11 Send Events to the We> Server with the Sensor Readings i505 events. send( string (temperature). levents.send(ping” MULL ni ste(),"senperature” milLis(0)5 events. send(String(humlaity) ._str(),"humiaity" mil1is0)s events send( String (pressure) <_str(), pressure” ,wilis(0)s events. send( String gastesistance) <_str(),"g8s" milLis())s ‘The following diagram summarizes how Server-Sent Events work to update the web page. itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino! ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, 1207/002 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, Client (browser) Server (ESP8266) EventSource Open event stream (events) 2) Get new sensor readings addeventListener (‘temperature’) (Chumiaity’y ‘temperature’ (‘pressure’) r , (eos) humidity’ pressure’ ‘gas Update web page {new sensor readings) BME680 Uploading the Code Now, upload the code to your ESP8266, Make sure you have the right board and COM port selected. After uploading, open the Serial Monitor at a baud rate of 115200, Press the £5P8266 on-board RSTEN button, The IP address should be printed in the serial monitor. Som i jconfigsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv Imode:DI0, clock div:1 load: 0x3£££0018, len:4 load: 0x3£££001c, len: 928 Ino © tail 12 room 4 ‘Load: 040078000, len: 9280 ‘Load: 0%40080400, len: 5848 lentry 040080698 WiFi. 20x00, c30_drv:0x00,hd_drv:0x00, we Clatear Ish tse ee itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino! 1220o7mosiz021 ES8265 NodeMCU Web Server with BMESBO- Weather Staton | Random Nerd Tutorials Demonstration Open a browser in your local network and type the ESP8266 IP address, You should get access to the ESP8266 web server with the latest BME68O readings. Srewreesrune 28.51 °C 4 suneomry 59.44 % bee tase Aas 28.51 °C vanaoiry 59.44% 1003.62 hPa moss 22.85 KO Wrapping Up itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino! 13207/002 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, In this tutorial you've learned how to build an asynchronous web server weather station with the ESP8266 to display BME680 sensor readings - gas (air quality), temperature, humidity and pressure - and how to update the readings automatically on the web page using Server-Sent Events. We have other web server tutorials that you may like: ‘= ESP8266 DHT11/DHT22 Temperature and Humidity Web Server with Arduino IDE 1» E5P8266 Web Server - Control Outputs with Arduino IDE = ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity) ‘= ESP8266 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) We hope you've found this project interesting, Learn more about the ESP8266 with our resources: 1» Home Automation Using ESP8265 1 MicroPython Programming with ESP32 and ESP8266 1» More £5P8266 Projects and Tutorials. Thanks for reading. Se ee) me [eBook] MicroPython Programming with ESP32 and ESP8266 Learn howr to program and bold projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD » Recommended Resources Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, ‘Arduino, and Node-RED, itpsrandomnerdttorials.comfesp6268-nodemcu-bmes60-web-server-arduino! 1420o7iove024 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, Home Automation using ESP8266 eBook and video course » Build loT and home automation projects. Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience! What to Read Next. ESP8266 NodeMCU MQTT - Publish BME280 Sensor Readings (Arduino IDE) itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino! 18207/002 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, MicroPython: MQTT - Publish BME280 Sensor Readings (FSP32/ESP8266) MicroPython: DS18820 Temperature Sensor with ESP32 and ESP8266 [SOLVED] Failed to connect to ESP32: Timed out waiting for packet header itpssrandomnerdttorials.comfesp6268-nodemcu-bmes80-web-srver-arduino! 161207/002 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, arse wi rin iwiwanuy aero using inter ujas ann yaiere MicroPython: WS2812B Addressable RGB LEDS with ESP32 and ESP8266 Enjoyed this project? Stay updated by subscribing our weekly newsletter! Your Email Addres 5 thoughts on “ESP8266 NodeMCU Web Server with BME680 - Weather Station (Arduino IDE)" Abimbola ‘August 20, 2020 at 7:02 pm Great tutorial Please, could we have one tutorial on using ESP+SIM module, so that one could access the web by just putting the sim card (26, but preferably 36) directly on the module? Thank you in advance, Reply & Sara Santos August 21, 2020 at 11:01 am Hi We have this project using this ESP32 board. You can access the internet using https://randornerdtutorials.com/esp32-sim800}-publish-data-to-cloud nope this helps. Regards, sara Reply itpssrandomnerdttorials.comfesp8266-nodemcu-bme880-web-server-arduino! 17207/0202 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, Jaimie Blagg. ‘August 21, 2020 at 5:00 pm. Great tutorial, going to build it soon as my sensor arrives. Do you have any plans to integrate this with Homeassistant? Would love to put one in various rooms throughout the house Thanks Jaimie Reply & Sara Santos ‘August 21, 2020 at 5:04 pm Hi [Av the moment, we don't have any plans to use Home Assistant. Regards, sara Reply carl Novernber 22, 2020 at 6:56 pm | built this and expanded it using your other tutorials to 1. publish via MQTT 2. Send and display via Node Red dashboard 3. Added external data from Open Weather site. I therefore created a dashboard with both internal home environment conditions as well as external weather conditions, As usual, your tutorials are excellent and are so thorough that anyone can just integrate portions of your projects into ‘much larger and complex projects, The sky's the limit ! Thanks once again, Reply Leave a Comment itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino!o7iove024 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, Name * Email * Website DNotity me of follow-up comments by eral DINotity me of new posts by email Visit Maker Advisor - Tools and Gear for makers, hobbyists and Divers » Home Automation using ESP8266 eBook and video course » Build lov and home automation projects Build a Home Automation System from Scratch » With Raspberry Pi, P8266, Arduino, and Node-RED. itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino! 19207/002 ESP8266 NodeMCU Web Server with BMES80 - Weather Station | Random Nera Tutorials, ‘About Support Terms Privacy Polley Refunds MakerAdwsor:com Join the Lab Copyright® 2013-2021 -RandomNeraTUuorialscom- All Rights Reserved itpssrandomnerdttorials.comfesp6266-nodemcu-bmes80-web-server-arduino!