{"id":89499,"date":"2019-09-19T13:46:25","date_gmt":"2019-09-19T13:46:25","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=89499"},"modified":"2020-04-15T15:14:14","modified_gmt":"2020-04-15T15:14:14","slug":"esp32-esp8266-raspberry-pi-lamp-server","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-esp8266-raspberry-pi-lamp-server\/","title":{"rendered":"ESP32\/ESP8266 Publish Data to Raspberry Pi LAMP Server"},"content":{"rendered":"\n<p>In this project you\u2019ll build an ESP32 or ESP8266 client that makes an HTTP POST request to a <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">Raspberry Pi <strong>LAMP<\/strong> server<\/a> (<strong>L<\/strong>inux, <strong>A<\/strong>pache, <strong>M<\/strong>ySQL, <strong>P<\/strong>HP). The Raspberry Pi has a PHP script to insert data (sensor readings) into a MySQL database.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Publish-Readings-MySQL.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Insert Data into MySQL Database running on Raspberry Pi\" class=\"wp-image-89530\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Publish-Readings-MySQL.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Publish-Readings-MySQL.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Publish-Readings-MySQL.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Publish-Readings-MySQL.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>You&#8217;ll also have a web page that displays the sensor readings, timestamps and other information stored in the database. You can visualize your data locally from any browser in your network. <\/p>\n\n\n\n<p><strong>Note: <\/strong> you can make this project <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-mysql-database-php\/\">accessible from anywhere in the world follow this project<\/a>.<\/p>\n\n\n\n<p>As an example, we&#8217;ll be using a BME280 sensor connected to an ESP board. You can modify the code provided to send readings from a different sensor or use multiple boards.<\/p>\n\n\n\n<p>To build this project, you&#8217;ll use these technologies:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span style=\"font-size: inherit; background-color: initial;\">Running LAMP server on Raspberry Pi<\/span><\/li><li>ESP32 or ESP8266 programmed with Arduino IDE<\/li><li>PHP script to insert data into MySQL and display it on a web page<\/li><li>MySQL database to store readings<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">0. Prerequisites<\/h2>\n\n\n\n<p>Before continuing with this tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You should be familiar with the Raspberry Pi board \u2013&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-raspberry-pi\/\" target=\"_blank\">read Getting Started with Raspberry Pi<\/a>;<\/li><li>You should have the Raspbian or Raspbian Lite operating system installed \u2013&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/\" target=\"_blank\">read Installing Raspbian Lite, Enabling and Connecting with SSH<\/a>;<\/li><li>You also need the following hardware: <ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/raspberry-pi-board\/\" target=\"_blank\">Raspberry Pi board<\/a>&nbsp;\u2013 read&nbsp;<a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/best-raspberry-pi-starter-kits\/\" target=\"_blank\">Best Raspberry Pi Starter Kits<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/microsd-card-raspberry-pi-16gb-class-10\/\" target=\"_blank\">MicroSD Card \u2013 16GB Class10<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-power-supply\/\" target=\"_blank\">Raspberry Pi Power Supply (5V 2.5A)<\/a><\/li><\/ul><\/li><li>To prepare a LAMP server on Raspberry Pi follow: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">Install Apache + MySQL + PHP (LAMP Server)<\/a><\/li><\/ul>\n\n\n\n<p class=\"rntbox rntclblue\">If you like home automation and you want to build a complete home automation system, I recommend downloading my <a href=\"https:\/\/randomnerdtutorials.com\/build-a-home-automation-system-for-100\/\">home automation course<\/a>.<\/p>\n\n\n\n<p>After having your Raspberry Pi board prepared with Raspbian OS and a LAMP server, you can continue with this tutorial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Hosting Your PHP Application and MySQL Database &#8211; Raspberry Pi<\/h2>\n\n\n\n<p>The goal of this project is to have your Raspberry Pi running a <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">LAMP server<\/a> that allows you to store sensor readings from the ESP32 or ESP8266. You can visualize the readings from any browser in your local network. <\/p>\n\n\n\n<p>Here&#8217;s a high level overview:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Overview.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"875\" height=\"801\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Overview.png?resize=875%2C801&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Hosting PHP Application and MySQL Database on Raspberry Pi to post ESP32 or ESP8266 Sensor Readings\" class=\"wp-image-89531\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Overview.png?w=875&amp;quality=100&amp;strip=all&amp;ssl=1 875w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Overview.png?resize=300%2C275&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Overview.png?resize=768%2C703&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>If you want to make your data accessible from anywhere, I recommend reading one of these projects instead:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-mysql-database-php\/\">ESP32\/ESP8266 Insert Data into MySQL Database using PHP and Arduino IDE<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/visualize-esp32-esp8266-sensor-readings-from-anywhere\/\">Visualize Your Sensor Readings from Anywhere in the World (ESP32\/ESP8266 + MySQL + PHP)<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. Preparing Your MySQL Database<\/h2>\n\n\n\n<p>After <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">installing a LAMP server and phpMyAdmin on Raspberry Pi<\/a>, you can login into phpMyAdmin. After that, follow the next steps to create your database and SQL table.<\/p>\n\n\n\n<p>Open your browser and type <strong>http:\/\/Your-Raspberry-Pi-IP-Address\/phpmyadmin<\/strong>), your should see the login page for phpMyAdmin web interface.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"753\" height=\"703\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-Raspberry-Pi-Open-phpMyAdmin-Login-Page.png?resize=753%2C703&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Open phpMyAdmin Login Page\" class=\"wp-image-89446\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-Raspberry-Pi-Open-phpMyAdmin-Login-Page.png?w=753&amp;quality=100&amp;strip=all&amp;ssl=1 753w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-Raspberry-Pi-Open-phpMyAdmin-Login-Page.png?resize=300%2C280&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><\/figure><\/div>\n\n\n\n<p>After login, you should see a similar page:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1067\" height=\"681\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/0-Raspberry-Pi-phpMyAdmin-Local-Database-MySQL.png?resize=1067%2C681&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi phpMyAdmin Local Database MySQL\" class=\"wp-image-89501\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/0-Raspberry-Pi-phpMyAdmin-Local-Database-MySQL.png?w=1067&amp;quality=100&amp;strip=all&amp;ssl=1 1067w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/0-Raspberry-Pi-phpMyAdmin-Local-Database-MySQL.png?resize=300%2C191&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/0-Raspberry-Pi-phpMyAdmin-Local-Database-MySQL.png?resize=768%2C490&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/0-Raspberry-Pi-phpMyAdmin-Local-Database-MySQL.png?resize=1024%2C654&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1067px) 100vw, 1067px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Creating a database<\/h3>\n\n\n\n<p><strong>1.<\/strong> Select the &#8220;<strong>Databases<\/strong>&#8221; menu at the top, complete the &#8220;<strong>Create database<\/strong>&#8221; fields:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>esp_data<\/li><li>utf8mb4_general_ci<\/li><\/ul>\n\n\n\n<p>Then, press the <strong>Create<\/strong> button:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"521\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/1-Raspberry-Pi-phpMyAdmin-create-new-database.png?resize=873%2C521&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi phpMyAdmin create new database\" class=\"wp-image-89502\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/1-Raspberry-Pi-phpMyAdmin-create-new-database.png?w=873&amp;quality=100&amp;strip=all&amp;ssl=1 873w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/1-Raspberry-Pi-phpMyAdmin-create-new-database.png?resize=300%2C179&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/1-Raspberry-Pi-phpMyAdmin-create-new-database.png?resize=768%2C458&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/figure><\/div>\n\n\n\n<p>That&#8217;s it! Your new database was created successfully. Now, save your database name because you&#8217;ll need it later:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Database name<\/strong>: esp_data<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Creating a SQL table<\/h3>\n\n\n\n<p>After creating your database, in the left sidebar select your database name <span class=\"rnthl rntliteral\">esp_data<\/span>:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"574\" height=\"331\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/2-Raspberry-Pi-phpMyAdmin-open-new-database.png?resize=574%2C331&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi phpMyAdmin open new database\" class=\"wp-image-89503\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/2-Raspberry-Pi-phpMyAdmin-open-new-database.png?w=574&amp;quality=100&amp;strip=all&amp;ssl=1 574w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/2-Raspberry-Pi-phpMyAdmin-open-new-database.png?resize=300%2C173&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntcorange\"><strong>Important: <\/strong> make sure you&#8217;ve opened the <span class=\"rnthl rntliteral\">esp_data<\/span> database. Then, click the SQL tab. If you don&#8217;t follow these exact steps and run the SQL query, you might create a table in the wrong database.<\/p>\n\n\n\n<p>Copy the SQL query in the following snippet:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">CREATE TABLE SensorData (\n    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n    sensor VARCHAR(30) NOT NULL,\n    location VARCHAR(30) NOT NULL,\n    value1 VARCHAR(10),\n    value2 VARCHAR(10),\n    value3 VARCHAR(10),\n    reading_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n)\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-ESP8266-PHP-MySQL\/raw\/master\/code\/SensorData_Table.sql\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Open the &#8220;SQL&#8221; tab, paste it in the SQL query field (highlighted with a red rectangle) and press the <strong>Go<\/strong> button to create your table:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1035\" height=\"640\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/3-Raspberry-Pi-phpMyAdmin-run-SQL.png?resize=1035%2C640&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi phpMyAdmin run SQL query\" class=\"wp-image-89504\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/3-Raspberry-Pi-phpMyAdmin-run-SQL.png?w=1035&amp;quality=100&amp;strip=all&amp;ssl=1 1035w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/3-Raspberry-Pi-phpMyAdmin-run-SQL.png?resize=300%2C186&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/3-Raspberry-Pi-phpMyAdmin-run-SQL.png?resize=768%2C475&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/3-Raspberry-Pi-phpMyAdmin-run-SQL.png?resize=1024%2C633&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1035px) 100vw, 1035px\" \/><\/figure><\/div>\n\n\n\n<p>This should appear if your table was created successfully:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1035\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/4-Raspberry-Pi-phpMyAdmin-run-SQL-table-created.png?resize=1035%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi phpMyAdmin run SQL table created\" class=\"wp-image-89505\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/4-Raspberry-Pi-phpMyAdmin-run-SQL-table-created.png?w=1035&amp;quality=100&amp;strip=all&amp;ssl=1 1035w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/4-Raspberry-Pi-phpMyAdmin-run-SQL-table-created.png?resize=300%2C122&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/4-Raspberry-Pi-phpMyAdmin-run-SQL-table-created.png?resize=768%2C313&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/4-Raspberry-Pi-phpMyAdmin-run-SQL-table-created.png?resize=1024%2C418&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1035px) 100vw, 1035px\" \/><\/figure><\/div>\n\n\n\n<p>After that, you should see your newly created table called <span class=\"rnthl rntliteral\">SensorData<\/span> in the <span class=\"rnthl rntliteral\">esp_data<\/span> database as shown in the figure below:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-ESP8266-PHPMyAdmin-View-SQL-Database.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1189\" height=\"410\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-phpMyAdmin-table-created-empty.png?resize=1189%2C410&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi phpMyAdmin table created empty\" class=\"wp-image-89506\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-phpMyAdmin-table-created-empty.png?w=1189&amp;quality=100&amp;strip=all&amp;ssl=1 1189w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-phpMyAdmin-table-created-empty.png?resize=300%2C103&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-phpMyAdmin-table-created-empty.png?resize=768%2C265&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/5-Raspberry-Pi-phpMyAdmin-table-created-empty.png?resize=1024%2C353&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1189px) 100vw, 1189px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">3. PHP Script HTTP POST &#8211; Insert Data in MySQL Database<\/h2>\n\n\n\n<p>In this section, we&#8217;re going to create a PHP script that is responsible for receiving incoming requests from the ESP32 or ESP8266 and inserting the data into a MySQL database.<\/p>\n\n\n\n<p>You can either run the next commands on a Raspberry Pi set as a desktop computer or using an <a href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/\">SSH connection<\/a>.<\/p>\n\n\n\n<p>If you&#8217;re connected to your Raspberry Pi with an SSH connection, type the next command to create a file in <span class=\"rnthl rntliteral\">\/var\/www\/html<\/span> directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:~ $ nano \/var\/www\/html\/post-esp-data.php<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"661\" height=\"258\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/11-Raspberry-Pi-Save-post-esp-data-PHP-file.png?resize=661%2C258&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Save post esp data PHP file\" class=\"wp-image-89535\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/11-Raspberry-Pi-Save-post-esp-data-PHP-file.png?w=661&amp;quality=100&amp;strip=all&amp;ssl=1 661w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/11-Raspberry-Pi-Save-post-esp-data-PHP-file.png?resize=300%2C117&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong> if you&#8217;re following this tutorial and you&#8217;re not familiar with PHP or MySQL, I recommend creating these exact files. Otherwise, you&#8217;ll need to modify the ESP sketch provided with different URL paths. <\/p>\n\n\n\n<p>Copy the following PHP script to the newly created file (<em>post-esp-data.php<\/em>):<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">&lt;?php\n\n\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-esp8266-mysql-database-php\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n$servername = &quot;localhost&quot;;\n\n\/\/ REPLACE with your Database name\n$dbname = &quot;REPLACE_WITH_YOUR_DATABASE_NAME&quot;;\n\/\/ REPLACE with Database user\n$username = &quot;REPLACE_WITH_YOUR_USERNAME&quot;;\n\/\/ REPLACE with Database user password\n$password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\n\/\/ Keep this API Key value to be compatible with the ESP32 code provided in the project page. \n\/\/ If you change this value, the ESP32 sketch needs to match\n$api_key_value = &quot;tPmAT5Ab3j7F9&quot;;\n\n$api_key= $sensor = $location = $value1 = $value2 = $value3 = &quot;&quot;;\n\nif ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {\n    $api_key = test_input($_POST[&quot;api_key&quot;]);\n    if($api_key == $api_key_value) {\n        $sensor = test_input($_POST[&quot;sensor&quot;]);\n        $location = test_input($_POST[&quot;location&quot;]);\n        $value1 = test_input($_POST[&quot;value1&quot;]);\n        $value2 = test_input($_POST[&quot;value2&quot;]);\n        $value3 = test_input($_POST[&quot;value3&quot;]);\n        \n        \/\/ Create connection\n        $conn = new mysqli($servername, $username, $password, $dbname);\n        \/\/ Check connection\n        if ($conn-&gt;connect_error) {\n            die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);\n        } \n        \n        $sql = &quot;INSERT INTO SensorData (sensor, location, value1, value2, value3)\n        VALUES ('&quot; . $sensor . &quot;', '&quot; . $location . &quot;', '&quot; . $value1 . &quot;', '&quot; . $value2 . &quot;', '&quot; . $value3 . &quot;')&quot;;\n        \n        if ($conn-&gt;query($sql) === TRUE) {\n            echo &quot;New record created successfully&quot;;\n        } \n        else {\n            echo &quot;Error: &quot; . $sql . &quot;&lt;br&gt;&quot; . $conn-&gt;error;\n        }\n    \n        $conn-&gt;close();\n    }\n    else {\n        echo &quot;Wrong API Key provided.&quot;;\n    }\n\n}\nelse {\n    echo &quot;No data posted with HTTP POST.&quot;;\n}\n\nfunction test_input($data) {\n    $data = trim($data);\n    $data = stripslashes($data);\n    $data = htmlspecialchars($data);\n    return $data;\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-ESP8266-PHP-MySQL\/raw\/master\/code\/post-esp-data.php\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Before saving the file, you need to modify the <span class=\"rnthl rntliteral\">$dbname<\/span>, <span class=\"rnthl rntliteral\">$username<\/span> and <span class=\"rnthl rntliteral\">$password<\/span> variables with your unique details:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Your Database name\n$dbname = \"esp_data\";\n\/\/ Your Database user\n$username = \"root\";\n\/\/ Your Database user password\n$password = \"YOUR_USER_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>After adding the database name, username and password, save the file (<strong>Ctrl+X<\/strong>, <strong>y<\/strong>, and <strong>Enter <\/strong>key) and continue with this tutorial.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"418\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/12-Raspberry-Pi-Saved-file-post-esp-data-PHP.png?resize=709%2C418&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Saved file post esp data PHP\" class=\"wp-image-89536\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/12-Raspberry-Pi-Saved-file-post-esp-data-PHP.png?w=709&amp;quality=100&amp;strip=all&amp;ssl=1 709w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/12-Raspberry-Pi-Saved-file-post-esp-data-PHP.png?resize=300%2C177&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 709px) 100vw, 709px\" \/><\/figure><\/div>\n\n\n\n<p>If you try to access your RPi IP address in the next URL path, you&#8217;ll see the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:\/\/You-Raspberry-Pi-IP-Address\/post-esp-data.php<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"575\" height=\"162\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/8-ESP32-ESP8266-PHP-Page-Save-Readings-to-Raspberry-Pi-Database-MySQL.png?resize=575%2C162&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 PHP Page Save Readings to Raspberry Pi Database MySQL\" class=\"wp-image-89509\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/8-ESP32-ESP8266-PHP-Page-Save-Readings-to-Raspberry-Pi-Database-MySQL.png?w=575&amp;quality=100&amp;strip=all&amp;ssl=1 575w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/8-ESP32-ESP8266-PHP-Page-Save-Readings-to-Raspberry-Pi-Database-MySQL.png?resize=300%2C85&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 575px) 100vw, 575px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">4. PHP Script &#8211; Display Database Content<\/h2>\n\n\n\n<p>Create another PHP file in the <span class=\"rnthl rntliteral\">\/var\/www\/html<\/span> directory that will display all the database content in a web page. Name your new file: <em>esp-data.php<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:~ $ nano \/var\/www\/html\/esp-data.php<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"661\" height=\"258\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/13-Raspberry-Pi-Save-esp-data-PHP-file.png?resize=661%2C258&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Save esp data PHP file\" class=\"wp-image-89537\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/13-Raspberry-Pi-Save-esp-data-PHP-file.png?w=661&amp;quality=100&amp;strip=all&amp;ssl=1 661w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/13-Raspberry-Pi-Save-esp-data-PHP-file.png?resize=300%2C117&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure><\/div>\n\n\n\n<p>Edit the newly created file (<em>esp-data.php<\/em>) and copy the following PHP script:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;&lt;body&gt;\n&lt;?php\n\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-esp8266-mysql-database-php\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n$servername = &quot;localhost&quot;;\n\n\/\/ REPLACE with your Database name\n$dbname = &quot;REPLACE_WITH_YOUR_DATABASE_NAME&quot;;\n\/\/ REPLACE with Database user\n$username = &quot;REPLACE_WITH_YOUR_USERNAME&quot;;\n\/\/ REPLACE with Database user password\n$password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\n\/\/ Create connection\n$conn = new mysqli($servername, $username, $password, $dbname);\n\/\/ Check connection\nif ($conn-&gt;connect_error) {\n    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);\n} \n\n$sql = &quot;SELECT id, sensor, location, value1, value2, value3, reading_time FROM SensorData ORDER BY id DESC&quot;;\n\necho '&lt;table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot;&gt;\n      &lt;tr&gt; \n        &lt;td&gt;ID&lt;\/td&gt; \n        &lt;td&gt;Sensor&lt;\/td&gt; \n        &lt;td&gt;Location&lt;\/td&gt; \n        &lt;td&gt;Value 1&lt;\/td&gt; \n        &lt;td&gt;Value 2&lt;\/td&gt;\n        &lt;td&gt;Value 3&lt;\/td&gt; \n        &lt;td&gt;Timestamp&lt;\/td&gt; \n      &lt;\/tr&gt;';\n \nif ($result = $conn-&gt;query($sql)) {\n    while ($row = $result-&gt;fetch_assoc()) {\n        $row_id = $row[&quot;id&quot;];\n        $row_sensor = $row[&quot;sensor&quot;];\n        $row_location = $row[&quot;location&quot;];\n        $row_value1 = $row[&quot;value1&quot;];\n        $row_value2 = $row[&quot;value2&quot;]; \n        $row_value3 = $row[&quot;value3&quot;]; \n        $row_reading_time = $row[&quot;reading_time&quot;];\n        \/\/ Uncomment to set timezone to - 1 hour (you can change 1 to any number)\n        \/\/$row_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$row_reading_time - 1 hours&quot;));\n      \n        \/\/ Uncomment to set timezone to + 4 hours (you can change 4 to any number)\n        \/\/$row_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$row_reading_time + 4 hours&quot;));\n      \n        echo '&lt;tr&gt; \n                &lt;td&gt;' . $row_id . '&lt;\/td&gt; \n                &lt;td&gt;' . $row_sensor . '&lt;\/td&gt; \n                &lt;td&gt;' . $row_location . '&lt;\/td&gt; \n                &lt;td&gt;' . $row_value1 . '&lt;\/td&gt; \n                &lt;td&gt;' . $row_value2 . '&lt;\/td&gt;\n                &lt;td&gt;' . $row_value3 . '&lt;\/td&gt; \n                &lt;td&gt;' . $row_reading_time . '&lt;\/td&gt; \n              &lt;\/tr&gt;';\n    }\n    $result-&gt;free();\n}\n\n$conn-&gt;close();\n?&gt; \n&lt;\/table&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-ESP8266-PHP-MySQL\/raw\/master\/code\/esp-data.php\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Add the <span class=\"rnthl rntliteral\">$dbname<\/span>, <span class=\"rnthl rntliteral\">$username<\/span> and <span class=\"rnthl rntliteral\">$password<\/span>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Your Database name\n$dbname = \"esp_data\";\n\/\/ Your Database user\n$username = \"root\";\n\/\/ Your Database user password\n$password = \"YOUR_USER_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>Save the file (<strong>Ctrl+X<\/strong>, <strong>y<\/strong>, and <strong>Enter <\/strong>key) and continue with this project.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"418\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/14-Raspberry-Pi-Saved-file-esp-data-PHP.png?resize=709%2C418&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Saved file esp data PHP\" class=\"wp-image-89538\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/14-Raspberry-Pi-Saved-file-esp-data-PHP.png?w=709&amp;quality=100&amp;strip=all&amp;ssl=1 709w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/14-Raspberry-Pi-Saved-file-esp-data-PHP.png?resize=300%2C177&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 709px) 100vw, 709px\" \/><\/figure><\/div>\n\n\n\n<p>If you try to access your Raspberry Pi IP Address in the following URL path, you&#8217;ll see the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:\/\/Your-Raspberry-Pi-IP-Address\/esp-data.php<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"505\" height=\"173\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/9-ESP32-ESP8266-PHP-Page-view-Reading.png?resize=505%2C173&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 PHP Page view Readings temperature humidity pressure BME280\" class=\"wp-image-89510\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/9-ESP32-ESP8266-PHP-Page-view-Reading.png?w=505&amp;quality=100&amp;strip=all&amp;ssl=1 505w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/9-ESP32-ESP8266-PHP-Page-view-Reading.png?resize=300%2C103&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 505px) 100vw, 505px\" \/><\/figure><\/div>\n\n\n\n<p>That&#8217;s it! If you see that empty table printed in your browser, it means that everything is ready. In the next section, you&#8217;ll learn how to insert data from your ESP32 or ESP8266 into the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Preparing Your ESP32 or ESP8266<\/h2>\n\n\n\n<p>This project is compatible with both the ESP32 and ESP8266 boards. You just need to assemble a simple circuit and upload the sketch provided to insert temperature, humidity, pressure and more into your database every 30 seconds.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>For this example we&#8217;ll get sensor readings from the BME280 sensor. Here&#8217;s a list of parts you need to build the circuit for this project:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\">ESP32 board<\/a>&nbsp;(read <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\">Best ESP32 dev boards<\/a>)<\/li><li>Alternative &#8211; <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\">ESP8266<\/a> board (read <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/best-esp8266-wi-fi-development-board\/\" target=\"_blank\">Best ESP8266 dev boards<\/a>)<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\">BME280 sensor<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\">Jumper wires<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematics<\/h3>\n\n\n\n<p>The BME280 sensor module we\u2019re using communicates via I2C communication protocol, so you need to connect it to the ESP32 or ESP8266 I2C pins.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">BME280 wiring to ESP32<\/h4>\n\n\n\n<p>The ESP32 I2C pins are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>GPIO 22:<\/strong>&nbsp;SCL (SCK)<\/li><li><strong>GPIO 21:<\/strong>&nbsp;SDA (SDI)<\/li><\/ul>\n\n\n\n<p>So, assemble your circuit as shown in the next schematic diagram (<a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">read complete Guide for ESP32 with BME280<\/a>).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"652\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?resize=750%2C652&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 wiring to ESP32\" class=\"wp-image-56623\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?resize=300%2C261&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntclblue\"><strong>Recommended reading:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pinout-reference-gpios\/\">ESP32 Pinout Reference Guide<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">BME280 wiring to ESP8266<\/h4>\n\n\n\n<p>The ESP8266 I2C pins are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>GPIO 5&nbsp;<\/strong>(D1): SCL (SCK)<\/li><li><strong>GPIO 4&nbsp;<\/strong>(D2): SDA (SDI)<\/li><\/ul>\n\n\n\n<p>Assemble your circuit as in the next schematic diagram if you&#8217;re using an ESP8266 board (<a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\">read complete Guide for ESP8266 with BME280<\/a>).<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"532\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP8266-BME280-Arduino-IDE.png?resize=705%2C532&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 wiring to ESP8266\" class=\"wp-image-85980\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP8266-BME280-Arduino-IDE.png?w=705&amp;quality=100&amp;strip=all&amp;ssl=1 705w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP8266-BME280-Arduino-IDE.png?resize=300%2C226&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntclblue\"><strong>Recommended reading:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">ESP8266 Pinout Reference Guide<\/a> <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ESP32\/ESP8266 Code<\/h3>\n\n\n\n<p>We\u2019ll program the ESP32\/ESP8266 using Arduino IDE, so you must have the ESP32\/ESP8266 add-on installed in your Arduino IDE. Follow one of the next tutorials depending on the board you&#8217;re using:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-windows-instructions\/\">Install the ESP32 Board in Arduino IDE<\/a> &#8211; you also need to <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">install the BME280 Library and Adafruit_Sensor library<\/a><\/li><li><a style=\"font-size: inherit; background-color: initial;\" href=\"https:\/\/randomnerdtutorials.com\/how-to-install-esp8266-board-arduino-ide\/\">Install the ESP8266 Board in Arduino IDE<\/a> &#8211; you also need to <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\">install the BME280 Library and Adafruit_Sensor library<\/a> <\/li><\/ul>\n\n\n\n<p>After installing the necessary board add-ons, copy the following code to your Arduino IDE, but don\u2019t upload it yet. You need to make some changes to make it work for you.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-esp8266-mysql-database-php\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n\n*\/\n\n#ifdef ESP32\n  #include &lt;WiFi.h&gt;\n  #include &lt;HTTPClient.h&gt;\n#else\n  #include &lt;ESP8266WiFi.h&gt;\n  #include &lt;ESP8266HTTPClient.h&gt;\n  #include &lt;WiFiClient.h&gt;\n#endif\n\n#include &lt;Wire.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;Adafruit_BME280.h&gt;\n\n\/\/ Replace with your network credentials\nconst char* ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\n\/\/ REPLACE with your Domain name and URL path or IP address with path\nconst char* serverName = &quot;http:\/\/example.com\/post-esp-data.php&quot;;\n\n\/\/ Keep this API Key value to be compatible with the PHP code provided in the project page. \n\/\/ If you change the apiKeyValue value, the PHP file \/post-esp-data.php also needs to have the same key \nString apiKeyValue = &quot;tPmAT5Ab3j7F9&quot;;\n\nString sensorName = &quot;BME280&quot;;\nString sensorLocation = &quot;Office&quot;;\n\n\/*#include &lt;SPI.h&gt;\n#define BME_SCK 18\n#define BME_MISO 19\n#define BME_MOSI 23\n#define BME_CS 5*\/\n\n#define SEALEVELPRESSURE_HPA (1013.25)\n\nAdafruit_BME280 bme;  \/\/ I2C\n\/\/Adafruit_BME280 bme(BME_CS);  \/\/ hardware SPI\n\/\/Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);  \/\/ software SPI\n\nvoid setup() {\n  Serial.begin(115200);\n  \n  WiFi.begin(ssid, password);\n  Serial.println(&quot;Connecting&quot;);\n  while(WiFi.status() != WL_CONNECTED) { \n    delay(500);\n    Serial.print(&quot;.&quot;);\n  }\n  Serial.println(&quot;&quot;);\n  Serial.print(&quot;Connected to WiFi network with IP Address: &quot;);\n  Serial.println(WiFi.localIP());\n\n  \/\/ (you can also pass in a Wire library object like &amp;Wire2)\n  bool status = bme.begin(0x76);\n  if (!status) {\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring or change I2C address!&quot;);\n    while (1);\n  }\n}\n\nvoid loop() {\n  \/\/Check WiFi connection status\n  if(WiFi.status()== WL_CONNECTED){\n    WiFiClient client;\n    HTTPClient http;\n    \n    \/\/ Your Domain name with URL path or IP address with path\n    http.begin(client, serverName);\n    \n    \/\/ Specify content-type header\n    http.addHeader(&quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded&quot;);\n    \n    \/\/ Prepare your HTTP POST request data\n    String httpRequestData = &quot;api_key=&quot; + apiKeyValue + &quot;&amp;sensor=&quot; + sensorName\n                          + &quot;&amp;location=&quot; + sensorLocation + &quot;&amp;value1=&quot; + String(bme.readTemperature())\n                          + &quot;&amp;value2=&quot; + String(bme.readHumidity()) + &quot;&amp;value3=&quot; + String(bme.readPressure()\/100.0F) + &quot;&quot;;\n    Serial.print(&quot;httpRequestData: &quot;);\n    Serial.println(httpRequestData);\n    \n    \/\/ You can comment the httpRequestData variable above\n    \/\/ then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)\n    \/\/String httpRequestData = &quot;api_key=tPmAT5Ab3j7F9&amp;sensor=BME280&amp;location=Office&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14&quot;;\n\n    \/\/ Send HTTP POST request\n    int httpResponseCode = http.POST(httpRequestData);\n     \n    \/\/ If you need an HTTP request with a content type: text\/plain\n    \/\/http.addHeader(&quot;Content-Type&quot;, &quot;text\/plain&quot;);\n    \/\/int httpResponseCode = http.POST(&quot;Hello, World!&quot;);\n    \n    \/\/ If you need an HTTP request with a content type: application\/json, use the following:\n    \/\/http.addHeader(&quot;Content-Type&quot;, &quot;application\/json&quot;);\n    \/\/int httpResponseCode = http.POST(&quot;{\\&quot;value1\\&quot;:\\&quot;19\\&quot;,\\&quot;value2\\&quot;:\\&quot;67\\&quot;,\\&quot;value3\\&quot;:\\&quot;78\\&quot;}&quot;);\n        \n    if (httpResponseCode&gt;0) {\n      Serial.print(&quot;HTTP Response code: &quot;);\n      Serial.println(httpResponseCode);\n    }\n    else {\n      Serial.print(&quot;Error code: &quot;);\n      Serial.println(httpResponseCode);\n    }\n    \/\/ Free resources\n    http.end();\n  }\n  else {\n    Serial.println(&quot;WiFi Disconnected&quot;);\n  }\n  \/\/Send an HTTP POST request every 30 seconds\n  delay(30000);  \n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-ESP8266-PHP-MySQL\/raw\/master\/code\/ESP32_ESP8266_MySQL_Database_PHP.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Setting your network credentials<\/h4>\n\n\n\n<p>You need to modify the following lines with your network credentials: SSID and password. The code is well commented on where you should make the changes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Replace with your network credentials\nconst char* ssid     = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Setting your serverName<\/h4>\n\n\n\n<p>You also need to type your Raspberry Pi IP address, so the ESP publishes the readings to your LAMP server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* serverName = \"http:\/\/Your-Raspberry-Pi-IP-Address\/post-esp-data.php\";<\/code><\/pre>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* serverName = \"http:\/\/192.168.1.86\/post-esp-data.php\";<\/code><\/pre>\n\n\n\n<p>Now, you can upload the code to your board. It should work straight away both in the ESP32 or ESP8266 board. If you want to learn how the code works, read the next section.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How the code works<\/h4>\n\n\n\n<p>This project is already quite long, so we won&#8217;t cover in detail how the code works, but here&#8217;s a quick summary:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Import all the libraries to make it work (it will import either the ESP32 or ESP8266 libraries based on the selected board in your Arduino IDE)<\/li><li>Set variables that you might want to change (<span class=\"rnthl rntliteral\">apiKeyValue<\/span>, <span class=\"rnthl rntliteral\">sensorName<\/span>, <span class=\"rnthl rntliteral\">sensorLocation<\/span>)<\/li><li>The <span class=\"rnthl rntliteral\">apiKeyValue<\/span> is just a random string that you can modify. It&#8217;s used for security reasons, so only anyone that knows your API key can publish data to your database<\/li><li>Initialize the serial communication for debugging purposes<\/li><li>Establish a Wi-Fi connection with your router<\/li><li>Initialize the BME280 to get readings<\/li><\/ul>\n\n\n\n<p>Then, in the <span class=\"rnthl rntliteral\">loop()<\/span> is where you actually make the HTTP POST request every 30 seconds with the latest BME280 readings:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Your Domain name with URL path or IP address with path\nhttp.begin(serverName);\n\n\/\/ Specify content-type header\nhttp.addHeader(\"Content-Type\", \"application\/x-www-form-urlencoded\");\n\n\/\/ Prepare your HTTP POST request data\nString httpRequestData = \"api_key=\" + apiKeyValue + \"&amp;sensor=\" + sensorName                      + \"&amp;location=\" + sensorLocation + \"&amp;value1=\" + String(bme.readTemperature())                      + \"&amp;value2=\" + String(bme.readHumidity()) + \"&amp;value3=\" + String(bme.readPressure()\/100.0F) + \"\";\n\nint httpResponseCode = http.POST(httpRequestData);<\/code><\/pre>\n\n\n\n<p>You can comment the <span class=\"rnthl rntliteral\">httpRequestData<\/span> variable above that concatenates all the BME280 readings and use the <span class=\"rnthl rntliteral\">httpRequestData<\/span> variable below for testing purposes:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String httpRequestData = \"api_key=tPmAT5Ab3j7F9&amp;sensor=BME280&amp;location=Office&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14\";<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>After completing all the steps, let your ESP board collect some readings and publish them to your server. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-BME280-Arduino-IDE-MySQL.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BME280 Arduino IDE MySQL\" class=\"wp-image-86000\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-BME280-Arduino-IDE-MySQL.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-BME280-Arduino-IDE-MySQL.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>If everything is correct, this is what you should see in your Arduino IDE Serial Monitor:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1022\" height=\"413\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-ESP32-ESP8266-Publish-Readings-to-Raspberry-Pi-Database-MySQL.png?resize=1022%2C413&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Publish Readings to Raspberry Pi Database MySQL\" class=\"wp-image-89511\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-ESP32-ESP8266-Publish-Readings-to-Raspberry-Pi-Database-MySQL.png?w=1022&amp;quality=100&amp;strip=all&amp;ssl=1 1022w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-ESP32-ESP8266-Publish-Readings-to-Raspberry-Pi-Database-MySQL.png?resize=300%2C121&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/10-ESP32-ESP8266-Publish-Readings-to-Raspberry-Pi-Database-MySQL.png?resize=768%2C310&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1022px) 100vw, 1022px\" \/><\/figure><\/div>\n\n\n\n<p>If you open your Raspberry Pi IP address in this URL path <strong>\/esp-data.php<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:\/\/Your-Raspberry-Pi-IP-Address\/esp-data.php<\/code><\/pre>\n\n\n\n<p>You should see the all the readings stored in your database. Refresh the web page to see the latest readings:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"787\" height=\"613\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/7-Raspberry-Pi-PHP-MySQL-view-ESP32-ESP8266-readings.png?resize=787%2C613&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi PHP MySQL view ESP32 ESP8266 readings\" class=\"wp-image-89508\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/7-Raspberry-Pi-PHP-MySQL-view-ESP32-ESP8266-readings.png?w=787&amp;quality=100&amp;strip=all&amp;ssl=1 787w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/7-Raspberry-Pi-PHP-MySQL-view-ESP32-ESP8266-readings.png?resize=300%2C234&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/7-Raspberry-Pi-PHP-MySQL-view-ESP32-ESP8266-readings.png?resize=768%2C598&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/figure><\/div>\n\n\n\n<p>You can also go to phpMyAdmin to manage the data stored in your <span class=\"rnthl rntliteral\">SensorData<\/span> table. You can delete it, edit, etc&#8230;<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-phpMyAdmin-table-publish-ESP32-ESP8266-readings.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"846\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-phpMyAdmin-table-publish-ESP32-ESP8266-readings.png?resize=1200%2C846&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi phpMyAdmin table publish ESP32 ESP8266 readings\" class=\"wp-image-89507\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-phpMyAdmin-table-publish-ESP32-ESP8266-readings.png?w=1226&amp;quality=100&amp;strip=all&amp;ssl=1 1226w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-phpMyAdmin-table-publish-ESP32-ESP8266-readings.png?resize=300%2C211&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-phpMyAdmin-table-publish-ESP32-ESP8266-readings.png?resize=768%2C541&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/6-Raspberry-Pi-phpMyAdmin-table-publish-ESP32-ESP8266-readings.png?resize=1024%2C722&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial you&#8217;ve learned how to publish sensor data into a database in your own local Raspberry Pi LAMP server.<\/p>\n\n\n\n<p>The example provided is as simple as possible so that you can understand how everything works. After understanding this example, you may change the appearance of the table, publish different sensor readings, publish from multiple ESP boards, and much more.<\/p>\n\n\n\n<p><strong>You might also like reading:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">[Course] <\/a><\/strong><span><strong><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a><\/strong><\/span><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">Raspberry Pi: Install Apache + MySQL + PHP (LAMP Server)<\/a><\/li><li><a style=\"font-size: inherit; background-color: initial;\" href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-mysql-database-php\/\">ESP Insert Data into MySQL Database using PHP and Arduino IDE<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/visualize-esp32-esp8266-sensor-readings-from-anywhere\/\">Visualize Your Sensor Readings from Anywhere (ESP + MySQL + PHP)<\/a> <\/li><\/ul>\n\n\n\n<p>I hope you liked this project. If you have any questions, post a comment below and we&#8217;ll try to get back to you.<\/p>\n\n\n\n<p class=\"rntbox rntclgray\">If you like ESP32, you might consider enrolling in our course &#8220;<a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a>&#8220;. You can also access our free <a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">ESP32 resources here<\/a>. <\/p>\n\n\n\n<p>Thank you for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project you\u2019ll build an ESP32 or ESP8266 client that makes an HTTP POST request to a Raspberry Pi LAMP server (Linux, Apache, MySQL, PHP). The Raspberry Pi has &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32\/ESP8266 Publish Data to Raspberry Pi LAMP Server\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-raspberry-pi-lamp-server\/#more-89499\" aria-label=\"Read more about ESP32\/ESP8266 Publish Data to Raspberry Pi LAMP Server\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":89530,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301,264,190,268],"tags":[],"class_list":["post-89499","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-raspberrypi","category-project","category-raspberry-pi","category-raspberry-pi-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/09\/Raspberry-Pi-LAMP-Server-ESP32-ESP8266-Publish-Readings-MySQL.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/89499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=89499"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/89499\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/89530"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=89499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=89499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=89499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}