Compare commits

..

4 Commits

5 changed files with 4278 additions and 3370 deletions

View File

@ -41,7 +41,8 @@ function useSensor(measurement, name, end, duration) {
const get = async() => { const get = async() => {
setLoading(true); setLoading(true);
try { try {
const params = { end: end.unix(), duration: duration.len.toLowerCase(), window: duration.win }; const api_key = localStorage.getItem('api_key', 'null');
const params = { end: end.unix(), duration: duration.len.toLowerCase(), window: duration.win, api_key: api_key };
const res = await axios.get( const res = await axios.get(
'https://sensors-api.dns.t0.vc/history/'+measurement+'/'+name, 'https://sensors-api.dns.t0.vc/history/'+measurement+'/'+name,
{ params: params }, { params: params },
@ -368,6 +369,67 @@ function BedroomTemperature({end, duration}) {
); );
} }
function BasementTemperature({end, duration}) {
const [data, loading, tickFormatter] = useSensor('temperature', 'Basement', end, duration);
return (
<ChartContainer
name='Basement Temperature'
data={data}
lastFormatter={(x) => x.temperature_C?.toFixed(1) + ' °C'}
loading={loading}
>
<XAxis
dataKey='time'
minTickGap={10}
tickFormatter={tickFormatter}
/>
<YAxis
yAxisId='right'
domain={[0, 100]}
orientation='right'
hide={true}
/>
<YAxis
yAxisId='left'
domain={[-40, 40]}
/>
<CartesianGrid strokeDasharray='3 3'/>
<Tooltip
formatter={(v, name) => v.toFixed(1) + units[name]}
labelFormatter={timeStr => moment(timeStr).tz('America/Edmonton').format('ddd MMM DD h:mm A')}
separator=': '
/>
<ReferenceLine yAxisId='left' x={moment().tz('America/Edmonton').startOf('day').toISOString().replace('.000', '')} stroke='blue' />
<Line
type='monotone'
dataKey='temperature_C'
yAxisId='left'
name='Temperature'
stroke='black'
strokeWidth={2}
dot={false}
isAnimationActive={false}
/>
<Line
type='monotone'
dataKey='humidity'
yAxisId='right'
name='Humidity'
stroke='blue'
strokeWidth={2}
dot={false}
isAnimationActive={false}
/>
</ChartContainer>
);
}
function MiscTemperature({end, duration}) { function MiscTemperature({end, duration}) {
const [data, loading, tickFormatter] = useSensor('temperature', 'Misc', end, duration); const [data, loading, tickFormatter] = useSensor('temperature', 'Misc', end, duration);
@ -893,6 +955,14 @@ function LivingRoomLux({end, duration}) {
function Graphs({end, duration}) { function Graphs({end, duration}) {
const api_key = localStorage.getItem('api_key', false);
const handleSubmit = (e) => {
e.preventDefault();
const api_key = e.target[0].value;
localStorage.setItem('api_key', api_key);
}
return ( return (
<div className='container'> <div className='container'>
<SolarPower end={end} duration={duration} /> <SolarPower end={end} duration={duration} />
@ -903,11 +973,22 @@ function Graphs({end, duration}) {
<NookTemperature end={end} duration={duration} /> <NookTemperature end={end} duration={duration} />
<SeedsTemperature end={end} duration={duration} /> <SeedsTemperature end={end} duration={duration} />
<MiscTemperature end={end} duration={duration} /> <MiscTemperature end={end} duration={duration} />
<BasementTemperature end={end} duration={duration} />
<Thermostat end={end} duration={duration} /> <Thermostat end={end} duration={duration} />
<Gas end={end} duration={duration} /> <Gas end={end} duration={duration} />
<Water end={end} duration={duration} /> <Water end={end} duration={duration} />
<BedroomSleep end={end} duration={duration} /> <BedroomSleep end={end} duration={duration} />
<LivingRoomLux end={end} duration={duration} /> <LivingRoomLux end={end} duration={duration} />
{!!api_key ||
<div>
<form onSubmit={handleSubmit}>
<p>
<input placeholder='API key' />
</p>
</form>
</div>
}
</div> </div>
); );
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
import time import time
import traceback
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchElementException, WebDriverException
from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.chrome import ChromeDriverManager
import undetected_chromedriver as uc import undetected_chromedriver as uc
@ -17,7 +18,22 @@ chrome_options.add_argument('--headless')
chrome_options.add_argument('start-maximized') chrome_options.add_argument('start-maximized')
chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--no-sandbox')
driver = uc.Chrome(service=ser, options=chrome_options, version_main=116)
try:
driver = uc.Chrome(service=ser, options=chrome_options)
except WebDriverException as e:
print('Wrong chrome driver version, extracting correct version...')
tb = traceback.format_exc()
version_string = tb.split('Current browser version is ')[1]
major_version = version_string.split('.')[0]
print('Trying version:', major_version)
chrome_options = uc.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('start-maximized')
chrome_options.add_argument('--no-sandbox')
driver = uc.Chrome(service=ser, options=chrome_options, version_main=int(major_version))
try: try:
driver.get('https://sensors.dns.t0.vc') driver.get('https://sensors.dns.t0.vc')
@ -31,7 +47,8 @@ try:
'Outside_Temperature', 'Outside_Temperature',
'Bedroom_Temperature', 'Bedroom_Temperature',
'Nook_Temperature', 'Nook_Temperature',
'Misc_Temperature', #'Misc_Temperature',
'Basement_Temperature',
'Nook_Thermostat', 'Nook_Thermostat',
'Gas_Usage', 'Gas_Usage',
'Water_Usage', 'Water_Usage',

View File

@ -8,9 +8,8 @@ body {
.container { .container {
display: flex; display: flex;
flex-wrap: wrap; flex-direction: column;
justify-content: center; align-items: center;
margin-bottom: 3rem;
} }
.chart { .chart {

View File

@ -11,14 +11,13 @@ import 'leaflet/dist/leaflet.css';
let tzcache = {}; let tzcache = {};
const durations = [ const durations = [
{id: 0, len: 'Day', win: '10m', full: '10 min', delta: [1, 'days'], format: 'HH'}, {id: 0, len: 'Day', win: '1m', full: '1 min', delta: [1, 'days'], format: 'HH'},
{id: 1, len: 'Day', win: '1h', full: '1 hour', delta: [1, 'days'], format: 'HH'}, {id: 1, len: 'Week', win: '3m', full: '3 min', delta: [7, 'days'], format: 'HH'},
{id: 2, len: 'Week', win: '1h', full: '1 hour', delta: [7, 'days'], format: 'HH'}, {id: 2, len: 'Week', win: '10m', full: '10 min', delta: [7, 'days'], format: 'HH'},
{id: 3, len: 'Week', win: '1d', full: '1 day', delta: [7, 'days'], format: 'D'}, {id: 3, len: 'Month', win: '10m', full: '10 min', delta: [1, 'months'], format: 'D'},
{id: 4, len: 'Month', win: '1d', full: '1 day', delta: [1, 'months'], format: 'D'}, {id: 4, len: 'Month', win: '1h', full: '1 hour', delta: [1, 'months'], format: 'D'},
{id: 5, len: 'Month', win: '7d', full: '7 day', delta: [1, 'months'], format: 'D'}, {id: 5, len: 'Year', win: '2h', full: '2 hours', delta: [1, 'years'], format: 'M/D'},
{id: 6, len: 'Year', win: '1d', full: '1 day', delta: [1, 'years'], format: 'M/D'}, {id: 6, len: 'Year', win: '1d', full: '1 day', delta: [1, 'years'], format: 'M/D'},
{id: 7, len: 'Year', win: '30d', full: '30 day', delta: [1, 'years'], format: 'M'},
]; ];
const units = { const units = {
@ -69,6 +68,12 @@ function Owntracks({end, duration}) {
const coords = data.length ? data.map(({ lat, lon }) => [lat, lon]).filter(([lat, lon]) => lat !== null || lon !== null) : []; const coords = data.length ? data.map(({ lat, lon }) => [lat, lon]).filter(([lat, lon]) => lat !== null || lon !== null) : [];
const handleSubmit = (e) => {
e.preventDefault();
const api_key = e.target[0].value;
localStorage.setItem('api_key', api_key);
}
return ( return (
<> <>
{loading ? {loading ?
@ -78,12 +83,19 @@ function Owntracks({end, duration}) {
<MapContainer center={coords[coords.length-1]} zoom={13} scrollWheelZoom={true} style={{ width: '100%', height: 'calc(100vh - 2.5rem)' }}> <MapContainer center={coords[coords.length-1]} zoom={13} scrollWheelZoom={true} style={{ width: '100%', height: 'calc(100vh - 2.5rem)' }}>
<TileLayer <TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" url='https://maptiles.p.rapidapi.com/en/map/v1/{z}/{x}/{y}.png?rapidapi-key=4375b0b1d8msh0c9e7fa3efb9adfp1769dfjsnd603a0387fea'
/> />
<Polyline pathOptions={{color: 'blue'}} positions={coords} /> <Polyline pathOptions={{color: 'blue'}} positions={coords} />
</MapContainer> </MapContainer>
: :
<p>No coords</p> <>
<p>No data</p>
<form onSubmit={handleSubmit}>
<p>
<input placeholder='API key' />
</p>
</form>
</>
} }
</> </>
); );