A lightweight Arduino library for sending sensor data to InfluxDB Cloud. This library provides an easy-to-use interface for IoT data collection and transmission, with support for multiple sensors, batch operations, and power management features.
- Features
- Installation
- Dependencies
- Basic Usage
- Examples
- Advanced Features
- Compatibility
- Troubleshooting
- Contributing
- License
- Author
- Support
- Simple API for sending data to InfluxDB
- Support for multiple sensors
- Batch operations for efficient data transmission
- Power management capabilities
- Built-in error handling and retry logic
- HTTPS secure communication
- Compatible with ESP8266 and ESP32 boards
- Open Arduino IDE
- Go to Sketch -> Include Library -> Manage Libraries
- Search for "LightweightIoT"
- Click Install
- Download this repository as ZIP
- Open Arduino IDE
- Go to Sketch -> Include Library -> Add .ZIP Library
- Select the downloaded ZIP file
- ArduinoJson (>=6.0.0)
- ESP8266 or ESP32 board package (includes WiFi and HTTPClient)
#include <LightweightIoT.h>
// InfluxDB configuration
const char* INFLUXDB_URL = "your-influxdb-url";
const char* INFLUXDB_TOKEN = "your-token";
const char* INFLUXDB_ORG = "your-org";
const char* INFLUXDB_BUCKET = "your-bucket";
// WiFi configuration
const char* WIFI_SSID = "your-ssid";
const char* WIFI_PASSWORD = "your-password";
// Create IoT client
LightweightIoT iot;
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Configure and begin
iot.setConfig(INFLUXDB_URL, INFLUXDB_TOKEN, INFLUXDB_ORG, INFLUXDB_BUCKET);
iot.begin();
// Add tags
iot.addTag("device", "sensor1");
iot.addTag("location", "room1");
}
void loop() {
// Read sensor data
float temperature = 23.5; // Replace with actual sensor reading
// Send data
if (iot.writePoint("temperature", temperature)) {
Serial.println("Data sent successfully");
} else {
Serial.println("Failed to send data");
}
delay(60000); // Wait for 1 minute
}The library includes several example sketches demonstrating different features:
- BasicExample: Simple data transmission
- BasicTemperature: Temperature monitoring
- BasicBatch: Batch data collection
- BasicMultiSensor: Multiple sensor handling
- EnergyMonitoring: Power consumption monitoring
- EnvironmentalMonitoring: Environmental data with power saving
- MultiSensorExample: Advanced sensor management
Find these examples in the Arduino IDE under File -> Examples -> LightweightIoT
iot.beginBatch();
for (int i = 0; i < 5; i++) {
float temperature = readTemperature(); // Your sensor reading function
iot.addToBatch("temperature", temperature);
delay(1000);
}
iot.endBatch();if (!iot.writePoint("temperature", temperature)) {
Serial.print("Error: ");
Serial.println(iot.getLastErrorMessage());
}// Enable low power mode with 5-minute deep sleep
iot.setDeepSleepDuration(300000);
iot.enableLowPowerMode(true);- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This library is released under the MIT License. See the LICENSE file for details.
Judas Sithole (judassithole@duck.com)
For issues and feature requests, please create an issue in the GitHub repository: https://github.com/RacoonX65/LightweightIoT-Arduino-Lib
This library has been tested with:
- ESP8266 boards (NodeMCU, Wemos D1 Mini)
- ESP32 boards (ESP32 DevKit, ESP32-WROOM)
- Arduino IDE 1.8.x and 2.x
- Connection Failed: Ensure your WiFi credentials and InfluxDB configuration are correct
- Data Not Appearing: Verify your bucket and organization settings in InfluxDB
- Compilation Errors: Make sure you have the correct board package installed
For more detailed troubleshooting, check the Issues page.