1. Pengenalan Edge Computing
Edge Computing adalah paradigma komputasi yang memproses data sedekat mungkin dengan sumber data (di "edge" / tepi jaringan), bukan mengirim semuanya ke cloud yang jauh. Dalam konteks IoT, edge computing berarti memproses data sensor di perangkat lokal (ESP32, Raspberry Pi, gateway) sebelum β atau bahkan tanpa β mengirimnya ke cloud.
Edge computing muncul karena keterbatasan model cloud-only: latency tinggi, bandwidth terbatas, biaya transfer data yang besar, dan kebutuhan akan operasi yang berkelanjutan meski koneksi internet terputus.
Mengapa Edge Computing Penting?
| Alasan | Penjelasan | Contoh |
|---|---|---|
| Low Latency | Respons real-time tanpa round-trip ke cloud | Autonomous vehicle, robot industri |
| Bandwidth Savings | Filter dan kompres data sebelum kirim ke cloud | Video surveillance, sensor array |
| Offline Operation | Tetap berfungsi tanpa internet | Pertambangan, kapal laut, drone |
| Privacy | Data sensitif diproses lokal, tidak ke cloud | Kesehatan, keamanan wajah |
| Cost Reduction | Kurangi biaya transfer data dan compute cloud | High-frequency sensor data |
| Reliability | Sistem tetap jalan meski jaringan down | Sistem keselamatan, alarm kebakaran |
2. Edge vs Cloud Computing
Memahami perbedaan mendasar antara edge dan cloud computing membantu Anda menentukan kapan harus memproses data di mana.
Perbandingan Komprehensif
| Aspek | Edge Computing | Cloud Computing |
|---|---|---|
| Lokasi | Di dekat device / lokal | Data center jauh |
| Latency | π’ < 10ms | π΄ 50-200ms+ |
| Bandwidth | π’ Minim (data sudah difilter) | π΄ Tinggi (raw data) |
| Compute Power | π‘ Terbatas (ARM, RISC) | π’ Tak terbatas (GPU/TPU) |
| Storage | π‘ Terbatas (GB) | π’ Tak terbatas (TB/PB) |
| Skalabilitas | π΄ Terbatas per device | π’ Elastis, auto-scaling |
| Biaya | π’ Fixed (hardware sekali beli) | π‘ Variable (pay-per-use) |
| Offline | β Tetap berfungsi | β Tidak bisa |
| Keamanan Data | β Data tetap lokal | π‘ Data di jaringan & cloud |
| Update/Deploy | π΄ Perlu ke device (OTA) | π’ Centralized, mudah |
| Analytics Kompleks | π΄ Terbatas | π’ Big data, ML heavy |
Kapan Harus di Edge vs Cloud?
- Proses di EDGE jika: latency < 100ms diperlukan, bandwidth terbatas, harus offline-capable, data sensitif/privacy
- Proses di CLOUD jika: butuh compute besar (ML training), analytics lintas device, storage besar, akses dari mana saja
- Gunakan HYBRID jika: real-time processing di edge + historical analytics di cloud. Ini skenario terbaik untuk mayoritas IoT.
3. Latency dan Responsiveness
Latency adalah waktu yang diperlukan data untuk berpindah dari titik A ke titik B. Dalam IoT, latency menentukan seberapa cepat sistem merespons perubahan di dunia nyata. Edge computing mengurangi latency secara drastis dengan memproses data secara lokal.
Anatomi Latency
Bandwidth Optimization
| Strategi | Deskripsi | Penghematan Bandwidth |
|---|---|---|
| Data Filtering | Kirim hanya data yang berubah signifikan | 50-90% |
| Aggregation | Kirim rata-rata per menit, bukan per detik | 80-99% |
| Edge Analytics | Kirim insight, bukan raw data | 90-99% |
| Compression | Kompres data sebelum kirim | 30-70% |
| Event-based | Kirim hanya saat threshold terlampaui | 95-99% |
5. Arsitektur Edge Computing
Arsitektur edge computing yang baik mendefinisikan dengan jelas apa yang diproses di mana, bagaimana data mengalir, dan bagaimana edge dan cloud berkoordinasi.
Pola Arsitektur Edge
| Pola | Deskripsi | Cocok Untuk |
|---|---|---|
| Thin Edge | Device hanya kumpulkan data, semua proses di gateway/cloud | Sensor sederhana |
| Thick Edge | Device melakukan ML inference dan filtering sendiri | Smart camera, voice assistant |
| Store-and-Forward | Data disimpan lokal, dikirim ke cloud saat ada koneksi | Remote monitoring, offline areas |
| Edge-First | Keputusan real-time di edge, analytics di cloud | Industrial automation |
| Collaborative | Multi-device edge berkolaborasi, cloud sebagai koordinator | Smart city, autonomous fleet |
TinyML di ESP32
#include <TensorFlowLite_ESP32.h>
#include "tensorflow/lite/micro/all_ops_resolver.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/schema/schema_generated.h"
// Model yang sudah di-train dan di-convert ke TFLite Micro
#include "model_data.h" // Hasil export dari TensorFlow
// Arena memory untuk TFLite
constexpr int kTensorArenaSize = 32 * 1024; // 32KB
uint8_t tensor_arena[kTensorArenaSize];
const tflite::Model* model;
tflite::MicroInterpreter* interpreter;
TfLiteTensor* input;
TfLiteTensor* output;
void setup() {
Serial.begin(115200);
// Load model
model = tflite::GetModel(model_data);
static tflite::AllOpsResolver resolver;
static tflite::MicroInterpreter static_interpreter(
model, resolver, tensor_arena, kTensorArenaSize
);
interpreter = &static_interpreter;
// Allocate tensors
interpreter->AllocateTensors();
// Get input/output tensors
input = interpreter->input(0);
output = interpreter->output(0);
Serial.println("TinyML model loaded!");
Serial.printf("Input size: %d\n", input->bytes);
Serial.printf("Arena used: %d bytes\n", interpreter->arena_used_bytes());
}
void loop() {
// Baca sensor (contoh: 3-axis accelerometer)
float ax = readAccelX(); // -1.0 to 1.0
float ay = readAccelY();
float az = readAccelZ();
// Normalisasi dan isi input tensor
input->data.f[0] = ax;
input->data.f[1] = ay;
input->data.f[2] = az;
// Jalankan inference
unsigned long start = micros();
interpreter->Invoke();
unsigned long elapsed = micros() - start;
// Baca hasil
// Misal: 0=diam, 1=jalan, 2=lari, 3=jatuh
int predicted_class = -1;
float max_score = -1;
for (int i = 0; i < output->bytes / sizeof(float); i++) {
if (output->data.f[i] > max_score) {
max_score = output->data.f[i];
predicted_class = i;
}
}
const char* labels[] = {"Diam", "Jalan", "Lari", "Jatuh"};
Serial.printf("Activity: %s (%.2f) - Inference: %lu us\n",
labels[predicted_class], max_score, elapsed);
// Edge action: trigger alarm jika "Jatuh"
if (predicted_class == 3 && max_score > 0.8) {
Serial.println("β οΈ FALL DETECTED! Sending alert...");
// Kirim alert ke cloud (bukan raw sensor data!)
mqtt_publish("alert/fall", "sensor_001");
}
delay(100); // 10 Hz inference rate
}
8. Edge Gateway
Edge Gateway adalah perangkat yang menghubungkan jaringan sensor lokal dengan cloud. Gateway bertindak sebagai translator, aggregator, dan filter antara device resource-constrained dan cloud.
Fungsi Edge Gateway
| Fungsi | Penjelasan |
|---|---|
| Protocol Translation | Konversi antar protokol: BLEβMQTT, ZigbeeβHTTP, ModbusβMQTT |
| Data Aggregation | Kumpulkan data dari banyak sensor, kirim summary ke cloud |
| Edge Rules | Jalankan aturan lokal untuk respons cepat |
| Local Storage | Buffer data saat offline, sync saat online |
| Security | Firewall antara jaringan lokal dan internet |
| Device Management | OTA update, monitoring, konfigurasi device lokal |
import paho.mqtt.client as mqtt
import json, time, sqlite3
from threading import Thread
class IoTGateway:
def __init__(self):
# Local broker (ke device lokal)
self.local = mqtt.Client("gateway-local")
self.local.connect("localhost", 1883)
# Cloud broker (ke AWS/Azure)
self.cloud = mqtt.Client("gateway-cloud")
self.cloud.tls_set("ca.crt", "client.crt", "client.key")
self.cloud.connect("aws-iot-endpoint", 8883)
# Local database
self.db = sqlite3.connect('gateway.db')
self.db.execute('''CREATE TABLE IF NOT EXISTS buffer
(ts REAL, topic TEXT, data TEXT, sent INT DEFAULT 0)''')
# Rules engine
self.rules = [
{'topic': 'sensor/+/suhu', 'threshold': 35, 'action': 'alarm'},
{'topic': 'sensor/+/suhu', 'threshold': 0, 'below': True, 'action': 'alarm'}
]
def on_local_message(self, client, userdata, msg):
"""Terima data dari device lokal."""
data = json.loads(msg.payload.decode())
# Simpan ke buffer
self.db.execute('INSERT INTO buffer VALUES (?, ?, ?, 0)',
(time.time(), msg.topic, json.dumps(data)))
self.db.commit()
# Evaluasi rules lokal
self.evaluate_rules(msg.topic, data)
# Agregasi dan kirim ke cloud
self.forward_to_cloud(msg.topic, data)
def evaluate_rules(self, topic, data):
"""Evaluasi rules di edge β tanpa cloud dependency!"""
if 'suhu' in data and data['suhu'] > 35:
# Trigger alarm LOKAL (buzzer, LED, relay)
self.local.publish('cmd/alarm', json.dumps({
'device': data.get('device_id'),
'type': 'HIGH_TEMP',
'value': data['suhu']
}))
def forward_to_cloud(self, topic, data):
"""Teruskan data ke cloud (dengan filter)."""
cloud_topic = topic.replace('sensor/', 'devices/')
self.cloud.publish(cloud_topic, json.dumps(data))
def start(self):
self.local.on_message = self.on_local_message
self.local.subscribe("sensor/#")
Thread(target=self.local.loop_forever).start()
Thread(target=self.cloud.loop_forever).start()
# Periodic sync
while True:
self.sync_buffered()
time.sleep(60)
gateway = IoTGateway()
gateway.start()
9. Arsitektur Hybrid Edge-Cloud
Arsitektur hybrid menggabungkan keunggulan edge (low latency, offline) dan cloud (compute besar, global access) dalam satu sistem yang koheren.
Pembagian Kerja Edge vs Cloud
| Tugas | Di Edge | Di Cloud |
|---|---|---|
| Data Collection | β Sensor reading | β (via edge) |
| Preprocessing | β Filter, normalize, validate | β |
| Real-time Rules | β Threshold, interlock | β |
| ML Inference | β Simple models (TFLite) | β Complex models (GPU) |
| ML Training | β (resource terbatas) | β (GPU/TPU cluster) |
| Historical Analytics | β (storage terbatas) | β (data warehouse) |
| Dashboard Global | β (lokal saja) | β (akses dari mana saja) |
| Alert & Notification | β Alarm lokal (buzzer) | β Email, SMS, push |
| OTA Updates | β Terima update | β Push update |
- Cloud-only untuk real-time control β Latency tinggi, single point of failure
- Edge-only untuk analytics β Resource terbatas, tidak scalable
- Tanpa offline handling β Sistem mati saat internet putus
- Sinkronisasi tanpa conflict resolution β Data inconsistency
10. Use Cases
1. Predictive Maintenance di Pabrik
# EDGE: ESP32 dengan accelerometer pada motor industri
# - Baca getaran 1000 Hz (vibration analysis)
# - Jalankan FFT (Fast Fourier Transform) di edge
# - Jalankan anomaly detection model (TFLite)
# - Jika anomaly terdeteksi β alert lokal + kirim ke cloud
#
# CLOUD: AWS/GCP
# - Terima anomaly events (bukan raw vibration data!)
# - Dashboard maintenance untuk seluruh pabrik
# - Train ulang model berdasarkan feedback teknisi
# - Push model baru ke edge device (OTA)
#
# PENGHEMATAN BANDWIDTH:
# Raw data: 1000 samples/sec Γ 4 bytes = 4 KB/s per device
# Dengan 100 devices = 400 KB/s = 34 GB/hari!
# Edge analytics: ~1 event/menit Γ 200 bytes = 12 KB/jam
# Penghematan: 99.97%!
2. Smart Agriculture
# EDGE (per lahan):
# - Raspberry Pi Gateway + multiple ESP32 sensors
# - Soil moisture, temperature, humidity, light, pH
# - Edge rules: if soil_moisture < 30% β activate irrigation
# - Edge rules: if temp > 40 β activate shade/sprinkler
# - Data aggregation: kirim rata-rata per jam ke cloud
#
# CLOUD:
# - Analytics musiman (trend analysis)
# - Rekomendasi tanam berdasarkan historical data
# - Integrasi cuaca (weather API)
# - Dashboard petani via mobile app
#
# MANFAAT:
# - Respons irigasi < 1 detik (edge rules)
# - Tetap berfungsi saat internet mati (offline)
# - Hemat bandwidth (summary per jam)
# - Data historis untuk optimasi jangka panjang
11. Best Practices
| Aspek | Best Practice | Hindari |
|---|---|---|
| Data Flow | Filter dan agregasi di edge, kirim summary ke cloud | Kirim semua raw data ke cloud |
| Offline Handling | Store-and-forward, buffer lokal | Sistem mati tanpa internet |
| Security | Enkripsi data di edge, TLS ke cloud | Data plaintext di jaringan lokal |
| Updates | OTA firmware + model update | Manual flash per device |
| Monitoring | Device health heartbeat ke cloud | Blind spot tanpa monitoring |
| Redundancy | Failover ke cloud jika edge mati | Single point of failure |
| Resource Mgmt | Monitor RAM, CPU, storage di edge | Over-provisioning tanpa monitoring |
12. Quiz: Uji Pemahamanmu!
Setelah membaca tutorial di atas, jawablah 5 pertanyaan berikut untuk menguji pemahamanmu tentang Edge Computing: