Esp8266 arduino button11/24/2023 ![]() String jsonString = JSON.stringify(readings) ![]() Readings = String(bme.readPressure()/100.0F) Readings = String(bme.readTemperature()) Get Sensor Readings and return JSON object Serial.println("Could not find a valid BME280 sensor, check wiring!") Create AsyncWebServer object on port 80Īdafruit_BME280 bme // BME280 connect to ESP32 I2C (GPIO 21 = SDA, GPIO 22 = SCL) Function that receives the message from the ESP32 with the readingsĬonst char* ssid = "REPLACE_WITH_YOUR_SSID" Ĭonst char* password = "REPLACE_WITH_YOUR_PASSWORD" When websocket is established, call the getReadings() function html /ws` Ĭonsole.log('Trying to open a WebSocket connection…') We won’t explain how the CSS for this web page works because it is not relevant for this tutorial. Feel free to change it to make the web page look as you wish. Ĭopy the following to the style.css file. The unique ids for the HTML element where we’ll display the humidity and pressure are humidity and pressure. We do a similar procedure for the humidity and pressure. In this case, the unique id is temperature. Notice that you need a unique id for that HTML tag so that later we know how to refer to this HTML element. ![]() The temperature will show up in the following paragraph between the tags. The following lines display a card for the temperature. We won’t go into much detail about the content of the HTML file. We’ll upload these files to the ESP8266 filesystem (LittleFS).Ĭopy the following to the index.html file. You should save the HTML, CSS, and JavaScript files inside a folder called datainside the Arduino sketch folder, as shown in the previous diagram. For that, wire the sensor to the default ESP8266 SCL ( GPIO 5) and SDA ( GPIO 4) pins, as shown in the following schematic diagram. We’re going to use I2C communication with the BME280 sensor module. You can also use any other sensor you’re familiar with. So, you need to wire a BME280 sensor to your ESP8266. To exemplify how to display sensor readings on a web server with the ESP8266, we’ll send sensor readings from a BME280 sensor to the browser. If you’re programming the ESP8266 using PlatformIO, you should add the following lines to the platformio.ini file to include the libraries (also change the Serial Monitor speed to 115200): monitor_speed = 115200Īdafruit/Adafruit Unified Sensor ^1.1.4 Building the Circuit Installing Libraries (VS Code + PlatformIO) zip Library and select the libraries you’ve just downloaded. Alternatively, in your Arduino IDE, you can go to Sketch> Include Library > Add. The ESPAsyncWebServer and ESPAsynTCP libraries aren’t available to install through the Arduino Library Manager, so you need to copy the library files to the Arduino Installation Libraries folder. ![]() Go to Sketch > Include Library > Manage Libraries and search for the library name. You can install the first two libraries using the Arduino Library Manager.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |