n8n ile Endüstriyel IoT Otomasyonu: Sensörden E-postaya Akıllı İş Akışları
Giriş
Endüstriyel IoT projelerinde en zor kısımlardan biri farklı sistemlerin entegrasyonudur: Sensörler, veritabanları, email servisleri, ERP sistemleri, Slack/Teams... Her biri farklı API ve protokoller kullanır.
n8n, bu karmaşıklığı ortadan kaldıran açık kaynak bir workflow automation platformudur. Cloud & IoT Veri Toplama Çözümlerimiz kapsamında, n8n ile tesis otomasyonunu nasıl kolaylaştırabileceğinizi gösteriyoruz.
n8n Nedir?
n8n (nodemation), drag-and-drop arayüzü ile iş akışları (workflows) oluşturmanızı sağlar. Zapier ve Integromat'a benzer, ancak:
- Self-hosted: Kendi sunucunuzda çalışır (veri güvenliği)
- Açık kaynak: Ücretsiz, limitsiz
- Kodlanabilir: Custom JavaScript function nodes
- 350+ entegrasyon: AWS, Google, Slack, MQTT, HTTP, SQL...
Endüstriyel IoT Use Case'leri
1. Tank Doluluk Alarmı
Senaryo: GDT Dijital Transmitter'dan gelen ağırlık verisi %95'i aştığında email + Slack bildirimi.
n8n Workflow:
[MQTT Trigger] → [Filter] → [Branch]
├─→ [Send Email]
└─→ [Slack Message]
2. Günlük Üretim Raporu
Senaryo: Her gece saat 00:00'da ZMA cihazlarından günün toplam üretim verisini al, Excel'e çevir, email gönder.
n8n Workflow:
[Cron Trigger: 0 0 * * *] → [MySQL Query] → [Spreadsheet File] → [Email Attachment]
3. ERP Entegrasyonu
Senaryo: Tartım tamamlandığında (GDT tare eventi), SAP ERP'ye otomatik stok kaydı.
n8n Workflow:
[Webhook: /weighing-complete] → [HTTP Request: SAP API] → [If Error] → [Slack Alert]
n8n Kurulumu
Docker ile Kurulum (Önerilen)
# docker-compose.yml
version: '3'
services:
n8n:
image: n8nio/n8n:latest
ports:
- '5678:5678'
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=strongpassword
- N8N_HOST=n8n.fabrika.local
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.fabrika.local
volumes:
- n8n-data:/home/node/.n8n
restart: unless-stopped
volumes:
n8n-data:
docker-compose up -d
Web arayüzü: http://localhost:5678
Manuel Kurulum (Ubuntu)
# Node.js yükle
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
# n8n global yükle
sudo npm install -g n8n
# Başlat
n8n start
# Servis olarak çalıştır
sudo npm install -g pm2
pm2 start n8n
pm2 save
pm2 startup
Örnek Workflow #1: MQTT Tank Monitoring
Senaryo Detayı
3 tank var, her birinden AWS IoT Core'a MQTT ile veri geliyor:
- Topic:
amazeng/factory/tank1/weight - Payload:
{"weight_kg": 4520, "timestamp": 1672531200000}
Hedef: Ağırlık 5000kg'ı aştığında:
- Email gönder (bakı[email protected])
- Slack #alarms kanalına mesaj
- MySQL'e alarm kaydı
n8n Workflow Yapısı
1. MQTT Trigger Node
{
"protocol": "mqtt",
"host": "xxxxx.iot.eu-west-1.amazonaws.com",
"port": 8883,
"topic": "amazeng/factory/+/weight",
"tls": true,
"certPath": "/certs/gateway-cert.pem",
"keyPath": "/certs/gateway-private.key"
}
2. Function Node (Veri Parse)
// MQTT payload parse et
const payload = JSON.parse($input.item.json.payload)
const tankName = $input.item.json.topic.split('/')[2] // "tank1"
return {
json: {
tank: tankName,
weight: payload.weight_kg,
timestamp: new Date(payload.timestamp),
},
}
3. IF Node (Threshold Check)
{
"conditions": {
"number": [
{
"value1": "={{$json.weight}}",
"operation": "larger",
"value2": 5000
}
]
}
}
4a. Send Email Node
{
"fromEmail": "[email protected]",
"toEmail": "[email protected]",
"subject": "⚠️ Tank Kapasıte Alarmı: {{$json.tank}}",
"text": "Tank {{$json.tank}} ağırlığı {{$json.weight}} kg'a ulaştı!\n\nAcil boşaltma gerekebilir.",
"html": "<h2>Tank Alarmı</h2><p><strong>Tank:</strong> {{$json.tank}}</p><p><strong>Ağırlık:</strong> {{$json.weight}} kg</p>"
}
4b. Slack Node
{
"channel": "#alarms",
"text": ":warning: *Tank Alarm* :warning:\n\n*Tank:* {{$json.tank}}\n*Ağırlık:* {{$json.weight}} kg\n*Zaman:* {{$json.timestamp}}"
}
4c. MySQL Node (Insert)
INSERT INTO alarms (tank_name, weight_kg, alarm_type, timestamp)
VALUES ('{{$json.tank}}', {{$json.weight}}, 'capacity_exceeded', '{{$json.timestamp}}')
Test ve Debugging
n8n'de Execute Workflow butonuna basın. MQTT mesajı geldiğinde tüm node'lar çalışır ve sonuçları gösterir.
Test MQTT Mesajı Gönderme:
mosquitto_pub -h xxxxx.iot.eu-west-1.amazonaws.com \
-p 8883 \
--cafile AmazonRootCA1.pem \
--cert gateway-cert.pem \
--key gateway-private.key \
-t "amazeng/factory/tank1/weight" \
-m '{"weight_kg": 5200, "timestamp": 1735488000000}'
Örnek Workflow #2: Günlük Rapor Otomasyonu
Senaryo
Her gece saat 23:00'da:
- MySQL'den günün tüm tartım kayıtlarını çek
- Excel dosyası oluştur
- Email ekinde gönder
n8n Workflow
1. Cron Trigger
{
"triggerTimes": {
"hour": 23,
"minute": 0
}
}
2. MySQL Query
SELECT
tank_name,
COUNT(*) as total_weighings,
SUM(weight_kg) as total_weight,
AVG(weight_kg) as avg_weight,
MAX(weight_kg) as max_weight
FROM weighings
WHERE DATE(timestamp) = CURDATE()
GROUP BY tank_name
3. Spreadsheet File Node
{
"operation": "toFile",
"fileFormat": "xlsx",
"fileName": "Günlük_Rapor_{{$now.format('YYYY-MM-DD')}}.xlsx",
"sheetName": "Tartım Verileri"
}
4. Email Attachment
{
"fromEmail": "[email protected]",
"toEmail": "[email protected]",
"subject": "Günlük Üretim Raporu - {{$now.format('DD.MM.YYYY')}}",
"attachments": "binary,Günlük_Rapor_{{$now.format('YYYY-MM-DD')}}.xlsx",
"text": "Ekteki Excel dosyasında bugünün tüm tartım verileri bulunmaktadır."
}
Örnek Workflow #3: SAP ERP Entegrasyonu
Senaryo
GDT Transmitter'dan tare eventi geldiğinde, paket bilgisini SAP ERP'ye kaydet.
Webhook Endpoint
n8n'de Webhook Trigger oluşturun:
URL: https://n8n.fabrika.local/webhook/weighing-complete
Method: POST
HMI'dan çağrı (QML):
Button {
text: "TARE ve KAYDET"
onClicked: {
modbusClient.sendTare()
// n8n webhook'a POST
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://n8n.fabrika.local/webhook/weighing-complete");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({
"tank_id": "tank1",
"weight_kg": modbusClient.netWeight,
"operator": "Ahmet Yılmaz",
"timestamp": Date.now()
}));
}
}
n8n Workflow:
1. Webhook Trigger (yukardaki URL)
2. Function Node (Veri Hazırlama)
return {
json: {
MaterialDocument: {
MaterialDocumentItem: [
{
Material: 'SUE1000', // Süt ürün kodu
Plant: 'FAB1',
StorageLocation: 'TK01',
QuantityInBaseUnit: $json.body.weight_kg,
BaseUnit: 'KG',
GoodsMovementType: '101', // Stoka giriş
},
],
},
},
}
3. HTTP Request Node (SAP API)
{
"method": "POST",
"url": "https://sap.fabrika.local:443/sap/opu/odata/sap/API_MATERIAL_DOCUMENT_SRV/A_MaterialDocumentHeader",
"authentication": "basicAuth",
"sendBody": true,
"bodyContentType": "json",
"jsonBody": "={{$json}}"
}
4. IF Node (Error Check)
if ($json.statusCode === 201) {
return [{ json: { success: true } }]
} else {
return [null, { json: { error: $json.body } }]
}
5a. Success → Slack Notification
{
"channel": "#production",
"text": ":white_check_mark: SAP'ye kayıt başarılı: {{$json.body.weight_kg}} kg"
}
5b. Error → Email Alert
{
"toEmail": "[email protected]",
"subject": "SAP Entegrasyon Hatası",
"text": "Hata detayı: {{$json.error}}"
}
Gelişmiş Özellikler
1. Error Handling ve Retry
n8n'de her node için Error Workflow tanımlayabilirsiniz:
[MQTT] → [IF Error] → [Wait 5s] → [Retry MQTT]
└→ [After 3 retries] → [Slack Alert]
2. Data Transformation
JavaScript function node ile karmaşık dönüşümler:
// Modbus float parse
const reg1 = $json.registers[0]
const reg2 = $json.registers[1]
const buffer = Buffer.alloc(4)
buffer.writeUInt16BE(reg1, 0)
buffer.writeUInt16BE(reg2, 2)
const floatValue = buffer.readFloatBE(0)
return { json: { weight: floatValue } }
3. Conditional Routing
Switch node ile karmaşık senaryolar:
[MQTT] → [Switch: Tank ID]
├─→ Tank1 → [Email Group A]
├─→ Tank2 → [Email Group B]
└─→ Tank3 → [Slack + Email]
Güvenlik ve Best Practices
1. Webhook Authentication
// Function node: Token kontrolü
const authHeader = $input.item.headers.authorization
const expectedToken = $env.WEBHOOK_TOKEN
if (authHeader !== `Bearer ${expectedToken}`) {
throw new Error('Unauthorized')
}
return $input.all()
2. Credentials Management
n8n'de credentials güvenli saklanır:
- AWS IoT certificates
- MySQL passwords
- Email SMTP credentials
- SAP API keys
Asla workflow'da hardcode etmeyin!
3. Rate Limiting
MQTT'den saniyede 100 mesaj geliyor mu? Aggregate node ile gruplayın:
[MQTT] → [Aggregate: 10s window] → [Process Batch]
Maliyet Karşılaştırması
| Platform | Aylık Maliyet | Limitler |
|---|---|---|
| Zapier | $20-$600 | 750-50K tasks/ay |
| Integromat (Make) | $9-$299 | 1K-40K ops/ay |
| n8n (Self-hosted) | $0 | Limitsiz |
| n8n Cloud | $20-$900 | 2.5K-500K executions/ay |
n8n self-hosted, sunucu maliyeti hariç tamamen ücretsiz ve limitsizdir.
Gerçek Dünya Örneği
Bir gıda fabrikasında n8n kullanarak:
Öncesi:
- Manuel Excel kayıtları
- Email manuel gönderim
- SAP'ye manuel veri girişi
- Alarmlar operatör gözetimi ile
Sonrası (n8n ile):
- Otomatik Excel raporları (günlük)
- Threshold aşımında anında email/Slack
- SAP'ye otomatik stok kaydı
- 24/7 otomatik alarm
Sonuç: Operatör %60 daha verimli, hata oranı %90 azaldı.
Sonuç
n8n, Cloud & IoT Veri Toplama Çözümlerimiz ekosisteminde kritik bir rol oynar:
✅ No-code: Yazılımcı olmadan otomasyon
✅ Açık kaynak: Sınırsız kullanım
✅ Güvenli: Self-hosted, veri kontrolü sizde
✅ Esnek: 350+ hazır entegrasyon
n8n kurulumu ve workflow geliştirme desteği için iletişime geçin.