-
Notifications
You must be signed in to change notification settings - Fork 1
Technical Details
This page explains the technical aspects of how the GitHub IoT Arduino Module works.
The library interacts with GitHub's REST API through the following workflow:
- Authentication: Each request includes a GitHub Personal Access Token
- GET Request: Retrieves file metadata, including the SHA hash
- Content Processing: Prepares and encodes new content
- PUT Request: Updates the file with new content and the current SHA
- Response Handling: Processes the API response, including the new SHA
The library uses GitHub's Contents API endpoints:
-
GET
/repos/:owner/:repo/contents/:path- Get file contents -
PUT
/repos/:owner/:repo/contents/:path- Update file contents
GitHub requires file contents to be Base64 encoded in API requests. The encoding process follows mathematical principles:
Where each block
For the last block, if the input length is not a multiple of 3, padding is applied:
The library uses the following HTTP headers for API requests:
For GET requests:
Authorization: Bearer {token}
For PUT requests:
Authorization: Bearer {token}
Content-Type: application/json
The library handles various HTTP status codes:
| Status Code | Description | Library Action |
|---|---|---|
| 200 (OK) | Request successful | Process response |
| 401 (Unauthorized) | Invalid token | Return error |
| 404 (Not Found) | File or repo not found | Return error |
| 409 (Conflict) | SHA mismatch | Return error |
| 422 (Unprocessable Entity) | Validation failed | Return error |
The library uses ArduinoJson to handle JSON data. The JSON document structure is determined by the user, but the library handles the GitHub API-specific JSON structures.
Example GitHub API PUT payload:
{
"message": "Update data",
"content": "eyJzZW5zb3IiOiJ0ZW1wZXJhdHVyZSIsInZhbHVlIjoyMy41fQ==",
"sha": "f5f369a7a67a6c2c59daa9e10f65c22c17d9c643"
}Where:
-
message: Commit message -
content: Base64-encoded JSON data -
sha: Current file SHA hash
The memory required for a JSON document can be estimated with:
For ESP8266 devices, the maximum document size is more constrained than on ESP32 devices.
For more information on performance optimization, see the Performance Optimization page.
This documentation is created to provide a comprehensive guide for this project. Feel free to contribute!
๐
Last updated: February 24, 2025
โ๏ธ Maintained by: Your Name
๐ License: MIT License