Controlling Arduino via REST API
The ardulink-rest module exposes your Arduino as a REST API, letting you control pins and read values using HTTP/JSON. It includes a built-in Swagger UI so you can interact with your Arduino directly from a browser.
What It Does
ardulink-rest is a standalone server that:
- Connects to your Arduino via any Ardulink link
- Exposes REST endpoints for pin control
- Serves a Swagger UI for interactive exploration
- Supports full CRUD operations on digital and analog pins
┌──────────┐ Serial ┌──────────────┐ REST/HTTP ┌──────────────┐
│ Arduino │ <───────> │ ardulink-rest│ <─────────> │ Browser / │
│ (FW) │ │ (server) │ │ curl / API │
└──────────┘ └──────────────┘ └──────────────┘
Quick Start
1. Start the REST Server
java -jar ardulink-rest-2.3.1.jar \
-connection "ardulink://serial?port=/dev/ttyACM0"
For testing:
java -jar ardulink-rest-2.3.1.jar \
-connection "ardulink://virtual-console"
2. Open Swagger UI
Navigate to http://localhost:8080 in your browser. You’ll see the Swagger UI with all available endpoints.
3. Control Arduino from the Browser
Use the interactive Swagger UI to:
- List available pins
- Read digital/analog pin values
- Switch digital pins on/off
- Set analog pin values
- Send custom messages
REST API Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/pins |
List all available pins |
GET |
/api/digital/{pin} |
Read digital pin value |
PUT |
/api/digital/{pin} |
Set digital pin value |
GET |
/api/analog/{pin} |
Read analog pin value |
PUT |
/api/analog/{pin} |
Set analog pin value |
POST |
/api/custom |
Send custom message |
Using with curl
Set Digital Pin HIGH
curl -X PUT http://localhost:8080/api/digital/13 \
-H "Content-Type: application/json" \
-d '{"value": true}'
Read Analog Pin
curl http://localhost:8080/api/analog/0
Set Analog Pin Value
curl -X PUT http://localhost:8080/api/analog/0 \
-H "Content-Type: application/json" \
-d '{"value": 512}'
Maven Dependency
For programmatic REST server setup:
<dependency>
<groupId>org.ardulink</groupId>
<artifactId>ardulink-rest</artifactId>
<version>2.3.1</version>
</dependency>
Use Cases
- Web dashboards — Build HTML/JS dashboards that control Arduino
- Mobile apps — REST APIs work from any HTTP client
- Testing — Quick pin testing from the browser
- Integration — Connect Arduino to any REST-compatible system
- Microservices — Arduino as a REST endpoint in a larger architecture
Next Steps
- Apache Camel Integration — Enterprise messaging
- Ardulink-MQTT — IoT broker alternative
- Custom Messages — Build your own protocols