From 552686fc3b6b2ddd0b2bab078553846a2c28da60 Mon Sep 17 00:00:00 2001 From: Niko Hakala Date: Thu, 21 Nov 2019 11:36:20 +0200 Subject: [PATCH] Minor changes and possibly useless components --- README.md | 4 ++-- public/tinyforest.log.json | 12 ++++++++++++ src/Components/LogParser.js | 29 +++++++++++++++++++++++++++++ src/Components/Plants.js | 2 ++ src/Components/Sysinfo.js | 11 +++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 public/tinyforest.log.json create mode 100644 src/Components/LogParser.js diff --git a/README.md b/README.md index cc98775..1b8af48 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## TODO -Plant page layout, what goes where and what info do we actually need in the frontend.
-How to pull sysinfo, Only usefull info core temp etc.
+Sysinfo layout
+
## React stuff diff --git a/public/tinyforest.log.json b/public/tinyforest.log.json new file mode 100644 index 0000000..ffaac5e --- /dev/null +++ b/public/tinyforest.log.json @@ -0,0 +1,12 @@ +{ +"0" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 22 }, "loglevel": "INFO", "host": "alarmpi", "file": "system.py", "func": "init_file", "msg": {"info": "file created", "file": "/var/log/tinyforest/tinyforest.log.json"} }, +"1" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 22 }, "loglevel": "INFO", "host": "alarmpi", "file": "system.py", "func": "init_file", "msg": {"info": "file opened", "file": "/var/log/tinyforest/tinyforest.log.json"} }, +"2" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 23 }, "loglevel": "INFO", "host": "alarmpi", "file": "jsonreader.py", "func": "__init__", "msg": {"json_common": {"target": "/etc/tinyforest/json/profile_plant1_v01.json", "name": "Moisture sensor (1)", "description": "Moisture sensor (1): loaded JSON configuration"}} }, +"3" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 23 }, "loglevel": "DEBUG", "host": "alarmpi", "file": "jsonreader.py", "func": "__init__", "msg": {"json_common": {"target": "/etc/tinyforest/json/profile_plant1_v01.json", "name": "Moisture sensor (1)", "description": "Moisture sensor (1): {'enabled': True, 'sensor_type': 'common', 'gpio_pin': 24, 'gpio_pin_initialstate': 'LOW', 'gpio_pin_upstate': 'HIGH', 'sensor_friendly_name': 'Moisture sensor (1)', 'trigger_data_type': 'dummy_on_off', 'trigger_min': 1.0, 'trigger_max': 0.0, 'time': {'use_time': True, 'months': {'1': True, '2': True, '3': True, '4': True, '5': True, '6': True, '7': True, '8': True, '9': True, '10': True, '11': True, '12': True}, 'weeks': {'1': True, '2': True, '3': True, '4': True}, 'days': {'mon': {'enabled': True, 'interval': ['12.00', '18.00']}, 'tue': {'enabled': True, 'interval': ['8.00', '16.00']}, 'wed': {'enabled': True, 'interval': ['13.00', '20.00']}, 'thu': {'enabled': True, 'interval': ['4.00', '12.00']}, 'fri': {'enabled': True, 'interval': ['12.00', '18.00']}, 'sat': {'enabled': True, 'interval': ['6.00', '14.00']}, 'sun': {'enabled': True, 'interval': ['15.00', '23.59']}}}, 'devices_out': {'common': {'use_devices_out': True, 'check_interval': 0.25, 'keepalivetime_max': 5.0}, 'devices_out_spec': [{'enabled': True, 'gpio_pin': 14, 'gpio_pin_initialstate': 'LOW', 'gpio_pin_upstate': 'HIGH', 'operation_type': 'irrigation', 'name': 'pump_1', 'friendly_name': 'Water pump (1)'}, {'enabled': False, 'gpio_pin': 15, 'gpio_pin_initialstate': 'LOW', 'gpio_pin_upstate': 'HIGH', 'operation_type': 'irrigation', 'name': 'pump_2', 'friendly_name': 'Water pump (2)'}]}}"}} }, +"4" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 23 }, "loglevel": "WARNING", "host": "alarmpi", "file": "jsonreader.py", "func": "check_devices_out", "msg": {"json_common": {"target": "/etc/tinyforest/json/profile_plant1_v01.json", "name": "Light sensor (1)", "description": "Light sensor (1): output device UV lamp (1) disabled"}} }, +"5" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 23 }, "loglevel": "WARNING", "host": "alarmpi", "file": "jsonreader.py", "func": "__init__", "msg": {"json_common": {"target": "/etc/tinyforest/json/profile_plant1_v01.json", "name": "light", "description": "light: disabled"}} }, +"6" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 23 }, "loglevel": "WARNING", "host": "alarmpi", "file": "jsonreader.py", "func": "__init__", "msg": {"json_common": {"target": "/etc/tinyforest/json/profile_plant1_v01.json", "name": "temperature", "description": "temperature: disabled"}} }, +"7" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 23 }, "loglevel": "WARNING", "host": "alarmpi", "file": "jsonreader.py", "func": "check_devices_out", "msg": {"json_common": {"target": "/etc/tinyforest/json/profile_plant1_v01.json", "name": "pH sensor (1)", "description": "pH sensor (1): output device Fertilizer pump (1) disabled"}} }, +"8" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 23 }, "loglevel": "WARNING", "host": "alarmpi", "file": "jsonreader.py", "func": "__init__", "msg": {"json_common": {"target": "/etc/tinyforest/json/profile_plant1_v01.json", "name": "acidity", "description": "acidity: disabled"}} }, +"9" :{ "time": { "day": 30, "month": 10, "year": 2019, "hour": 11, "minute": 3, "second": 23 }, "loglevel": "INFO", "host": "alarmpi", "file": "jsonreader.py", "func": "__init__", "msg": {"json_common": {"target": "/etc/tinyforest/json/profile_plant1_v01.json", "name": "Moisture sensor (1)", "description": "Moisture sensor (1): started sensor process"}} } +} \ No newline at end of file diff --git a/src/Components/LogParser.js b/src/Components/LogParser.js new file mode 100644 index 0000000..4f7a746 --- /dev/null +++ b/src/Components/LogParser.js @@ -0,0 +1,29 @@ +import React, { useState, useEffect } from 'react'; + +const LogParser = () => { + + const [logs, setLogs] = useState([]); + + + useEffect(() => { + fetchLogs(); + }, []) + + + const fetchLogs = () => { + fetch('../tinyforest.log.json') + .then((res) => res.json()) + .then(data => setLogs(data)) + .catch(err => console.error(err)) + } + + console.log(log) + + return ( +
+ +
+ ); +}; + +export default LogParser; \ No newline at end of file diff --git a/src/Components/Plants.js b/src/Components/Plants.js index 276f301..c310372 100644 --- a/src/Components/Plants.js +++ b/src/Components/Plants.js @@ -20,6 +20,8 @@ const Plants = () => { .catch(err => console.error(err)) } + + //console.log(plant.imagefile) return ( diff --git a/src/Components/Sysinfo.js b/src/Components/Sysinfo.js index fb43495..78155f1 100644 --- a/src/Components/Sysinfo.js +++ b/src/Components/Sysinfo.js @@ -5,11 +5,13 @@ const Sysinfo = () => { const [moisture, setMoisture] = useState([]); const [light, setLight] = useState([]); const [temperature, setTemperature] = useState([]); + const [logs, setLogs] = useState([]); useEffect(() => { fetchMoisture(); fetchLight(); fetchTemperature(); + fetchLogs(); }, []) const fetchMoisture = () => { @@ -33,6 +35,15 @@ const Sysinfo = () => { .catch(err => console.error(err)) } + const fetchLogs = () => { + fetch('../tinyforest.log.json') + .then((res) => res.json()) + .then(data => setLogs(data)) + .catch(err => console.error(err)) + } + + + console.log(logs) console.log(moisture.sensor_friendly_name) console.log(light.sensor_friendly_name) console.log(temperature.sensor_friendly_name)