Hello Johannes,
I adjusted Robert’s code to filter on deviceID;
so after some trial & error, I found I need to use d.records.deviceID
for that:
54
collection "350916062784635_Data_WT_y2024"
site_place "Badeplasser"
site_name "bystranda"
short_name "bystranda"
region "sorlandet"
title "Sørlandet"
kommune
title "Kristiansand"
name "kristiansand"
status "active"
records
_id "66a19351bd5db5e4dbb34e8e"
deviceID "350916062784635"
region "sorlandet"
instead of
d.site_name
collection "350916062784635_Data_WT_y2024"
site_place "Badeplasser"
site_name "bystranda"
.
About 'struggles to connect to the URL: Maybe they log your IP and don’t want you to ‘scrape’ their site.
You can also just copy/paste the URL in a browser to see what happens (or not)
The code:
const URL = 'https://api-badetassen.eu.ngrok.io/test/get/iot/wt/data?when=last';
const response = await fetch(URL);
if (response.status !== 200) throw Error('Invalid response from website');
const data = await response.json();
const record = data.find(d => d.records.deviceID === '350916062784635');
if (! record) throw Error('Cannot find record');
//Just to show what returns what
// oh, and \n = newline, and \t = tab
log(`region:\t\t${record.records.region}\nkommune:\t${record.records.kommune}\nname:\t\t${record.records.name}\nmeasValue:\t${record.records.measValue}\nMeasUnit:\t${record.records.measUnit}\nlat:\t\t${record.records.lat}\nlng:\t\t${record.records.lng}\nupdatedAt:\t${record.records.updatedAt}`);
// To show all returned data unfiltered
log('\nAll unfiltered data:\n',data);
return record.records.measValue;

The line log('\nAll unfiltered data:\n',data);
returns this (just a snippet, while it’s huge):
All unfiltered data:
[
{
collection: '350916062783082_Data_WT_y2024',
site_place: 'Badeplasser',
site_name: 'sjøbadet',
short_name: 'sjøbadet',
region: 'vestlandet',
title: 'Vestlandet',(
kommune: { title: 'Sola', name: 'sola', status: 'active' },
records: {
_id: '66a1a1c1bd5db5e4dbb35958',
deviceID: '350916062783082',
region: 'vestlandet',
kommune: 'Sola',
name: 'Sjøbadet',
yrName: 'Myklebust Sjøbad',
lat: 58.9473,
lng: 5.5701,
measType: 'WT',
measUnit: 'Cel',
measValue: 18,
UTC: '+00',
createdAt: '2024-07-25T00:52:17.248Z',
updatedAt: '2024-07-25T00:52:17.248Z',
__v: 0
}
},
{
collection: '350916062784502_Data_WT_y2024',
site_place: 'Badeplasser',
site_name: 'damp egersund',
short_name: 'damp egersund',
region: 'vestlandet',
title: 'Vestlandet',
kommune: { title: 'Egersund', name: 'egersund', status: 'active' },
records: {
_id: '66a1a334bd5db5e4dbb35a48',
deviceID: '350916062784502',
region: 'vestlandet',
kommune: 'Egersund',
name: 'Damp Egersund',
yrName: 'Egersund gjestehavn',
lat: 58.45189423944471,
lng: 5.999201339640812,
measType: 'WT',
measUnit: 'Cel',
measValue: 17.8,
UTC: '+00',
createdAt: '2024-07-25T00:58:28.305Z',
updatedAt: '2024-07-25T00:58:28.305Z',
__v: 0
}
},
TRUNCATED
]