Added wind data
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
GeorgeWebberley 2026-01-28 11:24:38 +01:00
parent d0c8d34435
commit 7704532aa9

View file

@ -9,30 +9,32 @@ const bucket = process.env.DOCKER_INFLUXDB_INIT_BUCKET;
const client = new InfluxDB({ url, token });
const writeApi = client.getWriteApi(org, bucket);
const lat = 51.58;
const lon = -4.29;
const marineUrl = `https://marine-api.open-meteo.com/v1/marine?latitude=${lat}&longitude=${lon}&current=swell_wave_height,swell_wave_period,swell_wave_direction,wind_wave_height`;
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&current=wind_speed_10m,wind_direction_10m`;
async function fetchSurfData() {
try {
const lat = 51.58;
const lon = -4.29;
console.log("🌊 Fetching latest swell data...");
const url = `https://marine-api.open-meteo.com/v1/marine?latitude=${lat}&longitude=${lon}&current=swell_wave_height,swell_wave_period,swell_wave_direction,wind_wave_height`;
const response = await axios.get(url);
const current = response.data.current;
const [marineRes, weatherRes] = await Promise.all([
axios.get(marineUrl),
axios.get(weatherUrl)
]);
const currentSwell = marineRes.data.current;
const currentWind = weatherRes.data.current;
const point = new Point('surf_conditions')
.tag('location', 'rhossili_beach')
.floatField('swell_height', current.swell_wave_height)
.floatField('swell_period', current.swell_wave_period)
.floatField('swell_direction', current.swell_wave_direction)
.floatField('wind_wave_height', current.wind_wave_height);
.floatField('swell_height', currentSwell.swell_wave_height)
.floatField('swell_period', currentSwell.swell_wave_period)
.floatField('swell_direction', currentSwell.swell_wave_direction)
.floatField('wind_speed', currentWind.wind_speed_10m)
.floatField('wind_direction', currentWind.wind_direction_10m);
console.log(`📡 Data Captured: ${current.swell_wave_height}m at ${current.swell_wave_direction}°`);
// Write and explicitly flush
writeApi.writePoint(point);
await writeApi.flush();
console.log(`✅ Success! Data persisted.`);
await writeApi.flush();
console.log(`✅ Success: Captured ${currentSwell.swell_wave_height}m swell and ${currentWind.wind_speed_10m}km/h wind.`);
} catch (error) {
// If it's a connection error, let's be descriptive
if (error.code === 'ECONNREFUSED') {