guicybercode/fuzzy-kernel
A high-performance, distributed IoT platform combining Zig for edge computing and Elixir for server orchestration. This platform enables real-time sen...
A high-performance, distributed IoT platform combining Zig for edge computing and Elixir for server orchestration. This platform enables real-time sensor data collection, WebAssembly-based edge scripting, TinyML anomaly detection, and Over-The-Air (OTA) firmware updates.
The edge firmware runs on Raspberry Pi devices and provides:
The control server orchestrates all devices through:
Edge Device (Zig) ←→ MQTT/TLS ←→ EMQ X Broker ←→ Elixir Server ←→ LiveView Dashboard
↓ ↓
Local Cache PostgreSQL Database
↓
WASM Scripts
↓
TinyML Model
docker-compose up -d
docker-compose ps
EMQ X Dashboard: http://localhost:18083 (admin/public) PostgreSQL: localhost:5432
cd server
mix deps.get
mix ecto.create
mix ecto.migrate
cd assets && npm install && cd ..
mix phx.server
Server runs at: http://localhost:4000
cd edge
zig build -Dtarget=arm-linux-gnueabihf -Doptimize=ReleaseSafe
zig build
export DEVICE_ID=device-001
export MQTT_BROKER_HOST=localhost
export MQTT_BROKER_PORT=1883
zig build run
To deploy on Raspberry Pi:
cd edge
zig build -Dtarget=arm-linux-gnueabihf -Doptimize=ReleaseSafe
scp zig-out/bin/microkernel-edge [email protected]:/home/pi/
On the Raspberry Pi:
chmod +x microkernel-edge
./microkernel-edge
microkernel/
├── edge/ # Zig edge firmware
│ ├── build.zig # Build system with ARM cross-compilation
│ ├── config/
│ │ └── config.zig # Configuration management
│ └── src/
│ ├── main.zig # Main daemon entry point
│ ├── mqtt_client.zig # MQTT client with TLS
│ ├── coap_client.zig # CoAP protocol implementation
│ ├── sensors.zig # Generic sensor abstraction
│ ├── wasm_runtime.zig # WebAssembly runtime
│ ├── tinyml.zig # TinyML inference engine
│ ├── cache.zig # Local cache with persistence
│ └── tls.zig # TLS implementation
├── server/ # Elixir control server
│ ├── mix.exs # Project dependencies
│ ├── config/ # Application configuration
│ ├── lib/
│ │ ├── microkernel/
│ │ │ ├── application.ex # OTP application
│ │ │ ├── repo.ex # Ecto repository
│ │ │ ├── mqtt/
│ │ │ │ ├── subscriber.ex # MQTT message handler
│ │ │ │ └── publisher.ex # Command publisher
│ │ │ ├── devices/
│ │ │ │ ├── device.ex # Device schema
│ │ │ │ ├── registry.ex # Device registry
│ │ │ │ └── supervisor.ex # Device supervision
│ │ │ ├── ota/
│ │ │ │ └── updater.ex # OTA update manager
│ │ │ └── telemetry.ex # Telemetry collection
│ │ └── microkernel_web/
│ │ ├── endpoint.ex # Phoenix endpoint
│ │ ├── router.ex # Routes
│ │ └── live/
│ │ ├── device_live/
│ │ │ ├── index.ex # Device list dashboard
│ │ │ └── show.ex # Device detail view
│ │ └── components/ # Reusable components
│ └── priv/
│ └── repo/
│ └── migrations/ # Database migrations
├── docker-compose.yml # Infrastructure orchestration
└── README.md # This file
Environment variables for edge devices:
DEVICE_ID=device-001 # Unique device identifier
MQTT_BROKER_HOST=localhost # MQTT broker hostname
MQTT_BROKER_PORT=1883 # MQTT broker port
MQTT_CA_CERT=/path/to/ca.crt # CA certificate (optional)
MQTT_CLIENT_CERT=/path/to/client.crt # Client certificate (optional)
MQTT_CLIENT_KEY=/path/to/client.key # Client key (optional)
Edit server/config/dev.exs for development settings:
config :microkernel, :mqtt,
host: "localhost",
port: 1883,
client_id: "microkernel_server"
config :microkernel, Microkernel.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "microkernel_dev",
pool_size: 10
devices/{device_id}/telemetry
Payload:
{
"device_id": "device-001",
"sensor": "Temperature",
"value": 23.5,
"unit": "°C",
"timestamp": 1704067200,
"anomaly": false,
"confidence": 0.95
}
devices/{device_id}/commands
Payload:
{
"command": "update",
"payload": {
"version": "1.0.0"
},
"timestamp": 1704067200
}
The LiveView dashboard provides real-time monitoring:
Register and deploy firmware updates:
# In IEx console
Microkernel.OTA.Updater.register_update(
"1.0.1",
"https://example.com/firmware/1.0.1.bin",
"sha256:abcd1234...",
"Bug fixes and improvements"
)
Microkernel.OTA.Updater.deploy_update("device-001", "1.0.1")
Load and execute WebAssembly modules on edge devices:
const wasm_runtime = try wasm.WasmRuntime.init(allocator);
try wasm_runtime.loadModule("sensor_filter", "/path/to/filter.wasm");
const result = try wasm_runtime.processSensorData(
"sensor_filter",
"filter_temperature",
temperature_value
);
The edge devices include a TinyML engine for local inference:
const ml_engine = try tinyml.TinyMLEngine.init(allocator);
try ml_engine.loadModel(
"anomaly_detector",
"/var/lib/microkernel/models/anomaly.bin",
.AnomalyDetection
);
const result = try ml_engine.predictAnomaly("anomaly_detector", sensor_value);
if (result.anomaly_detected) {
// Handle anomaly
}
Edge (Zig):
cd edge
zig build test
Server (Elixir):
cd server
mix test
Edge (Zig):
zig fmt src/
Server (Elixir):
mix format
Basic MQTT communication
Sensor abstraction layer
WebAssembly runtime
TinyML inference
LiveView dashboard
OTA updates
Multi-region deployment
Advanced analytics
Mobile app
REST API
MIT License - see LICENSE file for details
Contributions are welcome! Please open an issue or submit a pull request.
For questions and support, please open an issue on GitHub.
성경 구절 (聖經 句節)
너희는 먼저 그의 나라와 그의 의를 구하라 그리하면 이 모든 것을 너희에게 더하시리라
마태복음 6:33
But seek first his kingdom and his righteousness, and all these things will be given to you as well.
Matthew 6:33