Anda di halaman 1dari 7

KOMUNIKASI DATA DAN TELEMETRI

Akademi Metrologi dan Instrumentasi

Nomor Modul 5
Tanggal 23 Desember 2020
Nama
NIM

Tata tertib peserta praktikum:

1. Seluruh peserta praktikum wajib mengerjakan tugas pendahuluan.


2. Pengerjaan tugas pendahuluan diberikan waktu maksimal 15 menit.
3. Seluruh peserta praktikum wajib memerhatikan materi yang diberikan.
4. Jika peserta kurang memahami materi, peserta diperbolehkan meminta keterangan lebih lanjut
kepada asisten.
5. Seluruh peserta praktikum wajib membuat tugas akhir setelah dilakukannya praktikum jarak
jauh.
6. Peserta mendapatkan bobot penilaian 80% untuk laporan praktikum dan 20% untuk tugas
pendahuluan

Tujuan praktikum:

1. Memahami konsep Internet of Things


2. Melakukan komunikasi menggunakan ESP32 yang tersambung pada web
3. Memahami pentingnya IoT pada era sekarang

1. Internet Of Things (IoT)

Internet of Things (IoT) didefinisikan sebagai infrastruktur jaringan global yang dinamis
dengan kemampuan self-configuration berdasarkan standar dan protokol komunikasi yang dapat
dioperasikan. Benda fisik dan virtual dalam IoT memiliki identitas dan atribut serta mampu
menggunakan antarmuka cerdas dan diintegrasikan sebagai jaringan informasi.

Dalam lingkungan IoT, sebuah pintu akan memiliki kemampuan untuk terhubung dengan
alarm kebakaran, atau kursi Anda akan berkomunikasi dengan lampu rumah Anda atau mobil
akan berkomunikasi dengan tempat parkir; daftarnya bisa semakin panjang, dan hanya dibatasi
oleh imajinasi Anda.

Sistem IoT terdiri dari hardware dan software. Komponen hardware termasuk sistem
tertanam, sensor dan SBC. IoT mencakup pemanfaatan sensor dan perangkat keras komunikasi
jarak dekat seperti RFID atau NFC, bersama dengan perangkat komputasi tertanam. Komponen
perangkat lunak IoT dibentuk oleh beberapa lapisan yang berbeda.

Software IoT terdiri dari beberapa lapisan. Lapisan paling rendah adalah sistem operasi
hardware. Lapisan selanjutnya adalah middleware and framework yang menjadi inti dari
software. Lapisan ini bertindak sebagai jembatan antar perangkat untuk mengaktifkan
komunikasi M2M, untuk memfasilitasi penyediaan informasi yang diperoleh dari lingkungan
sekitar kepada pengguna atau ke portal integrasi.

2. ESP32

ESP32 dibuat oleh Espressif Systems, ESP32 adalah sistem dengan biaya yang rendah,


berdaya rendah pada seri chip (SoC) dengan Wi-Fi & kemampuan Bluetooth dua mode!
Keluarga ESP32 termasuk chip ESP32-D0WDQ6 (dan ESP32-D0WD), ESP32-D2WD, ESP32-
S0WD, dan sistem dalam paket (SiP) ESP32-PICO-D4. Pada intinya, ada mikroprosesor
Tensilica Xtensa LX6 dual-core atau single-core dengan clock rate hingga 240 MHz. ESP32
sudah terintegrasi dengan built-in antenna switches, RF balun, power amplifier, low-noise
receive amplifier, filters, and power management modules. Didesain untuk perangkat seluler,
perangkat elektronik yang dapat dipakai, dan aplikasi IoT, ESP32 juga bekerja dengan konsumsi
daya sangat rendah melalui fitur hemat daya termasuk fine resolution clock gating, multiple
power modes, and dynamic power scaling.

Module ESP32 merupakan penerus dari module ESP8266 yang cukup populer untuk Aplikasi
IoT. Pada ESP32 terdapat inti CPU serta Wi-Fi yang lebih cepat, GPIO yang lebih, dan
mendukung Bluetooth Low Energy. Berikut ini adalah Arsitektur dan Block Diagram dari
ESP32 :

Fitur dan Spesifikasi ESP32:

1. Processors: 
    > Main processor: Tensilica Xtensa 32-bit LX6 microprocessor
       > Cores: 2 or 1 (depending on variation)
       > Clock frequency: up to 240 MHz
       > Performance: up to 600 DMIPS
    > Ultra low power co-processor: allows you to do ADC conversions, computation, and level
thresholds while in deep sleep.
2. Wireless connectivity:
    > Wi-Fi: 802.11 b/g/n/e/i (802.11n @ 2.4 GHz up to 150 Mbit/s)
    > Bluetooth: v4.2 BR/EDR and Bluetooth Low Energy (BLE)

3. Memory:
    > Internal memory:
       > ROM: 448 KiB
       > SRAM: 520 KiB
       > RTC fast SRAM: 8 KiB
       > RTC slow SRAM: 8 KiB
       > eFuse: 1 Kibit
       > Embedded flash:
           > 0 MiB (ESP32-D0WDQ6, ESP32-D0WD, and ESP32-S0WD chips)
           > 2 MiB (ESP32-D2WD chip)
           > 4 MiB (ESP32-PICO-D4 SiP module)
        > External flash & SRAM: ESP32 supports up to four 16 MiB external QSPI flashes and
SRAMs with hardware encryption based on AES to protect developers' programs and
data. ESP32 can access the external QSPI flash and SRAM through high-speed caches.
            > Up to 16 MiB of external flash are memory-mapped onto the CPU code space,
supporting 8-bit, 16-bit and 32-bit access. Code execution is supported.
            > Up to 8 MiB of external flash/SRAM memory are mapped onto the CPU data space,
supporting 8-bit, 16-bit and 32-bit access. Data-read is supported on the flash and
SRAM. Data-write is supported on the SRAM.

4. Peripheral input/output: Rich peripheral interface with DMA that includes capacitive touch,


ADCs (analog-to-digital converter), DACs (digital-to-analog converter), I²C (Inter-Integrated
Circuit), UART (universal asynchronous receiver/transmitter),  CAN 2.0 (Controller Area
Network), SPI (Serial Peripheral Interface), I²S (Integrated Inter-IC Sound), RMII (Reduced
Media-Independent Interface), PWM (pulse width modulation), and more.
    
5. Security:
    > IEEE 802.11 standard security features all supported, including WFA,  WPA/WPA2 and
WAPI
    > Secure boot
    > Flash encryption
    > 1024-bit OTP, up to 768-bit for customers
    > Cryptographic hardware acceleration: AES, SHA-2, RSA, elliptic curve cryptography
(ECC), random number generator (RNG).

Gambar 1. ESP32 dev kit v1

3. Persiapan Alat dan Bahan


 Personal Computer (PC)
 ESP32
 Internet
 Jumper
 Breadboard
 Resistor 220 ohm
 2 buah LED
 Potensiometer

4. Membuat Komunikasi ESP32 yang ditampilkan dengan Web

4.1. Langkah Persiapan


1) Siapkan PC
2) Siapkan 2 buah LED, 2 buah resistor 220 ohm dan jumper. Buatlah rangkaian
seperti gambar berikut:

Tabel 1. Keterangan pin komponen


Komponen Pin
Potensiometer 32
LED 1 26
LED 2 27

3) Buka Arduino IDE yang sebelumnya telah diatur board “Esp32” pada bagian
tools. Masukan kode sebagai berikut:

// Load Wi-Fi library


#include <WiFi.h>

// Replace with your network credentials


const char* ssid = "bam";
const char* password = "12345678";

// Set web server port number to 80


WiFiServer server(80);

// Variable to store the HTTP request


String header;

// Auxiliar variables to store the current output state


String output26State = "off";
String output27State = "off";

// Assign output variables to GPIO pins


const int output26 = 26;
const int output27 = 27;
const int potensio = 32;
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
int nilaipot;
void setup() {
Serial.begin(115200);
// Initialize the output variables as outputs
pinMode(output26, OUTPUT);
pinMode(output27, OUTPUT);
// Set outputs to LOW
digitalWrite(output26, LOW);
digitalWrite(output27, LOW);

// Connect to Wi-Fi network with SSID and password


Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}

void loop(){
WiFiClient client = server.available(); // Listen for incoming clients
nilaipot = analogRead(potensio);
if (client) { // If a new client connects,
currentTime = millis();
previousTime = currentTime;
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
Serial.print("nilai potensio");
Serial.println(nilaipot);
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the
client's connected
currentTime = millis();
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

// turns the GPIOs on and off


if (header.indexOf("GET /26/on") >= 0) {
Serial.println("GPIO 26 on");
output26State = "on";
digitalWrite(output26, HIGH);
} else if (header.indexOf("GET /26/off") >= 0) {
Serial.println("GPIO 26 off");
output26State = "off";
digitalWrite(output26, LOW);
} else if (header.indexOf("GET /27/on") >= 0) {
Serial.println("GPIO 27 on");
output27State = "on";
digitalWrite(output27, HIGH);
} else if (header.indexOf("GET /27/off") >= 0) {
Serial.println("GPIO 27 off");
output27State = "off";
digitalWrite(output27, LOW);
}

// Display the HTML web page


client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-
scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px
auto; text-align: center;}");
client.println(".button { background-color: #4CAF50; border: none; color: white; padding:
16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #555555;}</style></head>");

// Web Page Heading


client.println("<body><h1>ESP32 Web Server</h1>");

// Display current state, and ON/OFF buttons for GPIO 26


client.println("<p>GPIO 26 - State " + output26State + "</p>");
// If the output26State is off, it displays the ON button
if (output26State=="off") {
client.println("<p><a href=\"/26/on\"><button class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/26/off\"><button class=\"button
button2\">OFF</button></a></p>");
}

// Display current state, and ON/OFF buttons for GPIO 27


client.println("<p>GPIO 27 - State " + output27State + "</p>");
// If the output27State is off, it displays the ON button
if (output27State=="off") {
client.println("<p><a href=\"/27/on\"><button class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/27/off\"><button class=\"button
button2\">OFF</button></a></p>");
}
client.print("<p> nilai potensiometer </p>");
client.println(nilaipot);

client.println("</body></html>");

// The HTTP response ends with another blank line


client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}

4) Upload program lalu buka serial monitor


5) Pada serial monitor akan terdapat alamat IP web yang dibuat. Catat alamat IP
lalu buka web browser menggunakan HP/Pc yang terhubung ke jaringan internet
yang sama
6) Terdapat tampilan tombol kendali LED dan nilai potensiometer
7) Lakukan perubahan kondisi LED dari web yang ditampilkan
8) Amati LED
9) Putar potensiometer dan lihat perubahan nilai pada web.

Anda mungkin juga menyukai