用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ForceInjection/domain-driven-design-skills --skill edge-iot命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | edge-iot |
| description | Edge computing, IoT protocols, and embedded systems integration |
| domain | development-stacks |
| version | 1.0.0 |
| tags | ["edge","iot","mqtt","embedded","raspberry-pi","arduino","esp32"] |
Building applications for edge devices, IoT protocols, and embedded systems integration.
# docker-compose.yml
services:
mosquitto:
image: eclipse-mosquitto:2
ports:
- "1883:1883"
- "9001:9001"
volumes:
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf
- mosquitto_data:/mosquitto/data
- mosquitto_log:/mosquitto/log
volumes:
mosquitto_data:
mosquitto_log:
# mosquitto.conf
listener 1883
listener 9001
protocol websockets
allow_anonymous false
password_file /mosquitto/config/passwd
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
import mqtt from 'mqtt';
class MQTTClient {
private client: mqtt.MqttClient;
private subscriptions = new Map<string, Set<Function>>();
constructor(brokerUrl: string, options?: mqtt.IClientOptions) {
this.client = mqtt.connect(brokerUrl, {
clientId: `node_${Math.random().toString(16).slice(2, 10)}`,
clean: true,
reconnectPeriod: 5000,
...options,
});
this.client.on('connect', () => {
console.log('MQTT connected');
// Resubscribe to all topics
this.subscriptions.forEach((_, topic) => {
this.client.subscribe(topic);
});
});
this..(, {
handlers = .(topic);
message = .(payload);
handlers.( (topic, message));
});
..(, {
.(, error);
});
}
() {
(!..(topic)) {
..(topic, ());
..(topic);
}
..(topic)!.(handler);
{
..(topic)?.(handler);
(..(topic)?. === ) {
..(topic);
..(topic);
}
};
}
() {
payload = message ===
? message
: .(message);
..(topic, payload, {
: ,
...options,
});
}
(: ): <> {
handlers = <>();
..( {
(.(pattern, topic)) {
topicHandlers.( handlers.(h));
}
});
handlers;
}
(: , : ): {
patternParts = pattern.();
topicParts = topic.();
( i = ; i < patternParts.; i++) {
(patternParts[i] === ) ;
(patternParts[i] === ) ;
(patternParts[i] !== topicParts[i]) ;
}
patternParts. === topicParts.;
}
(: ): {
str = payload.();
{
.(str);
} {
str;
}
}
() {
..();
}
}
mqtt = (, {
: ,
: ,
});
mqtt.(, {
deviceId = topic.()[];
.(, data);
});
mqtt.(, {
.(, data);
});
mqtt.(, {
: ,
: .(),
});
class DeviceSimulator {
private mqtt: MQTTClient;
private deviceId: string;
private interval: NodeJS.Timeout | null = null;
constructor(deviceId: string, brokerUrl: string) {
this.deviceId = deviceId;
this.mqtt = new MQTTClient(brokerUrl);
// Subscribe to commands
this.mqtt.subscribe(`devices/${deviceId}/commands`, (_, command) => {
this.handleCommand(command);
});
}
start(intervalMs = 5000) {
this.interval = setInterval(() => {
this.sendTelemetry();
}, intervalMs);
}
stop() {
if (this.interval) {
clearInterval(this.);
. = ;
}
}
() {
telemetry = {
: + .() * ,
: + .() * ,
: + .() * ,
: + .() * ,
: .(),
};
..(, telemetry);
}
() {
.(, command);
(command.) {
:
..(, {
: ,
: .(),
});
;
:
;
}
}
}
// Edge function to process IoT data
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
// Device telemetry ingestion
if (url.pathname === '/ingest' && request.method === 'POST') {
const data = await request.json();
const deviceId = request.headers.get('X-Device-ID');
// Validate device
const device = await env.KV.get(`device:${deviceId}`);
if (!device) {
return new Response('Unauthorized', { status: 401 });
}
// Process at edge
const processed = processData(data);
// Store in Durable Object for aggregation
const aggregator = env.AGGREGATOR.get(
env.AGGREGATOR.(deviceId)
);
aggregator.(request., {
: ,
: .(processed),
});
(processed.) {
(, {
: ,
: .({
deviceId,
: processed.,
}),
});
}
();
}
(, { : });
},
};
() {
alert = data. > ? : ;
{
...data,
: .(),
alert,
};
}
{
: ;
: [] = [];
() {
. = state;
}
(: ): <> {
data = request.();
..(data);
(.. > ) {
..();
}
aggregates = {
: .(),
: .(),
: ..,
};
...(, aggregates);
(.(aggregates));
}
(: ): {
values = .
.( r[field])
.( v === );
values.( a + b, ) / values.;
}
}
# boot.py - WiFi connection
import network
import time
def connect_wifi(ssid, password):
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('Connecting to WiFi...')
wlan.connect(ssid, password)
timeout = 10
while not wlan.isconnected() and timeout > 0:
time.sleep(1)
timeout -= 1
if wlan.isconnected():
print('Connected:', wlan.ifconfig())
return True
else:
print('Failed to connect')
return False
connect_wifi('MyNetwork', 'password')
# main.py - Sensor reading and MQTT
from machine import Pin, ADC
from umqtt.simple import MQTTClient
import json
import time
import dht
# Configuration
MQTT_BROKER = '192.168.1.100'
DEVICE_ID = 'esp32-001'
TOPIC_TELEMETRY = f'devices/{DEVICE_ID}/telemetry'
TOPIC_COMMANDS = f'devices/{DEVICE_ID}/commands'
# Hardware setup
led = Pin(2, Pin.OUT)
dht_sensor = dht.DHT22(Pin(4))
light_sensor = ADC(Pin(34))
# MQTT client
client = MQTTClient(DEVICE_ID, MQTT_BROKER)
def on_message(topic, msg):
topic = topic.decode()
data = json.loads(msg.decode())
print(f'Command received: {data}')
if data.get('action') == 'led_on':
led.on()
elif data.get('action') == 'led_off':
led.off()
elif data.get('action') == 'blink':
for _ in range(5):
led.on()
time.sleep(0.2)
led.off()
time.sleep(0.2)
client.set_callback(on_message)
client.connect()
client.subscribe(TOPIC_COMMANDS)
def read_sensors():
dht_sensor.measure()
return {
'temperature': dht_sensor.temperature(),
: dht_sensor.humidity(),
: light_sensor.read(),
: time.time()
}
():
last_publish =
publish_interval =
:
client.check_msg()
current_time = time.time()
current_time - last_publish >= publish_interval:
:
data = read_sensors()
client.publish(TOPIC_TELEMETRY, json.dumps(data))
()
last_publish = current_time
Exception e:
()
time.sleep()
__name__ == :
main()
#include <WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <DHT.h>
// Configuration
const char* ssid = "MyNetwork";
const char* password = "password";
const char* mqtt_server = "192.168.1.100";
const char* device_id = "esp32-001";
// Hardware
#define DHT_PIN 4
#define DHT_TYPE DHT22
#define LED_PIN 2
#define LIGHT_PIN 34
DHT dht(DHT_PIN, DHT_TYPE);
WiFiClient espClient;
PubSubClient client(espClient);
unsigned long lastPublish = 0;
const long publishInterval = 5000;
void setup_wifi() {
delay(10);
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.() != WL_CONNECTED) {
();
Serial.();
}
Serial.();
Serial.(WiFi.());
}
{
StaticJsonDocument<> doc;
(doc, payload, length);
* action = doc[];
((action, ) == ) {
(LED_PIN, HIGH);
} ((action, ) == ) {
(LED_PIN, LOW);
}
}
{
(!client.()) {
Serial.();
(client.(device_id)) {
Serial.();
topic[];
(topic, , device_id);
client.(topic);
} {
Serial.();
Serial.(client.());
();
}
}
}
{
StaticJsonDocument<> doc;
doc[] = dht.();
doc[] = dht.();
doc[] = (LIGHT_PIN);
doc[] = ();
buffer[];
(doc, buffer);
topic[];
(topic, , device_id);
client.(topic, buffer);
Serial.();
}
{
Serial.();
(LED_PIN, OUTPUT);
dht.();
();
client.(mqtt_server, );
client.(callback);
}
{
(!client.()) {
();
}
client.();
now = ();
(now - lastPublish >= publishInterval) {
lastPublish = now;
();
}
}
interface Device {
id: string;
name: string;
type: string;
status: 'online' | 'offline' | 'error';
lastSeen: Date;
metadata: Record<string, any>;
config: Record<string, any>;
}
class DeviceRegistry {
constructor(
private db: Database,
private mqtt: MQTTClient
) {
// Listen for device status
this.mqtt.subscribe('devices/+/status', (topic, status) => {
const deviceId = topic.split('/')[1];
this.updateStatus(deviceId, status);
});
}
async register(device: Omit<Device, 'status' | 'lastSeen'>) {
: = {
...device,
: ,
: (),
};
...({ : fullDevice });
..(, device.);
fullDevice;
}
() {
...({
: { : deviceId },
: { config },
});
..(, config, { : });
}
() {
..(, command);
...({
: {
deviceId,
command,
: (),
},
});
}
() {
...({
: { : deviceId },
: {
: status.,
: (),
},
});
}
}