Add Smart Lights to SmartHome

This commit is contained in:
Ceda EI 2021-01-05 22:28:57 +05:30
parent 6e07c2be85
commit fe9f7e81e9
2 changed files with 17 additions and 3 deletions

View File

@ -1,8 +1,9 @@
import React, {useState, useEffect} from "react";
import PropTypes from "prop-types";
import { Box, Button } from "grommet";
import axios from "axios";
import { CAMERA_URL } from "../config";
import { CAMERA_URL, LIGHTS_URL } from "../config";
function SmartHome(props) {
const [ idx, setIdx ] = useState(0);
@ -10,6 +11,12 @@ function SmartHome(props) {
const id = setInterval(() => setIdx(i => i + 1), 20);
return () => clearInterval(id);
}, []);
function turnOn() {
axios.get(`${LIGHTS_URL}/on`);
}
function turnOff() {
axios.get(`${LIGHTS_URL}/off`);
}
return (
<Box
align="center"
@ -21,8 +28,14 @@ function SmartHome(props) {
height="95vh"
>
<img src={`${CAMERA_URL}?id=${idx}`} />
<Box direction="row" margin="1em 0">
<Button primary size="large" onClick={turnOn}
label="Turn On Lights" margin="0 0 0 0" />
<Button primary size="large" onClick={turnOff}
label="Turn Off Lights" margin="0 0 0 1em" />
</Box>
<Button primary size="large" onClick={props.close}
label="Dismiss" margin="1.5em" />
label="Dismiss" margin="0" />
</Box>
);
}

View File

@ -4,5 +4,6 @@ const TG_USERID = 123456789;
const CAR_API = "http://localhost:5000/";
const CAMERA_URL = "http://path.to/still/image.jpg";
const MAPS_API = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const LIGHTS_URL = "http://192.168.1.50:5000/";
export { WS_BASE, TG_API, TG_USERID, CAR_API, CAMERA_URL, MAPS_API };
export { WS_BASE, TG_API, TG_USERID, CAR_API, CAMERA_URL, MAPS_API, LIGHTS_URL };