50 lines
1.1 KiB
Arduino
50 lines
1.1 KiB
Arduino
|
#include <SPI.h>
|
||
|
#include <Ethernet.h>
|
||
|
#include <InfluxdbClient.h>
|
||
|
|
||
|
InfluxdbClient db;
|
||
|
// Network configuration
|
||
|
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC Address
|
||
|
IPAddress ip(10, 10, 1, 176); // IP Address
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
int cpu_usage = 0; // Example value
|
||
|
int memory_usage = 0; // Example value
|
||
|
char server_data[200];// = "system_metrics,host=local cpu_usage=40,memory_usage=100";
|
||
|
|
||
|
// Initialize Ethernet client
|
||
|
EthernetClient client;
|
||
|
|
||
|
void setup() {
|
||
|
Serial.begin(115200);
|
||
|
Ethernet.init(5);
|
||
|
db.begin();
|
||
|
while (!Serial) {
|
||
|
; // Wait for Serial Monitor to open
|
||
|
}
|
||
|
|
||
|
// Start Ethernet connection
|
||
|
Ethernet.begin(mac, ip);
|
||
|
|
||
|
// Give the Ethernet shield a second to initialize
|
||
|
delay(1000);
|
||
|
Serial.println("Ethernet setup completed");
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
Serial.println("sending");
|
||
|
|
||
|
cpu_usage +=3; // Example value
|
||
|
memory_usage += 1; // Example value
|
||
|
|
||
|
sprintf(server_data, "system_metrics,host=local cpu_usage=%d,memory_usage=%d", cpu_usage, memory_usage);
|
||
|
|
||
|
String result = db.Send_db(client, server_data);
|
||
|
|
||
|
|
||
|
Serial.println(result);
|
||
|
delay(2000);
|
||
|
}
|