<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pramaditya Fajri Migfar on Medium]]></title>
        <description><![CDATA[Stories by Pramaditya Fajri Migfar on Medium]]></description>
        <link>https://medium.com/@18221111?source=rss-e4f8a3e3090b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*EzHaKAelrbRqmAD1</url>
            <title>Stories by Pramaditya Fajri Migfar on Medium</title>
            <link>https://medium.com/@18221111?source=rss-e4f8a3e3090b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:10:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@18221111/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Project 10 — Data Visualization & Data Logging]]></title>
            <link>https://medium.com/@18221111/project-10-data-visualization-data-logging-331bb52509e5?source=rss-e4f8a3e3090b------2</link>
            <guid isPermaLink="false">https://medium.com/p/331bb52509e5</guid>
            <dc:creator><![CDATA[Pramaditya Fajri Migfar]]></dc:creator>
            <pubDate>Sun, 07 May 2023 15:59:07 GMT</pubDate>
            <atom:updated>2023-05-07T15:59:07.234Z</atom:updated>
            <content:encoded><![CDATA[<h3>Project 10 — Data Visualization &amp; Data Logging</h3><p>Melanjutnya project bonus sebelumnya tentang database, sekarang saya Pramaditya Fajri Migfar dari ITB dengan NIM 18221111 kembali lagi untuk mengerjakan project embedded tentang Data Visualization &amp; Data Logging. Langsung saja kita masuk ke alat dan bahan yang diperlukan untuk project kali ini.</p><h3><strong>Alat dan Bahan.</strong></h3><ol><li>ESP32</li><li>Kabel Micro USB</li><li>Laptop</li><li>Breadboar</li><li>BMP180</li><li>Kabel Jumper</li></ol><h3>Process.</h3><p>Langkah pertama yang dilakukan untuk project ini adalah membuat <em>database </em>baru, caranya adalah sama seperti project sebelumnya pada tab <strong>Create New Database.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4u6aol7UjJTp7BkKreEC1g.jpeg" /></figure><p>Kemudian, sama seperti project sebelumnya juga, klik Manage dan klik PhpMyAdmin dan buka tab SQL dan masukkan kode berikut.</p><pre>CREATE TABLE SensorData (<br>    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,<br>    sensor VARCHAR(30) NOT NULL,<br>    location VARCHAR(30) NOT NULL,<br>    value1 VARCHAR(10),<br>    value2 VARCHAR(10),<br>    value3 VARCHAR(10),<br>    reading_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mAjZ34_IJ5JzgXcXcHHtBw.jpeg" /></figure><p>Kode di atas, digunakan untuk menciptakan tabel Sensor pada <em>database</em> dengan atribut-atribut di atas. KEmudian, buat <em>script </em>PHP yang akan digunakan untuk memasukkan data ke dalam <em>database </em>tersebut. Berikut adalah <em>script</em> yang digunakan.</p><pre>&lt;!--<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/cloud-weather-station-esp32-esp8266/<br><br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br><br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br>--&gt;<br>&lt;?php<br>  $servername = &quot;localhost&quot;;<br><br>  // REPLACE with your Database name<br>  $dbname = &quot;REPLACE_WITH_YOUR_DATABASE_NAME&quot;;<br>  // REPLACE with Database user<br>  $username = &quot;REPLACE_WITH_YOUR_USERNAME&quot;;<br>  // REPLACE with Database user password<br>  $password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;<br><br>  function insertReading($sensor, $location, $value1, $value2, $value3) {<br>    global $servername, $username, $password, $dbname;<br><br>    // Create connection<br>    $conn = new mysqli($servername, $username, $password, $dbname);<br>    // Check connection<br>    if ($conn-&gt;connect_error) {<br>      die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>    }<br><br>    $sql = &quot;INSERT INTO SensorData (sensor, location, value1, value2, value3)<br>    VALUES (&#39;&quot; . $sensor . &quot;&#39;, &#39;&quot; . $location . &quot;&#39;, &#39;&quot; . $value1 . &quot;&#39;, &#39;&quot; . $value2 . &quot;&#39;, &#39;&quot; . $value3 . &quot;&#39;)&quot;;<br><br>    if ($conn-&gt;query($sql) === TRUE) {<br>      return &quot;New record created successfully&quot;;<br>    }<br>    else {<br>      return &quot;Error: &quot; . $sql . &quot;&lt;br&gt;&quot; . $conn-&gt;error;<br>    }<br>    $conn-&gt;close();<br>  }<br>  <br>  function getAllReadings($limit) {<br>    global $servername, $username, $password, $dbname;<br><br>    // Create connection<br>    $conn = new mysqli($servername, $username, $password, $dbname);<br>    // Check connection<br>    if ($conn-&gt;connect_error) {<br>      die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>    }<br><br>    $sql = &quot;SELECT id, sensor, location, value1, value2, value3, reading_time FROM SensorData order by reading_time desc limit &quot; . $limit;<br>    if ($result = $conn-&gt;query($sql)) {<br>      return $result;<br>    }<br>    else {<br>      return false;<br>    }<br>    $conn-&gt;close();<br>  }<br>  function getLastReadings() {<br>    global $servername, $username, $password, $dbname;<br><br>    // Create connection<br>    $conn = new mysqli($servername, $username, $password, $dbname);<br>    // Check connection<br>    if ($conn-&gt;connect_error) {<br>      die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>    }<br><br>    $sql = &quot;SELECT id, sensor, location, value1, value2, value3, reading_time FROM SensorData order by reading_time desc limit 1&quot; ;<br>    if ($result = $conn-&gt;query($sql)) {<br>      return $result-&gt;fetch_assoc();<br>    }<br>    else {<br>      return false;<br>    }<br>    $conn-&gt;close();<br>  }<br><br>  function minReading($limit, $value) {<br>     global $servername, $username, $password, $dbname;<br><br>    // Create connection<br>    $conn = new mysqli($servername, $username, $password, $dbname);<br>    // Check connection<br>    if ($conn-&gt;connect_error) {<br>      die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>    }<br><br>    $sql = &quot;SELECT MIN(&quot; . $value . &quot;) AS min_amount FROM (SELECT &quot; . $value . &quot; FROM SensorData order by reading_time desc limit &quot; . $limit . &quot;) AS min&quot;;<br>    if ($result = $conn-&gt;query($sql)) {<br>      return $result-&gt;fetch_assoc();<br>    }<br>    else {<br>      return false;<br>    }<br>    $conn-&gt;close();<br>  }<br><br>  function maxReading($limit, $value) {<br>     global $servername, $username, $password, $dbname;<br><br>    // Create connection<br>    $conn = new mysqli($servername, $username, $password, $dbname);<br>    // Check connection<br>    if ($conn-&gt;connect_error) {<br>      die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>    }<br><br>    $sql = &quot;SELECT MAX(&quot; . $value . &quot;) AS max_amount FROM (SELECT &quot; . $value . &quot; FROM SensorData order by reading_time desc limit &quot; . $limit . &quot;) AS max&quot;;<br>    if ($result = $conn-&gt;query($sql)) {<br>      return $result-&gt;fetch_assoc();<br>    }<br>    else {<br>      return false;<br>    }<br>    $conn-&gt;close();<br>  }<br><br>  function avgReading($limit, $value) {<br>     global $servername, $username, $password, $dbname;<br><br>    // Create connection<br>    $conn = new mysqli($servername, $username, $password, $dbname);<br>    // Check connection<br>    if ($conn-&gt;connect_error) {<br>      die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>    }<br><br>    $sql = &quot;SELECT AVG(&quot; . $value . &quot;) AS avg_amount FROM (SELECT &quot; . $value . &quot; FROM SensorData order by reading_time desc limit &quot; . $limit . &quot;) AS avg&quot;;<br>    if ($result = $conn-&gt;query($sql)) {<br>      return $result-&gt;fetch_assoc();<br>    }<br>    else {<br>      return false;<br>    }<br>    $conn-&gt;close();<br>  }<br>?&gt;</pre><p>Simpan <em>Script </em>dengan format esp-post-data.php dan upload pada folder public_html. Kemudian, setelah kita upload, buka website yourdomain.000webhost.com/esp-post-data.php dan akan muncul tampilan sebagai berikut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xpP6891cGV0dUQqUBN5Pgg.jpeg" /></figure><p>Selanjutnya, kita buat satu lagi file, tetapi berbeda dengan project sebelumnya, kita bukan membuat file PHP, melainkan file CSS untuk membuat tampilan website yang lebih menarik. Untuk <em>script-nya adalah sebagai berikut.</em></p><pre>/**<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/cloud-weather-station-esp32-esp8266/<br><br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br><br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br>**/<br>body {<br>    width: 60%;<br>    margin: auto;<br>    text-align: center;<br>    font-family: Arial;<br>    top: 50%;<br>    left: 50%;<br>}<br><br>@media screen and (max-width: 800px) {<br>    body {<br>        width: 100%;<br>    }<br>}<br><br>table {<br>    margin-left: auto;<br>    margin-right: auto;<br>}<br><br>div {<br>    margin-left: auto;<br>    margin-right: auto;<br>}<br><br>h2 { font-size: 2.5rem; }<br><br>.header {<br>  padding: 1rem;<br>  margin: 0 0 2rem 0;<br>  background: #f2f2f2;<br>}<br><br>h1 {<br>    font-size: 2rem;<br>    font-family: Arial, sans-serif;<br>    text-align: center;<br>    text-transform: uppercase;<br>}<br><br>.content {<br>    display: flex;<br>}<br><br>@media screen and (max-width: 500px) /* Mobile */ {<br>    .content {<br>        flex-direction: column;<br>    }<br>}<br><br>.mask {<br>    position: relative;<br>    overflow: hidden;<br>    display: block;<br>    width: 12.5rem;<br>    height: 6.25rem;<br>    margin: 1.25rem;<br>}<br><br>.semi-circle {<br>    position: relative;<br>    display: block;<br>    width: 12.5rem;<br>    height: 6.25rem;<br>    background: linear-gradient(to right, #3498db 0%, #05b027 33%, #f1c40f 70%, #c0392b 100%);<br>    border-radius: 50% 50% 50% 50% / 100% 100% 0% 0%;<br>}<br><br>.semi-circle::before {<br>    content: &quot;&quot;;<br>    position: absolute;<br>    bottom: 0;<br>    left: 50%;<br>    z-index: 2;<br>    display: block;<br>    width: 8.75rem;<br>    height: 4.375rem;<br>    margin-left: -4.375rem;<br>    background: #fff;<br>    border-radius: 50% 50% 50% 50% / 100% 100% 0% 0%;<br>}<br><br>.semi-circle--mask {<br>    position: absolute;<br>    top: 0;<br>    left: 0;<br>    width: 12.5rem;<br>    height: 12.5rem;<br>    background: transparent;<br>    transform: rotate(120deg) translate3d(0, 0, 0);<br>    transform-origin: center center;<br>    backface-visibility: hidden;<br>    transition: all 0.3s ease-in-out;<br>}<br><br>.semi-circle--mask::before {<br>    content: &quot;&quot;;<br>    position: absolute;<br>    top: 0;<br>    left: 0%;<br>    z-index: 2;<br>    display: block;<br>    width: 12.625rem;<br>    height: 6.375rem;<br>    margin: -1px 0 0 -1px;<br>    background: #f2f2f2;<br>    border-radius: 50% 50% 50% 50% / 100% 100% 0% 0%;<br>}<br><br>.gauge--2 .semi-circle { background: #3498db; }<br><br>.gauge--2 .semi-circle--mask { transform: rotate(20deg) translate3d(0, 0, 0); }<br><br>#tableReadings { border-collapse: collapse; }<br><br>#tableReadings td, #tableReadings th {<br>    border: 1px solid #ddd;<br>    padding: 10px;<br>}<br><br>#tableReadings tr:nth-child(even){ background-color: #f2f2f2; }<br><br>#tableReadings tr:hover { background-color: #ddd; }<br><br>#tableReadings th {<br>    padding: 10px;<br>    background-color: #2f4468;<br>    color: white;<br>}</pre><p>Berikutnya, kita buat satu lagi file PHP untuk memvisualisasikan data-data tersebut ke dalam <em>website</em> dalam bentuk <em>chart</em>. Untuk <em>script</em>-nya adalah sebagai berikut.</p><pre>&lt;!--<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/cloud-weather-station-esp32-esp8266/<br><br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br><br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br>--&gt;<br>&lt;?php<br>    include_once(&#39;esp-database.php&#39;);<br>    if (isset($_GET[&quot;readingsCount&quot;])){<br>      $data = $_GET[&quot;readingsCount&quot;];<br>      $data = trim($data);<br>      $data = stripslashes($data);<br>      $data = htmlspecialchars($data);<br>      $readings_count = $_GET[&quot;readingsCount&quot;];<br>    }<br>    // default readings count set to 20<br>    else {<br>      $readings_count = 20;<br>    }<br><br>    $last_reading = getLastReadings();<br>    $last_reading_temp = $last_reading[&quot;value1&quot;];<br>    $last_reading_humi = $last_reading[&quot;value2&quot;];<br>    $last_reading_time = $last_reading[&quot;reading_time&quot;];<br><br>    // Uncomment to set timezone to - 1 hour (you can change 1 to any number)<br>    //$last_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$last_reading_time - 1 hours&quot;));<br>    // Uncomment to set timezone to + 7 hours (you can change 7 to any number)<br>    //$last_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$last_reading_time + 7 hours&quot;));<br><br>    $min_temp = minReading($readings_count, &#39;value1&#39;);<br>    $max_temp = maxReading($readings_count, &#39;value1&#39;);<br>    $avg_temp = avgReading($readings_count, &#39;value1&#39;);<br><br>    $min_humi = minReading($readings_count, &#39;value2&#39;);<br>    $max_humi = maxReading($readings_count, &#39;value2&#39;);<br>    $avg_humi = avgReading($readings_count, &#39;value2&#39;);<br>?&gt;<br><br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>    &lt;head&gt;&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;<br><br>        &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;esp-style.css&quot;&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br>        &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;/head&gt;<br>    &lt;header class=&quot;header&quot;&gt;<br>        &lt;h1&gt; ESP Weather Station&lt;/h1&gt;<br>        &lt;form method=&quot;get&quot;&gt;<br>            &lt;input type=&quot;number&quot; name=&quot;readingsCount&quot; min=&quot;1&quot; placeholder=&quot;Number of readings (&lt;?php echo $readings_count; ?&gt;)&quot;&gt;<br>            &lt;input type=&quot;submit&quot; value=&quot;UPDATE&quot;&gt;<br>        &lt;/form&gt;<br>    &lt;/header&gt;<br>&lt;body&gt;<br>    &lt;p&gt;Last reading: &lt;?php echo $last_reading_time; ?&gt;&lt;/p&gt;<br>    &lt;section class=&quot;content&quot;&gt;<br>     &lt;div class=&quot;box gauge--1&quot;&gt;<br>     &lt;h3&gt;TEMPERATURE&lt;/h3&gt;<br>              &lt;div class=&quot;mask&quot;&gt;<br>     &lt;div class=&quot;semi-circle&quot;&gt;&lt;/div&gt;<br>     &lt;div class=&quot;semi-circle--mask&quot;&gt;&lt;/div&gt;<br>   &lt;/div&gt;<br>      &lt;p style=&quot;font-size: 30px;&quot; id=&quot;temp&quot;&gt;--&lt;/p&gt;<br>      &lt;table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot;&gt;<br>          &lt;tr&gt;<br>              &lt;th colspan=&quot;3&quot;&gt;Temperature &lt;?php echo $readings_count; ?&gt; readings&lt;/th&gt;<br>             &lt;/tr&gt;<br>          &lt;tr&gt;<br>              &lt;td&gt;Min&lt;/td&gt;<br>                    &lt;td&gt;Max&lt;/td&gt;<br>                    &lt;td&gt;Average&lt;/td&gt;<br>                &lt;/tr&gt;<br>                &lt;tr&gt;<br>                    &lt;td&gt;&lt;?php echo $min_temp[&#39;min_amount&#39;]; ?&gt; &amp;deg;C&lt;/td&gt;<br>                    &lt;td&gt;&lt;?php echo $max_temp[&#39;max_amount&#39;]; ?&gt; &amp;deg;C&lt;/td&gt;<br>                    &lt;td&gt;&lt;?php echo round($avg_temp[&#39;avg_amount&#39;], 2); ?&gt; &amp;deg;C&lt;/td&gt;<br>                &lt;/tr&gt;<br>            &lt;/table&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;box gauge--2&quot;&gt;<br>            &lt;h3&gt;HUMIDITY&lt;/h3&gt;<br>            &lt;div class=&quot;mask&quot;&gt;<br>                &lt;div class=&quot;semi-circle&quot;&gt;&lt;/div&gt;<br>                &lt;div class=&quot;semi-circle--mask&quot;&gt;&lt;/div&gt;<br>            &lt;/div&gt;<br>            &lt;p style=&quot;font-size: 30px;&quot; id=&quot;humi&quot;&gt;--&lt;/p&gt;<br>            &lt;table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot;&gt;<br>                &lt;tr&gt;<br>                    &lt;th colspan=&quot;3&quot;&gt;Humidity &lt;?php echo $readings_count; ?&gt; readings&lt;/th&gt;<br>                &lt;/tr&gt;<br>                &lt;tr&gt;<br>                    &lt;td&gt;Min&lt;/td&gt;<br>                    &lt;td&gt;Max&lt;/td&gt;<br>                    &lt;td&gt;Average&lt;/td&gt;<br>                &lt;/tr&gt;<br>                &lt;tr&gt;<br>                    &lt;td&gt;&lt;?php echo $min_humi[&#39;min_amount&#39;]; ?&gt; %&lt;/td&gt;<br>                    &lt;td&gt;&lt;?php echo $max_humi[&#39;max_amount&#39;]; ?&gt; %&lt;/td&gt;<br>                    &lt;td&gt;&lt;?php echo round($avg_humi[&#39;avg_amount&#39;], 2); ?&gt; %&lt;/td&gt;<br>                &lt;/tr&gt;<br>            &lt;/table&gt;<br>        &lt;/div&gt;<br>    &lt;/section&gt;<br>&lt;?php<br>    echo   &#39;&lt;h2&gt; View Latest &#39; . $readings_count . &#39; Readings&lt;/h2&gt;<br>            &lt;table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot; id=&quot;tableReadings&quot;&gt;<br>                &lt;tr&gt;<br>                    &lt;th&gt;ID&lt;/th&gt;<br>                    &lt;th&gt;Sensor&lt;/th&gt;<br>                    &lt;th&gt;Location&lt;/th&gt;<br>                    &lt;th&gt;Value 1&lt;/th&gt;<br>                    &lt;th&gt;Value 2&lt;/th&gt;<br>                    &lt;th&gt;Value 3&lt;/th&gt;<br>                    &lt;th&gt;Timestamp&lt;/th&gt;<br>                &lt;/tr&gt;&#39;;<br><br>    $result = getAllReadings($readings_count);<br>        if ($result) {<br>        while ($row = $result-&gt;fetch_assoc()) {<br>            $row_id = $row[&quot;id&quot;];<br>            $row_sensor = $row[&quot;sensor&quot;];<br>            $row_location = $row[&quot;location&quot;];<br>            $row_value1 = $row[&quot;value1&quot;];<br>            $row_value2 = $row[&quot;value2&quot;];<br>            $row_value3 = $row[&quot;value3&quot;];<br>            $row_reading_time = $row[&quot;reading_time&quot;];<br>            // Uncomment to set timezone to - 1 hour (you can change 1 to any number)<br>            //$row_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$row_reading_time - 1 hours&quot;));<br>            // Uncomment to set timezone to + 7 hours (you can change 7 to any number)<br>            //$row_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$row_reading_time + 7 hours&quot;));<br><br>            echo &#39;&lt;tr&gt;<br>                    &lt;td&gt;&#39; . $row_id . &#39;&lt;/td&gt;<br>                    &lt;td&gt;&#39; . $row_sensor . &#39;&lt;/td&gt;<br>                    &lt;td&gt;&#39; . $row_location . &#39;&lt;/td&gt;<br>                    &lt;td&gt;&#39; . $row_value1 . &#39;&lt;/td&gt;<br>                    &lt;td&gt;&#39; . $row_value2 . &#39;&lt;/td&gt;<br>                    &lt;td&gt;&#39; . $row_value3 . &#39;&lt;/td&gt;<br>                    &lt;td&gt;&#39; . $row_reading_time . &#39;&lt;/td&gt;<br>                  &lt;/tr&gt;&#39;;<br>        }<br>        echo &#39;&lt;/table&gt;&#39;;<br>        $result-&gt;free();<br>    }<br>?&gt;<br><br>&lt;script&gt;<br>    var value1 = &lt;?php echo $last_reading_temp; ?&gt;;<br>    var value2 = &lt;?php echo $last_reading_humi; ?&gt;;<br>    setTemperature(value1);<br>    setHumidity(value2);<br><br>    function setTemperature(curVal){<br>     //set range for Temperature in Celsius -5 Celsius to 38 Celsius<br>     var minTemp = -5.0;<br>     var maxTemp = 38.0;<br>        //set range for Temperature in Fahrenheit 23 Fahrenheit to 100 Fahrenheit<br>     //var minTemp = 23;<br>     //var maxTemp = 100;<br><br>     var newVal = scaleValue(curVal, [minTemp, maxTemp], [0, 180]);<br>     $(&#39;.gauge--1 .semi-circle--mask&#39;).attr({<br>      style: &#39;-webkit-transform: rotate(&#39; + newVal + &#39;deg);&#39; +<br>      &#39;-moz-transform: rotate(&#39; + newVal + &#39;deg);&#39; +<br>      &#39;transform: rotate(&#39; + newVal + &#39;deg);&#39;<br>     });<br>     $(&quot;#temp&quot;).text(curVal + &#39; ºC&#39;);<br>    }<br><br>    function setHumidity(curVal){<br>     //set range for Humidity percentage 0 % to 100 %<br>     var minHumi = 0;<br>     var maxHumi = 100;<br><br>     var newVal = scaleValue(curVal, [minHumi, maxHumi], [0, 180]);<br>     $(&#39;.gauge--2 .semi-circle--mask&#39;).attr({<br>      style: &#39;-webkit-transform: rotate(&#39; + newVal + &#39;deg);&#39; +<br>      &#39;-moz-transform: rotate(&#39; + newVal + &#39;deg);&#39; +<br>      &#39;transform: rotate(&#39; + newVal + &#39;deg);&#39;<br>     });<br>     $(&quot;#humi&quot;).text(curVal + &#39; %&#39;);<br>    }<br><br>    function scaleValue(value, from, to) {<br>        var scale = (to[1] - to[0]) / (from[1] - from[0]);<br>        var capped = Math.min(from[1], Math.max(from[0], value)) - from[0];<br>        return ~~(capped * scale + to[0]);<br>    }<br>&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Simpan <em>Script </em>dengan format esp-weather-station.php dan upload pada folder public_html. Kemudian, setelah kita upload, buka website yourdomain.000webhost.com/esp-weather-station.php dan akan muncul tampilan sebagai berikut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWhYhRx3hVBjg_wty-DEsg.jpeg" /></figure><p>Nah, kita berhasil melakukan setup pada website. Berikutnya, langsung saja kita ambil ESP32 dan kita rangkai dengan rangkaian sama seperti project sebelumnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LgdyPBCnKk4XNprXVK4vaw.jpeg" /></figure><p>Berikutnya, kita bisa mulai menyusun kode program pada Arduino IDE. Untuk kodenya, kurang lebih mirip dengan kode program yang kita gunakan pada <em>project</em> sebelumnya.</p><pre>/*<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/<br>  <br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br>  <br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br><br>*/<br><br>#include &lt;WiFi.h&gt;<br>#include &lt;WiFiClientSecure.h&gt;<br>#include &lt;HTTPClient.h&gt;<br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_Sensor.h&gt;<br>#include &lt;Adafruit_BME280.h&gt;<br><br>// Replace with your network credentials<br>const char* ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;<br>const char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;<br><br>// REPLACE with your Domain name and URL path or IP address with path<br>const char* serverName = &quot;https://example.com/esp-post-data.php&quot;;<br><br>// Keep this API Key value to be compatible with the PHP code provided in the project page. <br>// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key <br>String apiKeyValue = &quot;tPmAT5Ab3j7F9&quot;;<br><br>String sensorName = &quot;BME280&quot;;<br>String sensorLocation = &quot;Office&quot;;<br><br>/*#include &lt;SPI.h&gt;<br>#define BME_SCK 18<br>#define BME_MISO 19<br>#define BME_MOSI 23<br>#define BME_CS 5*/<br><br>#define SEALEVELPRESSURE_HPA (1013.25)<br><br>Adafruit_BME280 bme;  // I2C<br>//Adafruit_BME280 bme(BME_CS);  // hardware SPI<br>//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);  // software SPI<br><br>void setup() {<br>  Serial.begin(115200);<br>  <br>  WiFi.begin(ssid, password);<br>  Serial.println(&quot;Connecting&quot;);<br>  while(WiFi.status() != WL_CONNECTED) { <br>    delay(500);<br>    Serial.print(&quot;.&quot;);<br>  }<br>  Serial.println(&quot;&quot;);<br>  Serial.print(&quot;Connected to WiFi network with IP Address: &quot;);<br>  Serial.println(WiFi.localIP());<br><br>  // (you can also pass in a Wire library object like &amp;Wire2)<br>  bool status = bme.begin(0x76);<br>  if (!status) {<br>    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring or change I2C address!&quot;);<br>    while (1);<br>  }<br>}<br><br>void loop() {<br>  //Check WiFi connection status<br>  if(WiFi.status()== WL_CONNECTED){<br>    WiFiClientSecure *client = new WiFiClientSecure;<br>    client-&gt;setInsecure(); //don&#39;t use SSL certificate<br>    HTTPClient https;<br>    <br>    // Your Domain name with URL path or IP address with path<br>    https.begin(*client, serverName);<br>    <br>    // Specify content-type header<br>    https.addHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);<br>    <br>    // Prepare your HTTP POST request data<br>    String httpRequestData = &quot;api_key=&quot; + apiKeyValue + &quot;&amp;sensor=&quot; + sensorName<br>                          + &quot;&amp;location=&quot; + sensorLocation + &quot;&amp;value1=&quot; + String(bme.readTemperature())<br>                          + &quot;&amp;value2=&quot; + String(bme.readHumidity()) + &quot;&amp;value3=&quot; + String(bme.readPressure()/100.0F) + &quot;&quot;;<br>    Serial.print(&quot;httpRequestData: &quot;);<br>    Serial.println(httpRequestData);<br>    <br>    // You can comment the httpRequestData variable above<br>    // then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)<br>    //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;;<br><br>    // Send HTTP POST request<br>    int httpResponseCode = https.POST(httpRequestData);<br>     <br>    // If you need an HTTP request with a content type: text/plain<br>    //https.addHeader(&quot;Content-Type&quot;, &quot;text/plain&quot;);<br>    //int httpResponseCode = https.POST(&quot;Hello, World!&quot;);<br>    <br>    // If you need an HTTP request with a content type: application/json, use the following:<br>    //https.addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>    //int httpResponseCode = https.POST(&quot;{\&quot;value1\&quot;:\&quot;19\&quot;,\&quot;value2\&quot;:\&quot;67\&quot;,\&quot;value3\&quot;:\&quot;78\&quot;}&quot;);<br>    <br>    if (httpResponseCode&gt;0) {<br>      Serial.print(&quot;HTTP Response code: &quot;);<br>      Serial.println(httpResponseCode);<br>    }<br>    else {<br>      Serial.print(&quot;Error code: &quot;);<br>      Serial.println(httpResponseCode);<br>    }<br>    // Free resources<br>    https.end();<br>  }<br>  else {<br>    Serial.println(&quot;WiFi Disconnected&quot;);<br>  }<br>  //Send an HTTP POST request every 30 seconds<br>  delay(30000);  <br>}</pre><p>Klik <em>upload</em> dan akan tampak tampilan sebagai berikut pada serial monitor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SpEHMCVMg0dsF0zAoaFuRg.jpeg" /></figure><p>Setelah berhasil upload kode diatas, akses kembali <a href="https://medium.com/yourdomain.000webhost.com/esp-chart.php">yourdomain.000webhost.com/esp-data.php</a> dan akan muncul tampilan hasil pembacaan ESP32 pada <em>website</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WEZLBYf0fx0M6eSKFBi0Pg.jpeg" /></figure><p>Gakalah keren dari project sebelumnya kan??? Nahh kita sekarang sudah berada di penghujung project kali ini. Jika kita review, sebenarnya project ini serupa dengan <em>project </em>sebelumnya. Cuman yang menjadi pembeda adalah pada <em>file </em>esp-weather-station.php. Pada file tersebut, program akan mengakses data yang tersimpan di tabel SQL dan menampilkannya dalam bentuk visual seperti di atas dengan memanfaatkan file CSS untuk membuat visual menjadi menarik dan akan terus terupdate untuk nilai datanya jika kita mengklik update.</p><p>Oke mungkin sekian untuk project kali ini tentang database, semoga bermanfaat dan sampai jumpa di project-project berikutnya. Terima kasih!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=331bb52509e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Project 9 : Database]]></title>
            <link>https://medium.com/@18221111/project-9-database-2ad908980294?source=rss-e4f8a3e3090b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ad908980294</guid>
            <dc:creator><![CDATA[Pramaditya Fajri Migfar]]></dc:creator>
            <pubDate>Sun, 07 May 2023 14:54:10 GMT</pubDate>
            <atom:updated>2023-05-07T15:26:51.985Z</atom:updated>
            <content:encoded><![CDATA[<h3>Project 9 : Database</h3><p>Hallo kembali lagi di medium saya Pramaditya Fajri Migfar dari ITB dengan NIM 18221111. Hari ini saya kembali lagi untuk mengerjakan project embedded tentang database. Meskipun ini hanyalah project bonus, bukan wajib seperti project sebelumnya, tetap saja project kali ini tidak kalah menarik dari project-project sebelumnya. Langsung saja kita masuk ke alat dan bahan yang diperlukan untuk project kali ini.</p><h3><strong>Alat dan Bahan.</strong></h3><ol><li>ESP32</li><li>Kabel Micro USB</li><li>Laptop</li><li>Breadboard</li><li>BMP180</li><li>Kabel Jumper</li></ol><h3><strong>Proses.</strong></h3><p>Langkah pertama yang diperlukan untuk project ini adalah menentukan <em>domain</em> dan <em>hosting server,</em> setelah bertanya ke teman-teman saya ternyata banyak dari mereka menggunakan <a href="https://www.000webhost.com/">https://www.000webhost.com/</a> karena itu langsung saja kita buka website tersebut danmelakukan <em>sign up</em> dan memberi nama pada <em>project website </em>yang akan dibuat. Kemudian, buat <em>database </em>baru pada menu <strong>Create New Database</strong>. Lalu, isi nama, <em>username database</em>, dan <em>password.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qV2hkTQ_sC2MNonnCgV_Fg.jpeg" /></figure><p>Kemudian, klik <strong>Manage -&gt; PhpMyAdmin -&gt; SQL </strong>setelah itu masukkan query berikut.</p><pre>CREATE TABLE SensorData (<br>    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,<br>    sensor VARCHAR(30) NOT NULL,<br>    location VARCHAR(30) NOT NULL,<br>    value1 VARCHAR(10),<br>    value2 VARCHAR(10),<br>    value3 VARCHAR(10),<br>    reading_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NKRUpnL1ND1gLnzMPxFkfw.jpeg" /></figure><p>Lalu, akan muncul tampilan tabel SensorData yang telah dibuat. Kemudian selanjutnya adalah menciptakan <em>script </em>PHP yang akan menerima permintaan dari ESP32 dan memasukkan data-data hasil pembacaan ke dalam MySQL Database. <em>Script</em>-nya adalah sebagai berikut.</p><pre>&lt;?php<br><br>/*<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/<br>  <br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br>  <br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br>*/<br><br>$servername = &quot;localhost&quot;;<br><br>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASE_NAME&quot;;<br>// REPLACE with Database user<br>$username = &quot;REPLACE_WITH_YOUR_USERNAME&quot;;<br>// REPLACE with Database user password<br>$password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;<br><br>// Keep this API Key value to be compatible with the ESP32 code provided in the project page. <br>// If you change this value, the ESP32 sketch needs to match<br>$api_key_value = &quot;tPmAT5Ab3j7F9&quot;;<br><br>$api_key= $sensor = $location = $value1 = $value2 = $value3 = &quot;&quot;;<br><br>if ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {<br>    $api_key = test_input($_POST[&quot;api_key&quot;]);<br>    if($api_key == $api_key_value) {<br>        $sensor = test_input($_POST[&quot;sensor&quot;]);<br>        $location = test_input($_POST[&quot;location&quot;]);<br>        $value1 = test_input($_POST[&quot;value1&quot;]);<br>        $value2 = test_input($_POST[&quot;value2&quot;]);<br>        $value3 = test_input($_POST[&quot;value3&quot;]);<br>        <br>        // Create connection<br>        $conn = new mysqli($servername, $username, $password, $dbname);<br>        // Check connection<br>        if ($conn-&gt;connect_error) {<br>            die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>        } <br>        <br>        $sql = &quot;INSERT INTO SensorData (sensor, location, value1, value2, value3)<br>        VALUES (&#39;&quot; . $sensor . &quot;&#39;, &#39;&quot; . $location . &quot;&#39;, &#39;&quot; . $value1 . &quot;&#39;, &#39;&quot; . $value2 . &quot;&#39;, &#39;&quot; . $value3 . &quot;&#39;)&quot;;<br>        <br>        if ($conn-&gt;query($sql) === TRUE) {<br>            echo &quot;New record created successfully&quot;;<br>        } <br>        else {<br>            echo &quot;Error: &quot; . $sql . &quot;&lt;br&gt;&quot; . $conn-&gt;error;<br>        }<br>    <br>        $conn-&gt;close();<br>    }<br>    else {<br>        echo &quot;Wrong API Key provided.&quot;;<br>    }<br><br>}<br>else {<br>    echo &quot;No data posted with HTTP POST.&quot;;<br>}<br><br>function test_input($data) {<br>    $data = trim($data);<br>    $data = stripslashes($data);<br>    $data = htmlspecialchars($data);<br>    return $data;<br>}</pre><p>Untuk <em>script</em> di atas, saya menyalin kode yang telah disediakan oleh randomnerdstutorial dan menyimpannya dengan format post-esp-data.php yang kemudian diupload pada <em>folder </em>public_html. Lalu, saya menciptakan <em>script</em> PHP untuk menampilkan semua konten yang ada di dalam <em>database</em> ke <em>website </em>dengan <em>script</em> sebagai berikut.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;&lt;body&gt;<br>&lt;?php<br>/*<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/<br>  <br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br>  <br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br>*/<br><br>$servername = &quot;localhost&quot;;<br><br>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASE_NAME&quot;;<br>// REPLACE with Database user<br>$username = &quot;REPLACE_WITH_YOUR_USERNAME&quot;;<br>// REPLACE with Database user password<br>$password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;<br><br>// Create connection<br>$conn = new mysqli($servername, $username, $password, $dbname);<br>// Check connection<br>if ($conn-&gt;connect_error) {<br>    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>} <br><br>$sql = &quot;SELECT id, sensor, location, value1, value2, value3, reading_time FROM SensorData ORDER BY id DESC&quot;;<br><br>echo &#39;&lt;table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot;&gt;<br>      &lt;tr&gt; <br>        &lt;td&gt;ID&lt;/td&gt; <br>        &lt;td&gt;Sensor&lt;/td&gt; <br>        &lt;td&gt;Location&lt;/td&gt; <br>        &lt;td&gt;Value 1&lt;/td&gt; <br>        &lt;td&gt;Value 2&lt;/td&gt;<br>        &lt;td&gt;Value 3&lt;/td&gt; <br>        &lt;td&gt;Timestamp&lt;/td&gt; <br>      &lt;/tr&gt;&#39;;<br> <br>if ($result = $conn-&gt;query($sql)) {<br>    while ($row = $result-&gt;fetch_assoc()) {<br>        $row_id = $row[&quot;id&quot;];<br>        $row_sensor = $row[&quot;sensor&quot;];<br>        $row_location = $row[&quot;location&quot;];<br>        $row_value1 = $row[&quot;value1&quot;];<br>        $row_value2 = $row[&quot;value2&quot;]; <br>        $row_value3 = $row[&quot;value3&quot;]; <br>        $row_reading_time = $row[&quot;reading_time&quot;];<br>        // Uncomment to set timezone to - 1 hour (you can change 1 to any number)<br>        //$row_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$row_reading_time - 1 hours&quot;));<br>      <br>        // Uncomment to set timezone to + 4 hours (you can change 4 to any number)<br>        //$row_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$row_reading_time + 4 hours&quot;));<br>      <br>        echo &#39;&lt;tr&gt; <br>                &lt;td&gt;&#39; . $row_id . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_sensor . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_location . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_value1 . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_value2 . &#39;&lt;/td&gt;<br>                &lt;td&gt;&#39; . $row_value3 . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_reading_time . &#39;&lt;/td&gt; <br>              &lt;/tr&gt;&#39;;<br>    }<br>    $result-&gt;free();<br>}<br><br>$conn-&gt;close();<br>?&gt; <br>&lt;/table&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Sama seperti sebelumnya, saya menyalin kode yang telah disediakan oleh randomnerdstutorial dan menyimpannya dengan format esp_data.php yang kemudian diupload pada <em>folder </em>public_html. Sehingga akan terlihat sebagai berikut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X_1FmKVhx9TBckY5Nxs8rg.jpeg" /></figure><p>Kemudian, tampilan scriptpost-data.php dapat dicek dengan mengakses website yourdomain.000webhost.com/esp-data.php dan akan muncul tampilan sebagai berikut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4p8AVZfCWojYf10Kv1aLA.jpeg" /></figure><p>Nah, kita berhasil melakukan setup pada website. Berikutnya, langsung saja kita ambil ESP32 kita untuk melakukan pembacaan temperatur, ketinggian, dan tekanan yang akan ditampilkan pada <em>website. </em>Untuk rangkaiannya adalah sebagai berikut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxdyzt28Hv2MHjack5ws-A.jpeg" /></figure><p>Berikutnya, kita bisa mulaimenyusun kode program pada Arduino IDE. Untuk kodenya, diambil dari kode pada project empat namun ditambah dengan modifikasi agar bisa mengunggah pembacaan data ke <em>database </em>yang telah kita buat.</p><pre>/*<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/<br>  <br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br>  <br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br>*/<br>#ifdef ESP32<br>  #include &lt;WiFi.h&gt;<br>  #include &lt;HTTPClient.h&gt;<br>#else<br>  #include &lt;ESP8266WiFi.h&gt;<br>  #include &lt;ESP8266HTTPClient.h&gt;<br>  #include &lt;WiFiClient.h&gt;<br>#endif<br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_BMP085.h&gt;<br>// Replace with your network credentials<br>const char* ssid     = &quot;REPLACE-WITH-YOUR-SSID&quot;;<br>const char* password = &quot;REPLACE-WITH-YOUR-PASSWORD&quot;;<br>// REPLACE with your Domain name and URL path or IP address with path<br>const char* serverName = &quot;http://chintyaw.000webhostapp.com/post-esp-data.php&quot;;<br>// Keep this API Key value to be compatible with the PHP code provided in the project page. <br>// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key <br>String apiKeyValue = &quot;tPmAT5Ab3j7F9&quot;;<br>String sensorName = &quot;BMP180&quot;;<br>String sensorLocation = &quot;Kos&quot;;<br>#define SEALEVELPRESSURE_HPA (1013.25)<br>Adafruit_BMP085 bmp;  // I2C<br>void setup() {<br>  Serial.begin(115200);<br>  <br>  WiFi.begin(ssid, password);<br>  Serial.println(&quot;Connecting&quot;);<br>  while(WiFi.status() != WL_CONNECTED) { <br>    delay(500);<br>    Serial.print(&quot;.&quot;);<br>  }<br>  Serial.println(&quot;&quot;);<br>  Serial.print(&quot;Connected to WiFi network with IP Address: &quot;);<br>  Serial.println(WiFi.localIP());<br>// (you can also pass in a Wire library object like &amp;Wire2)<br>  bool status = bmp.begin(0x76);<br>  if (!status) {<br>    Serial.println(&quot;Could not find a valid BMP180 sensor, check wiring or change I2C address!&quot;);<br>    while (1);<br>  }<br>}<br>void loop() {<br>  //Check WiFi connection status<br>  if(WiFi.status()== WL_CONNECTED){<br>    HTTPClient http;<br>    <br>    // Your Domain name with URL path or IP address with path<br>    http.begin(serverName);<br>    <br>    // Specify content-type header<br>    http.addHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);<br>    <br>    // Prepare your HTTP POST request data<br>    String httpRequestData = &quot;api_key=&quot; + apiKeyValue + &quot;&amp;sensor=&quot; + sensorName<br>                          + &quot;&amp;location=&quot; + sensorLocation + &quot;&amp;value1=&quot; + String(bmp.readTemperature())<br>                          + &quot;&amp;value2=&quot; + String(bmp.readAltitude()) + &quot;&amp;value3=&quot; + String(bmp.readPressure()/100.0F) + &quot;&quot;;<br>    Serial.print(&quot;httpRequestData: &quot;);<br>    Serial.println(httpRequestData);<br>    <br>    // You can comment the httpRequestData variable above<br>    // then, use the httpRequestData variable below (for testing purposes without the BMP180 sensor)<br>    //String httpRequestData = &quot;api_key=tPmAT5Ab3j7F9&amp;sensor=BMP180&amp;location=Home&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14&quot;;<br>// Send HTTP POST request<br>    int httpResponseCode = http.POST(httpRequestData);<br>     <br>    // If you need an HTTP request with a content type: text/plain<br>    //http.addHeader(&quot;Content-Type&quot;, &quot;text/plain&quot;);<br>    //int httpResponseCode = http.POST(&quot;Hello, World!&quot;);<br>    <br>    // If you need an HTTP request with a content type: application/json, use the following:<br>    //http.addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>    //int httpResponseCode = http.POST(&quot;{\&quot;value1\&quot;:\&quot;19\&quot;,\&quot;value2\&quot;:\&quot;67\&quot;,\&quot;value3\&quot;:\&quot;78\&quot;}&quot;);<br>        <br>    if (httpResponseCode&gt;0) {<br>      Serial.print(&quot;HTTP Response code: &quot;);<br>      Serial.println(httpResponseCode);<br>    }<br>    else {<br>      Serial.print(&quot;Error code: &quot;);<br>      Serial.println(httpResponseCode);<br>    }<br>    // Free resources<br>    http.end();<br>  }<br>  else {<br>    Serial.println(&quot;WiFi Disconnected&quot;);<br>  }<br>  //Send an HTTP POST request every 30 seconds<br>  delay(5000);  <br>}</pre><p>Klik <em>upload</em> dan akan tampak tampilan sebagai berikut pada serial monitor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qrA9cvD7S7l25mTLHdWJ5A.jpeg" /></figure><p>Setelah berhasil upload kode diatas, akses kembali yourdomain.000webhost.com/esp-data.php dan akan muncul tampilan hasil pembacaan ESP32 pada <em>website</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdLNC3MsCZaXCxa0t2fF0g.jpeg" /></figure><p>Nahhh keren bukan??? Jadi di <em>project </em>ini, kita telah berhasil membaca data kondisi sekitar dan ditampilkan pada website, tetapi perbedaan pada project sebelumnya adalah kita memanfaatkan PHP, yakni post-esp-data.php yang digunakan untuk mengecek data dari server dan kemudian akan disimpan dalam database SQL yang sudah dibuat sebelumnya dan berikutnya adalah esp-data.php yang membaca data yang sebelumnya telah disimpan dalam database dan menampilkannya dalam bentuk website.</p><p>Oke mungkin sekian untuk project kali ini tentang database, semoga bermanfaat dan sampai jumpa di project-project berikutnya. Terima kasih!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ad908980294" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>