42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
|
|
var renderer = new MatrixRenderer("192.168.1.216"); // Your WLED IP
|
|
var ntp = new NtpService("ntp.parsons.cc");
|
|
|
|
// Replace these with your actual InfluxDB v2 credentials
|
|
// If Influx is on the same Pi, you can use the Pi's local IP and port 8086
|
|
var influx = new InfluxDataService(
|
|
url: "http://parsons.cc:8086",
|
|
token: ":",
|
|
org: "-",
|
|
bucket: "sensor_data"
|
|
);
|
|
|
|
Console.WriteLine("Starting DDP stream with live InfluxDB data...");
|
|
|
|
float currentTemp = 1f;
|
|
int currentWaterLevel = 100;
|
|
Stopwatch dbTimer = Stopwatch.StartNew();
|
|
|
|
while (true)
|
|
{
|
|
// Only query the database every 5 seconds (5000 ms)
|
|
if (dbTimer.ElapsedMilliseconds > 5000 || currentTemp == 0f)
|
|
{
|
|
currentTemp = await influx.GetLatestTemperatureAsync();
|
|
currentWaterLevel = await influx.GetLatestWaterAsync();
|
|
Console.WriteLine($"Fetched new temp: {currentTemp}c");
|
|
Console.WriteLine($"Fetched new water: {currentWaterLevel}%");
|
|
dbTimer.Restart();
|
|
}
|
|
|
|
DateTime now = ntp.GetCurrentTime();
|
|
|
|
// Keep pushing frames to WLED at 30 FPS
|
|
await renderer.DrawAndSendFrameAsync(currentTemp, currentWaterLevel, now);
|
|
|
|
|
|
await Task.Delay(1000 / 30);
|
|
} |