Skip to content

Commit d47e456

Browse files
embhornclaude
andcommitted
Add CLAUDE.md for Claude Code guidance
Provides build commands, architecture overview, and development information for AI-assisted development with Claude Code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ea02a33 commit d47e456

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

CLAUDE.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Overview
6+
7+
wolfMQTT is an MQTT client library written in C for embedded systems. It supports MQTT v3.1.1 and v5.0 protocols, MQTT-SN for sensor networks, and integrates with wolfSSL for TLS support.
8+
9+
## Build Commands
10+
11+
### Standard Build (Linux/macOS)
12+
```bash
13+
./autogen.sh # Required if cloned from GitHub
14+
./configure # See --help for options
15+
make
16+
sudo make install
17+
```
18+
19+
### Run Tests
20+
```bash
21+
make check # Runs all tests with local mosquitto broker
22+
```
23+
24+
### Individual Test Scripts
25+
```bash
26+
./scripts/client.test # Main MQTT client tests (QoS 0-2, TLS)
27+
./scripts/nbclient.test # Non-blocking client tests
28+
./scripts/multithread.test # Multi-threading tests
29+
./scripts/stress.test # Stress testing (requires --enable-stress)
30+
```
31+
32+
### CMake Build
33+
```bash
34+
mkdir build && cd build
35+
cmake .. -DWITH_WOLFSSL=/path/to/wolfssl/install/ # Use installed wolfSSL
36+
# OR
37+
cmake .. -DWITH_WOLFSSL_TREE=/path/to/wolfssl/ # Use source tree
38+
cmake --build .
39+
```
40+
41+
### Common Configure Options
42+
```bash
43+
--enable-tls # TLS support (default: enabled)
44+
--enable-v5 # MQTT v5.0 support
45+
--enable-sn # MQTT-SN (Sensor Network) support
46+
--enable-nonblock # Non-blocking I/O support
47+
--enable-mt # Multi-threading support
48+
--enable-websocket # WebSocket support (requires libwebsockets)
49+
--enable-curl # libcurl backend support
50+
--enable-all # Enable all features
51+
--enable-debug # Debug mode (--enable-debug=verbose for extra logging)
52+
--enable-stress # Stress testing (e.g., --enable-stress=t7,p8 for 7 threads, 8 pubs)
53+
--disable-tls # Disable TLS for testing without wolfSSL
54+
```
55+
56+
### Running Examples
57+
```bash
58+
./examples/mqttclient/mqttclient -? # Show help with available options
59+
./examples/mqttclient/mqttclient -h localhost -p 1883 # Connect to local broker
60+
./examples/mqttclient/mqttclient -h localhost -t -p 8883 # TLS connection
61+
```
62+
63+
## Architecture
64+
65+
### Core Library Components (in /src/)
66+
67+
1. **mqtt_client.c** - Top-level client API
68+
- `MqttClient_Init()`, `MqttClient_Connect()`, `MqttClient_Publish()`
69+
- `MqttClient_Subscribe()`, `MqttClient_WaitMessage()`, `MqttClient_Disconnect()`
70+
71+
2. **mqtt_packet.c** - MQTT packet encoding/decoding
72+
- Structures: `MqttConnect`, `MqttPublish`/`MqttMessage`, `MqttSubscribe`
73+
74+
3. **mqtt_socket.c** - Transport layer with TLS integration
75+
- Network callbacks via `MqttNet` structure
76+
77+
4. **mqtt_sn_client.c / mqtt_sn_packet.c** - MQTT-SN protocol support
78+
79+
### Public Headers (in /wolfmqtt/)
80+
81+
- `mqtt_types.h` - Type definitions, error codes, platform abstractions
82+
- `mqtt_client.h` - Client API declarations
83+
- `mqtt_packet.h` - Packet structures
84+
- `mqtt_socket.h` - Network interface
85+
- `options.h` - Generated build configuration
86+
87+
### Examples (in /examples/)
88+
89+
- `mqttclient/` - Full-featured reference client (best starting template)
90+
- `mqttsimple/` - Standalone BSD sockets client
91+
- `nbclient/` - Non-blocking I/O example
92+
- `multithread/` - Multi-threaded publish/subscribe
93+
- `firmware/` - Firmware update (fwpush/fwclient)
94+
- `aws/`, `azure/`, `wiot/` - Cloud platform integrations
95+
- `sn-client/` - MQTT-SN client
96+
- `websocket/` - WebSocket client
97+
- `pub-sub/` - Simple mqtt-pub and mqtt-sub utilities
98+
99+
### Shared Example Code
100+
101+
- `examples/mqttnet.c` - Network callback reference implementation
102+
- `examples/mqttport.c` - Platform abstraction layer
103+
- `examples/mqttexample.c` - Common example utilities
104+
105+
## Key Compile Macros
106+
107+
```c
108+
ENABLE_MQTT_TLS // TLS support
109+
WOLFMQTT_V5 // MQTT v5.0
110+
WOLFMQTT_SN // MQTT-SN protocol
111+
WOLFMQTT_NONBLOCK // Non-blocking I/O
112+
WOLFMQTT_MULTITHREAD // Multi-threading
113+
WOLFMQTT_DYN_PROP // Dynamic property allocation (v5.0)
114+
DEBUG_WOLFMQTT // Debug mode
115+
```
116+
117+
## Testing
118+
119+
Tests require a local mosquitto broker. The CI uses `bubblewrap` for network isolation.
120+
121+
To skip external broker tests:
122+
```bash
123+
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS=1 ./configure --enable-all
124+
make check
125+
```
126+
127+
Test certificates are in `/certs/` (RSA and ECC variants).
128+
Broker test config: `/scripts/broker_test/mosquitto.conf`
129+
130+
## Code Style
131+
132+
Uses `.clang-format` with LLVM base style:
133+
- Tab indentation (4-space tabs)
134+
- K&R inspired style
135+
136+
## Dependencies
137+
138+
- **wolfSSL** - Required for TLS support
139+
- **libwebsockets** - Optional, for WebSocket support
140+
- **libcurl** - Optional, for curl backend
141+
- **mosquitto** - For running tests

0 commit comments

Comments
 (0)