esp32_mqtt_pub.cpp LANG: cpp
Low-latency MQTT sensor telemetry broadcast loop for ESP32 boards using PubSubClient.
#include <WiFi.h>
#include <PubSubClient.h>

WiFiClient espClient;
PubSubClient client(espClient);

void connectMQTT() {
  while (!client.connected()) {
    Serial.print("Connecting MQTT...");
    if (client.connect("ESP32_Node_01", "user", "pass")) {
      Serial.println("connected");
    } else {
      delay(5000);
    }
  }
}

void loop() {
  if (!client.connected()) connectMQTT();
  client.loop();
  
  char payload[64];
  sprintf(payload, "{\"temp\":%.2f,\"hum\":%.2f}", readTemp(), readHum());
  client.publish("sangkara/telemetry", payload);
  delay(1000); // 1Hz telemetry frequency
}
docker-compose.yml LANG: yaml
Multi-container local edge server deployment containing n8n and outbound Cloudflare Tunnels.
version: '3.8'
services:
  n8n:
    image: n8nio/n8n:latest
    container_name: n8n_edge
    restart: always
    ports:
      - "5678:5678"
    volumes:
      - n8n_data:/home/node/.n8n
    environment:
      - GENERIC_TIMEZONE=Asia/Jakarta

  cloudflare-tunnel:
    image: cloudflare/cloudflared:latest
    container_name: cf_tunnel
    restart: always
    command: tunnel --no-autoupdate run
    environment:
      - TUNNEL_TOKEN=${TUNNEL_TOKEN}

volumes:
  n8n_data:
data_cleaner.py LANG: python
Macroeconomic Bloomberg news scraping data normalizer and text preprocessor.
import re
import nltk
from nltk.corpus import stopwords

def preprocess_text(raw_html):
    # Remove HTML markup tags
    clean_text = re.sub(r'<[^>]+>', '', raw_html)
    # Remove non-alphabet characters
    clean_text = re.sub(r'[^a-zA-Z\s]', '', clean_text)
    # Convert to lowercase and tokenize
    words = clean_text.lower().split()
    # Remove standard English stopwords
    stop_words = set(stopwords.words('english'))
    filtered = [w for w in words if w not in stop_words]
    return " ".join(filtered)

# Usage in Pandas DataFrame
# df['clean_content'] = df['raw_news'].apply(preprocess_text)
edge_deploy_check.sh LANG: bash
Automated bash health check script for edge server configurations and Docker containers status.
#!/bin/bash
# Edge server health monitor daemon

THRESHOLD=90
CPU_LOAD=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4}')
RAM_USAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}')

echo "[$(date)] Running System Health Check..."
echo "CPU Load: ${CPU_LOAD}% | Memory Usage: ${RAM_USAGE}%"

if (( $(echo "${CPU_LOAD} > ${THRESHOLD}" | bc -l) )); then
  echo "[WARNING] High CPU Load detected!"
  # Trigger alerting webhook using curl
  curl -X POST -H "Content-Type: application/json" \
    -d '{"event":"high_cpu","load":'"${CPU_LOAD}"'}' \
    http://localhost:5678/webhook/alert
fi
Glenferdinza AI Assistant RAG Systems Engine