This commit is contained in:
parent
d0c8d34435
commit
7704532aa9
|
|
@ -9,30 +9,32 @@ const bucket = process.env.DOCKER_INFLUXDB_INIT_BUCKET;
|
||||||
const client = new InfluxDB({ url, token });
|
const client = new InfluxDB({ url, token });
|
||||||
const writeApi = client.getWriteApi(org, bucket);
|
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() {
|
async function fetchSurfData() {
|
||||||
try {
|
try {
|
||||||
const lat = 51.58;
|
const [marineRes, weatherRes] = await Promise.all([
|
||||||
const lon = -4.29;
|
axios.get(marineUrl),
|
||||||
console.log("🌊 Fetching latest swell data...");
|
axios.get(weatherUrl)
|
||||||
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 currentSwell = marineRes.data.current;
|
||||||
const current = response.data.current;
|
const currentWind = weatherRes.data.current;
|
||||||
|
|
||||||
const point = new Point('surf_conditions')
|
const point = new Point('surf_conditions')
|
||||||
.tag('location', 'rhossili_beach')
|
.tag('location', 'rhossili_beach')
|
||||||
.floatField('swell_height', current.swell_wave_height)
|
.floatField('swell_height', currentSwell.swell_wave_height)
|
||||||
.floatField('swell_period', current.swell_wave_period)
|
.floatField('swell_period', currentSwell.swell_wave_period)
|
||||||
.floatField('swell_direction', current.swell_wave_direction)
|
.floatField('swell_direction', currentSwell.swell_wave_direction)
|
||||||
.floatField('wind_wave_height', current.wind_wave_height);
|
.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);
|
writeApi.writePoint(point);
|
||||||
await writeApi.flush();
|
await writeApi.flush();
|
||||||
|
console.log(`✅ Success: Captured ${currentSwell.swell_wave_height}m swell and ${currentWind.wind_speed_10m}km/h wind.`);
|
||||||
console.log(`✅ Success! Data persisted.`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If it's a connection error, let's be descriptive
|
// If it's a connection error, let's be descriptive
|
||||||
if (error.code === 'ECONNREFUSED') {
|
if (error.code === 'ECONNREFUSED') {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue