diff --git a/app/components/evse.tsx b/app/components/evse.tsx index 0e2c8b5..36ce413 100644 --- a/app/components/evse.tsx +++ b/app/components/evse.tsx @@ -3,7 +3,7 @@ import { SyntheticEvent, useRef, useState } from 'react'; import Input from './input'; import { ConState, IWriter } from '../service/websocket/websocket.model'; -import WebSocket from './WebSocket'; +import WebSocket from './web.socket'; import { ChargingSocket, IChargingSocket } from '../service/ocpp/connector'; import { HandleOcpp } from '../service/ocpp/ocpp.handler'; import { SendBootNotification } from '../service/ocpp/command/boot-notification/boot.notification'; @@ -14,6 +14,7 @@ import { } from '../service/ocpp/command/status-notification/status.notification'; import { SendStatusNotification } from '../service/ocpp/command/status-notification/statusnotification'; import Transaction from './transaction'; +import MeterValue from './meter.value'; const defaultValue = 'ws://localhost:8080/ocpp/JwNpTpPxPm/CHR202305102'; const connectorId = 1; @@ -74,10 +75,12 @@ export default function Evse() { onMessage={onMessage} online={online} /> - + {online ? ( + + ) : null}
@@ -88,6 +91,15 @@ export default function Evse() { changeState={changeState} />
+ {socket[0].State == StatusNotification.CHARGING ? ( +
+ +
+ ) : null} ); } diff --git a/app/components/meter.value.tsx b/app/components/meter.value.tsx new file mode 100644 index 0000000..3aa8c30 --- /dev/null +++ b/app/components/meter.value.tsx @@ -0,0 +1,59 @@ +import React, { useEffect, useState } from 'react'; +import Select, { ReturnValue } from './select'; +import { meterValueList } from './transaction'; +import { StatusNotification } from '../service/ocpp/command/status-notification/status.notification'; +import Button from './button'; +import { SendMeterValue } from '../service/ocpp/command/meter-value/meter.value'; +import { IWriter } from '../service/websocket/websocket.model'; + +const DEFAULT_INTERVAL = 20000; + +type meterValue = { + w: IWriter; + connectorId: number; + state: StatusNotification; +}; + +export default function MeterValue({ + w, + connectorId, + state, +}: meterValue): React.JSX.Element { + const [meter, setMeter] = useState>([250]); + const meterValue = { name: meter.toString(), value: meter[0] }; + + const onSelectChange = (item: ReturnValue) => { + meter[0] = item as number; + setMeter([...meter]); + }; + + const onClick = () => { + SendMeterValue(w, connectorId, meter[0]); + }; + + useEffect(() => { + console.info('start interval'); + const id = setInterval(onClick, DEFAULT_INTERVAL - 19000); + return () => { + console.info('clean up interval'); + clearInterval(id); + }; + }, []); + + return ( +
+

Meter value

+

Notes: Meter Values are sent every 20 seconds

+ -
+