From 7704532aa9e49de2b30be0a02f9d56b9213170c2 Mon Sep 17 00:00:00 2001 From: GeorgeWebberley Date: Wed, 28 Jan 2026 11:24:38 +0100 Subject: [PATCH] Added wind data --- fetcher/index.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/fetcher/index.js b/fetcher/index.js index 4b6e6ce..b5bccd5 100644 --- a/fetcher/index.js +++ b/fetcher/index.js @@ -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}¤t=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}¤t=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}¤t=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') {