Initial commit
This commit is contained in:
commit
6474f14aea
23
webclient/.gitignore
vendored
Normal file
23
webclient/.gitignore
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
41
webclient/package.json
Normal file
41
webclient/package.json
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"name": "webclient",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@testing-library/jest-dom": "^5.11.4",
|
||||||
|
"@testing-library/react": "^11.1.0",
|
||||||
|
"@testing-library/user-event": "^12.1.10",
|
||||||
|
"axios": "^0.21.1",
|
||||||
|
"moment": "^2.29.1",
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2",
|
||||||
|
"react-scripts": "4.0.3",
|
||||||
|
"recharts": "^2.0.9",
|
||||||
|
"web-vitals": "^1.0.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"react-app",
|
||||||
|
"react-app/jest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
36
webclient/public/index.html
Normal file
36
webclient/public/index.html
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="theme-color" content="#000000" />
|
||||||
|
<!--
|
||||||
|
manifest.json provides metadata used when your web app is installed on a
|
||||||
|
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||||
|
-->
|
||||||
|
<!--
|
||||||
|
Notice the use of %PUBLIC_URL% in the tags above.
|
||||||
|
It will be replaced with the URL of the `public` folder during the build.
|
||||||
|
Only files inside the `public` folder can be referenced from the HTML.
|
||||||
|
|
||||||
|
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||||
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
|
-->
|
||||||
|
<title>Solar Display</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
<!--
|
||||||
|
This HTML file is a template.
|
||||||
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
||||||
|
You can add webfonts, meta tags, or analytics to this file.
|
||||||
|
The build step will place the bundled scripts into the <body> tag.
|
||||||
|
|
||||||
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
|
-->
|
||||||
|
</body>
|
||||||
|
</html>
|
49
webclient/src/App.css
Normal file
49
webclient/src/App.css
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: #212121;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 40em;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panels:after {
|
||||||
|
content: "";
|
||||||
|
display: table;
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
float: left;
|
||||||
|
width: 23%;
|
||||||
|
padding-bottom: 20%;
|
||||||
|
border-radius: 5%;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 0.5em;
|
||||||
|
position: relative;
|
||||||
|
margin: 1%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-label {
|
||||||
|
position: absolute;
|
||||||
|
color: white;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
font-size: 2em;
|
||||||
|
width: 110%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container p {
|
||||||
|
color: white;
|
||||||
|
font-size: 2em;
|
||||||
|
margin: 0.25em;
|
||||||
|
}
|
||||||
|
|
122
webclient/src/App.js
Normal file
122
webclient/src/App.js
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
||||||
|
import axios from 'axios';
|
||||||
|
import moment from 'moment';
|
||||||
|
import './App.css';
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const [data, setData] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const get = async() => {
|
||||||
|
try {
|
||||||
|
const res = await axios.get('https://reg.t0.vc/solar.json');
|
||||||
|
setData(res.data);
|
||||||
|
} catch (error) {
|
||||||
|
setData(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
get();
|
||||||
|
const interval = setInterval(get, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const listen = () => {
|
||||||
|
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
|
var myArrayBuffer = audioCtx.createBuffer(2, audioCtx.sampleRate * 5, audioCtx.sampleRate);
|
||||||
|
for (var channel = 0; channel < myArrayBuffer.numberOfChannels; channel++) {
|
||||||
|
var nowBuffering = myArrayBuffer.getChannelData(channel);
|
||||||
|
for (var i = 0; i < myArrayBuffer.length; i++) {
|
||||||
|
nowBuffering[i] = data.history[i % data.history.length].total / 24000.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var source = audioCtx.createBufferSource();
|
||||||
|
source.buffer = myArrayBuffer;
|
||||||
|
source.connect(audioCtx.destination);
|
||||||
|
source.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{data ?
|
||||||
|
<div>
|
||||||
|
<ResponsiveContainer width='100%' height={300}>
|
||||||
|
<LineChart data={data.history}>
|
||||||
|
<XAxis
|
||||||
|
dataKey='time'
|
||||||
|
minTickGap={10}
|
||||||
|
tickFormatter={timeStr => moment.utc(timeStr).format('HH:mm')}
|
||||||
|
/>
|
||||||
|
<YAxis />
|
||||||
|
<CartesianGrid strokeDasharray='3 3'/>
|
||||||
|
<Tooltip
|
||||||
|
labelFormatter={timeStr => 'Time: ' + moment.utc(timeStr).format('HH:mm')}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Line
|
||||||
|
type='monotone'
|
||||||
|
dataKey='total'
|
||||||
|
name='Watts'
|
||||||
|
stroke='#ff5900'
|
||||||
|
strokeWidth={2}
|
||||||
|
dot={false}
|
||||||
|
animationDuration={1000}
|
||||||
|
/>
|
||||||
|
</LineChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
|
||||||
|
<button onClick={listen}>Listen</button>
|
||||||
|
|
||||||
|
{data.night ?
|
||||||
|
<div className='container'>
|
||||||
|
<p>The sun has set 😴</p>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<div className='container'>
|
||||||
|
<p>Total: {data.actual_total} W — {parseInt(data.actual_total / 5985 * 100)}%</p>
|
||||||
|
|
||||||
|
<p>Today: {data.today_energy} kWh</p>
|
||||||
|
|
||||||
|
<p>Updated: {data.timestamp.split(' ')[1]}</p>
|
||||||
|
|
||||||
|
<p>Individual panels:</p>
|
||||||
|
|
||||||
|
<div className='panels'>
|
||||||
|
{Object.values(data.inverters).map((x, i) =>
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className='panel'
|
||||||
|
style={{ backgroundColor: `hsl(21, 100%, ${x.power[0]/315*50}%)` }}
|
||||||
|
>
|
||||||
|
<div className='panel-label'>
|
||||||
|
{x.power[0]}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{i != 2 &&
|
||||||
|
<div
|
||||||
|
className='panel'
|
||||||
|
style={{ backgroundColor: `hsl(21, 100%, ${x.power[1]/315*50}%)` }}
|
||||||
|
>
|
||||||
|
<div className='panel-label'>
|
||||||
|
{x.power[1]}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<div className='stats'>
|
||||||
|
Loading...
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
10
webclient/src/index.js
Normal file
10
webclient/src/index.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>,
|
||||||
|
document.getElementById('root')
|
||||||
|
);
|
11640
webclient/yarn.lock
Normal file
11640
webclient/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user