Advertisement
pleasedontcode

"Sensor Streaming" rev_01

Jan 22nd, 2025
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Sensor Streaming"
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-01-22 15:44:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall utilize the InfluxDB Client */
  21.     /* library to log sensor data to an InfluxDB */
  22.     /* database, ensuring efficient data storage and */
  23.     /* retrieval for IoT applications. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <InfluxDbClient.h> //https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. InfluxDBClient influxDbClient("http://your-influxdb-url:8086", "your-database-name"); // Initialize InfluxDB client
  37.  
  38. void setup(void)
  39. {
  40.     // Initialize serial communication for debugging
  41.     Serial.begin(115200);
  42.    
  43.     // Initialize the InfluxDB client
  44.     if (!influxDbClient.validateConnection()) {
  45.         Serial.print("InfluxDB connection failed: ");
  46.         Serial.println(influxDbClient.getLastErrorMessage());
  47.     }
  48.     else {
  49.         Serial.println("Connected to InfluxDB!");
  50.     }
  51. }
  52.  
  53. void loop(void)
  54. {
  55.     // Example sensor data
  56.     float sensorValue = analogRead(34); // Read from an analog pin (example pin 34)
  57.    
  58.     // Create a point to send to InfluxDB
  59.     Point sensorData("sensor_data"); // Measurement name
  60.     sensorData.addField("value", sensorValue); // Add field with sensor value
  61.     sensorData.addTag("sensor", "analog"); // Add a tag to identify the sensor
  62.  
  63.     // Write the point to InfluxDB
  64.     influxDbClient.writePoint(sensorData);
  65.  
  66.     // Wait before the next read
  67.     delay(10000); // Delay for 10 seconds
  68. }
  69.  
  70. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement