-
Notifications
You must be signed in to change notification settings - Fork 1
API Reference
GALIH RIDHO UTOMO edited this page Feb 24, 2025
·
1 revision
This page documents all classes, methods, and properties available in the GitHub IoT Arduino Module.
The main class for interacting with GitHub repositories for IoT data storage.
githubiot(const char* token, const char* repo_url)Creates a new instance of the githubiot class.
Parameters:
-
token: GitHub authentication token with 'Bearer ' prefix -
repo_url: GitHub API URL for the target file
Example:
const char* token = "Bearer ghp_xxxxxxxxxxxxxxxxxxxx";
const char* repo_url = "https://api.github.com/repos/username/repo/contents/data.json";
githubiot iot_module(token, repo_url);String get_current_sha()Retrieves the current SHA hash of the file in the GitHub repository.
Returns:
- String containing the SHA hash, or empty string if failed
Example:
String sha = iot_module.get_current_sha();
if (sha != "") {
Serial.println("Current SHA: " + sha);
} else {
Serial.println("Failed to get SHA");
}void upload_to_github(DynamicJsonDocument doc, String& last_sha)Uploads JSON data to GitHub by updating the specified file.
Parameters:
-
doc: ArduinoJson DynamicJsonDocument containing the data to upload -
last_sha: Reference to the current SHA string (will be updated with new SHA)
Example:
DynamicJsonDocument doc(1024);
doc["sensor"] = "temperature";
doc["value"] = 25.5;
doc["timestamp"] = 1645729845;
String sha = iot_module.get_current_sha();
iot_module.upload_to_github(doc, sha);These members are used internally by the class:
private:
const char* _token; // GitHub authentication token
const char* _repo_url; // GitHub repository API URL
String _last_sha; // Last known SHA hash#ifndef GITHUBIOT_H
#define GITHUBIOT_H
#include <Arduino.h>
#include <ArduinoJson.h>
#include <base64.h>
// Platform-specific includes
#ifdef ESP32
#include <WiFi.h>
#include <HTTPClient.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#endif
class githubiot {
public:
githubiot(const char* token, const char* repoUrl);
String get_current_sha();
void upload_to_github(DynamicJsonDocument doc, String& last_sha);
private:
const char* _token;
const char* _repo_url;
String _last_sha;
};
#endifFor usage examples, see the Usage Examples 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