31-micropython
IoT aquarium monitoring with causal inference on Raspberry Pi 5
Install / Use
npx skills add yoshidomekouichi/aquapulseInstalls into whichever agent you are using.
Cursor Rules
Cursor IDE rules (v2)
Quality Score
Category
OperationsSupported Platforms
Skill content
View source on GitHubdescription: MicroPython Coding Standards for ESP32 alwaysApply: false globs:
- "esp32/**/*.py" metadata: environments: cloud
MicroPython Standards (ESP32)
This file applies only to MicroPython code for ESP32 hardware.
Memory Constraints (CRITICAL)
ESP32 RAM: ~100KB available for MicroPython
Flash: 4MB (code + filesystem)
AVOID:
- Large imports (import only what you need)
- Heavy libraries (requests, asyncio extensive use)
- Large data structures in memory
USE:
- Lightweight u-prefixed libraries
- Streaming for large data
- Garbage collection when needed (import gc; gc.collect())
Library Selection
Standard library → u-prefixed version:
# ✓ Correct
import urequests
import ujson
import utime
# ✗ Wrong (these don't exist in MicroPython)
import requests
import json
import time
Common libraries:
urequests- HTTP requests (lightweight)ujson- JSON encoding/decodingutime- Time functionsmachine- Hardware control (GPIO, Pin, etc.)network- WiFi connectivity
Async/Concurrency
⚠️ LIMITED asyncio support
AVOID:
- Complex asyncio patterns
- Multiple concurrent tasks
- AsyncIO-based libraries
OK:
- Simple asyncio.run() for single async function
- time.sleep() for delays (blocking is fine)
PREFER:
- Synchronous, blocking code
- Simple loops with time.sleep()
Error Handling
ALWAYS catch exceptions:
# ✓ Good
try:
response = urequests.post(url, data=data)
print(f'Success: {response.status_code}')
response.close()
except Exception as e:
print(f'Error: {e}')
# Continue or retry
No tracebacks in production:
- MicroPython prints full tracebacks
- Catch exceptions to prevent ugly errors
- Log errors for debugging
Implement reconnection logic:
def connect_wifi():
retry_count = 0
max_retries = 3
while retry_count < max_retries:
try:
wlan.connect(SSID, PASSWORD)
# wait for connection
return True
except Exception as e:
print(f'WiFi error: {e}')
retry_count += 1
utime.sleep(5)
return False
Hardware Access
Pin configuration:
from machine import Pin
# Output (LED, relay)
led = Pin(2, Pin.OUT)
led.on()
led.off()
# Input (button, sensor)
button = Pin(0, Pin.IN, Pin.PULL_UP)
state = button.value()
DS18B20 Temperature Sensor:
import machine
import onewire
import ds18x20
dat = machine.Pin(4)
ds = ds18x20.DS18X20(onewire.OneWire(dat))
roms = ds.scan()
ds.convert_temp()
utime.sleep_ms(750)
temp = ds.read_temp(roms[0])
Network Operations
WiFi connection:
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
# Wait for connection
while not wlan.isconnected():
utime.sleep(1)
print(f'Connected: {wlan.ifconfig()[0]}')
HTTP POST:
import urequests
import ujson
data = {'sensor_id': 'esp32_001', 'value': 25.5}
response = urequests.post(
'https://example.com/api',
headers={'Content-Type': 'application/json'},
data=ujson.dumps(data),
timeout=10
)
print(f'Status: {response.status_code}')
response.close() # Always close!
Before Writing MicroPython Code
Self-check:
[ ] Using u-prefixed libraries (urequests, ujson)?
[ ] Memory usage considered?
[ ] Avoid complex asyncio?
[ ] Exception handling implemented?
[ ] WiFi reconnection logic?
[ ] HTTP response.close() called?
Common Mistakes
✗ Using standard Python libraries (requests, json)
✗ Not closing HTTP responses (memory leak)
✗ Complex asyncio patterns
✗ No exception handling
✗ No WiFi reconnection logic
✗ Large data structures in RAM
Debugging
Print debugging:
print(f'Temperature: {temp:.2f}C')
print(f'WiFi status: {wlan.isconnected()}')
print(f'Free memory: {gc.mem_free()} bytes')
REPL access:
- Connect via USB serial (e.g., screen, picocom)
- Test code interactively
- Check errors immediately
Soft reset:
import machine
machine.soft_reset()
Related Skills
Agent-Reach
84.7kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
headroom
73.5kCompress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
nanobot
48.5kUltra-lightweight, open-source, self-hosted personal AI agent framework in Python with WebUI, tools, memory, MCP, multi-agent workflows, automation, and chat apps
Scrapling
83.0k🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev
Security Score
Audited on Invalid Date
