Skip to content
Snippets Groups Projects
Commit 02f4f525 authored by kevinle350's avatar kevinle350
Browse files

Data Transmission tested, everything pretty much done minus a few bugs,...

Data Transmission tested, everything pretty much done minus a few bugs, styling, and using real data
parent 67bd63a0
No related branches found
No related tags found
No related merge requests found
...@@ -14,57 +14,52 @@ Open [http://localhost:3000](http://localhost:3000) to view it in your browser. ...@@ -14,57 +14,52 @@ Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\ The page will reload when you make changes.\
You may also see any lint errors in the console. You may also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\ ## Data Flow
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build` Frontend -> ESP32
Input from User:
- Plant Name: string
- Minimum Water Level: string
- Watering Hours: string
- Maximum Water Usage: string
Builds the app for production to the `build` folder.\ Output:
It correctly bundles React in production mode and optimizes the build for the best performance. - Plant Name: string
- Minimum Water Level: string
- Watering Hours: string
- Maximum Water Usage: string
The build is minified and the filenames include the hashes.\ ESP32 -> Frontend
Your app is ready to be deployed! Input from Sensors:
- Current Moisture Level: tbd
- Current Water Usage: tbd
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. Output:
- Current Moisture Level: string
- Current Water Usage: string
### `npm run eject` # How things work
All the variables uptop uses useState React hook which initiates the variable and a function that can be called to set the variable data. This is how we store data globally.
**Note: this is a one-way operation. Once you `eject`, you can't go back!** Modal is for user to input the necessary parameters to send to the ESP32.
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. Connecting to ESP32 via Websocket for data transmission
Documentation: https://www.npmjs.com/package/react-use-websocket
- websocket takes in the ESP32 IP address and gives us:
- sendMessage: allows us to send data to the ESP32 from the frontend
- lastMessage: data ESP32 sends frontend
- readyState: status of Websocket connections
- UseEffect React hook to constantly fetch and update the data everytime there is a change in the lastMessage variable. This allows us to do live updating.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. Everything else is self explanitory, it is how the webpage is laid out, nothing super fancy.
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `npm run build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
overflow-x: hidden; overflow-x: hidden;
overflow-y: hidden; overflow-y: hidden;
display: block; display: block;
::-webkit-scrollbar {
display: none;
}
} }
.container { .container {
...@@ -24,7 +26,7 @@ ...@@ -24,7 +26,7 @@
height: 100vh; height: 100vh;
/* background-color: #FCFCFC; */ /* background-color: #FCFCFC; */
overflow-x: hidden; overflow-x: hidden;
overflow-y: hidden; overflow-y: auto;
text-align: center; text-align: center;
} }
......
...@@ -11,11 +11,10 @@ function Landing() { ...@@ -11,11 +11,10 @@ function Landing() {
const [plants,setPlants] = useState([]); const [plants,setPlants] = useState([]);
const [healths, setHealths] = useState([]); // fill this later w actual data const [healths, setHealths] = useState([]); // fill this later w actual data
const [modalIsOpen, setModalIsOpen] = useState(false) const [modalIsOpen, setModalIsOpen] = useState(false)
const [sensorData, setSensorData] = useState(null);
var [dataFromModal, setDataFromModal] = useState({}); var [dataFromModal, setDataFromModal] = useState({});
// station: '192.168.4.1' localWiFi(AP): 172.16.107.184 // station: '192.168.4.1' localWiFi(AP): 172.16.107.184
const ESP32_IP_ADDRESS = '172.16.107.184'; const ESP32_IP_ADDRESS = '192.168.1.8';
const { sendMessage, lastMessage, readyState } = useWebSocket(`ws://${ESP32_IP_ADDRESS}/ws`); const { sendMessage, lastMessage, readyState } = useWebSocket(`ws://${ESP32_IP_ADDRESS}/ws`);
// For Data Transmission testing purposes // For Data Transmission testing purposes
...@@ -49,6 +48,7 @@ function Landing() { ...@@ -49,6 +48,7 @@ function Landing() {
); );
setPlants([...plants, newPlantData]); setPlants([...plants, newPlantData]);
console.log(plants)
setHealths([...healths, newHealth]) setHealths([...healths, newHealth])
}; };
...@@ -63,10 +63,22 @@ function Landing() { ...@@ -63,10 +63,22 @@ function Landing() {
const receiveData = (data) => { const receiveData = (data) => {
setDataFromModal(data); setDataFromModal(data);
} }
// Gonna send plants: [{name, maxWaterUsage, minMoistureLevel, wateringHours}] to ESP32
// hardcoded data on ESP32 for now
const [dataObjects, setDataObjects] = useState([]);
useEffect(() => {
if (lastMessage !== null) {
try {
// Parse the message data as JSON and update the state
const data = JSON.parse(lastMessage.data);
setDataObjects(data);
} catch (e) {
console.error("Failed to parse JSON:", e);
}
}
}, [lastMessage]);
...@@ -121,12 +133,17 @@ function Landing() { ...@@ -121,12 +133,17 @@ function Landing() {
<div className='health-wrap'> <div className='health-wrap'>
<p className='health-header'>Plant Health</p> <p className='health-header'>Plant Health</p>
<div className='health-container'> <div className='health-container'>
{healths.map((health, index) => ( {/* {healths.map((health, index) => (
<div key = {index}>{health}</div> <div key = {index}>{health}</div>
))} */}
{dataObjects.map((item, index) => (
<p key={index}>
Address: {item.address}, Health: {item.health}
</p>
))} ))}
</div> </div>
</div> </div>
...@@ -197,4 +214,40 @@ export default Landing; ...@@ -197,4 +214,40 @@ export default Landing;
// useEffect(() => { // useEffect(() => {
// // Fetch sensor data on component mount // // Fetch sensor data on component mount
// fetchSensorData(); // fetchSensorData();
// }, []); // }, []);
\ No newline at end of file
// sensorDatas: [(curMoistureLvl, curWaterUsage)]
// {sensorDatas.map((sensorData, index) => (
// <div key = {index}>{health}</div>
// <p>{sensorData[0]}, {sensorData[1]}</p>
// ))}
// setSensorDatas(lastMessage.data)
// Important, for parsing Data
//const [dataObjects, setDataObjects] = useState([]);
// useEffect(() => {
// if (lastMessage !== null) {
// try {
// // Parse the message data as JSON and update the state
// const data = JSON.parse(lastMessage.data);
// setDataObjects(data);
// } catch (e) {
// console.error("Failed to parse JSON:", e);
// }
// }
// }, [lastMessage]);
// <div>
// <h1>Data Tuples</h1>
// <ul>
// {dataObjects.map((item, index) => (
// <li key={index}>
// Address: {item.address}, Health: {item.health}
// </li>
// ))}
// </ul>
// </div>
\ No newline at end of file
...@@ -24,7 +24,6 @@ const MyModal = ({ isOpen, closeModal, sendDataToParent }) => { ...@@ -24,7 +24,6 @@ const MyModal = ({ isOpen, closeModal, sendDataToParent }) => {
return ( return (
<Modal isOpen={isOpen} onRequestClose={closeModal} > <Modal isOpen={isOpen} onRequestClose={closeModal} >
<h2>Fill in Information</h2> <h2>Fill in Information</h2>
<button>Configuration</button>
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<label htmlFor="Plant Name">Plant Name:</label> <label htmlFor="Plant Name">Plant Name:</label>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment