Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Sensor Streaming"
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-01-22 15:44:44
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall utilize the InfluxDB Client */
- /* library to log sensor data to an InfluxDB */
- /* database, ensuring efficient data storage and */
- /* retrieval for IoT applications. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <InfluxDbClient.h> //https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- InfluxDBClient influxDbClient("http://your-influxdb-url:8086", "your-database-name"); // Initialize InfluxDB client
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(115200);
- // Initialize the InfluxDB client
- if (!influxDbClient.validateConnection()) {
- Serial.print("InfluxDB connection failed: ");
- Serial.println(influxDbClient.getLastErrorMessage());
- }
- else {
- Serial.println("Connected to InfluxDB!");
- }
- }
- void loop(void)
- {
- // Example sensor data
- float sensorValue = analogRead(34); // Read from an analog pin (example pin 34)
- // Create a point to send to InfluxDB
- Point sensorData("sensor_data"); // Measurement name
- sensorData.addField("value", sensorValue); // Add field with sensor value
- sensorData.addTag("sensor", "analog"); // Add a tag to identify the sensor
- // Write the point to InfluxDB
- influxDbClient.writePoint(sensorData);
- // Wait before the next read
- delay(10000); // Delay for 10 seconds
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement