From 5c88e8fa3c973f93c748014bf7b32918c2e0171a Mon Sep 17 00:00:00 2001 From: Julian Cuni Date: Sat, 11 Jul 2026 18:57:55 +0200 Subject: [PATCH] feat(discovering): single-process CSMS on :9000 with discovery API + live session captures station.py is now one FastAPI/uvicorn process owning port 9000: the OCPP 1.6J WebSocket (catch-all path) plus an HTTP control API (status, events, tags, probe, remote start/stop, trigger, unlock, setconfig). Adds the events.jsonl journal and auto-interrogation on connect. Includes the captures from the 2026-07-09 live test session: full GetConfiguration dump of eu092025, real charging transactions on both guns (RFID + remote start/stop), and the negative Autocharge/MacEnabled results. Cards A/B + app-remote enrolled in station_config.json. --- discovering/discovery_TESTCP.json | 31 +++ discovering/discovery_eu092025.json | 336 ++++++++++++++++++++++++++++ discovering/events.jsonl | 61 +++++ discovering/requirements.txt | 2 + discovering/seen_tags.json | 35 +++ discovering/station.py | 260 +++++++++++++++++++-- discovering/station_config.json | 15 +- 7 files changed, 720 insertions(+), 20 deletions(-) create mode 100644 discovering/discovery_TESTCP.json create mode 100644 discovering/discovery_eu092025.json create mode 100644 discovering/events.jsonl create mode 100644 discovering/seen_tags.json diff --git a/discovering/discovery_TESTCP.json b/discovering/discovery_TESTCP.json new file mode 100644 index 0000000..34bd3fa --- /dev/null +++ b/discovering/discovery_TESTCP.json @@ -0,0 +1,31 @@ +{ + "charge_point": "TESTCP", + "probed_at": "2026-07-09T14:50:00.315598+00:00", + "boot_info": { + "vendor": "FakeVendor", + "model": "FakeModel-7kW", + "firmware_version": "0.0.1" + }, + "configuration": [ + { + "key": "NumberOfConnectors", + "readonly": true, + "value": "1" + }, + { + "key": "SupportedFeatureProfiles", + "readonly": true, + "value": "Core,RemoteTrigger,LocalAuthListManagement" + }, + { + "key": "MeterValueSampleInterval", + "readonly": false, + "value": "60" + } + ], + "unknown_keys": [], + "trigger_status_notification": "Accepted", + "connectors_seen": { + "1": "Available" + } +} \ No newline at end of file diff --git a/discovering/discovery_eu092025.json b/discovering/discovery_eu092025.json new file mode 100644 index 0000000..218d985 --- /dev/null +++ b/discovering/discovery_eu092025.json @@ -0,0 +1,336 @@ +{ + "charge_point": "eu092025", + "probed_at": "2026-07-09T15:33:50.788871+00:00", + "boot_info": { + "vendor": "SimpleCharge", + "model": "MultiSocketCharger", + "charge_point_serial_number": "24310588", + "firmware_version": "1.24.0620.1", + "iccid": "", + "imsi": "" + }, + "configuration": [ + { + "key": "AllowOfflineTxForUnknownId", + "readonly": false, + "value": "false" + }, + { + "key": "AuthorizationCacheEnabled", + "readonly": false, + "value": "true" + }, + { + "key": "AuthorizeRemoteTxRequests", + "readonly": false, + "value": "false" + }, + { + "key": "ClockAlignedDataInterval", + "readonly": false, + "value": "0" + }, + { + "key": "ConnectorPhaseRotationMaxLength", + "readonly": true, + "value": "1" + }, + { + "key": "ConnectionTimeOut", + "readonly": false, + "value": "60" + }, + { + "key": "GetConfigurationMaxKeys", + "readonly": true, + "value": "30" + }, + { + "key": "HeartbeatInterval", + "readonly": false, + "value": "7200" + }, + { + "key": "LocalAuthorizeOffline", + "readonly": false, + "value": "false" + }, + { + "key": "LocalPreAuthorize", + "readonly": false, + "value": "0" + }, + { + "key": "MaxEnergyOnInvalidId", + "readonly": false, + "value": "0" + }, + { + "key": "MeterValueSampleInterval", + "readonly": false, + "value": "60" + }, + { + "key": "NumberOfConnectors", + "readonly": true, + "value": "2" + }, + { + "key": "ResetRetries", + "readonly": false, + "value": "0" + }, + { + "key": "StopTransactionOnEVSideDisconnect", + "readonly": false, + "value": "1" + }, + { + "key": "StopTransactionOnInvalidId", + "readonly": false, + "value": "1" + }, + { + "key": "TransactionMessageAttempts", + "readonly": false, + "value": "50" + }, + { + "key": "TransactionMessageRetryInterval", + "readonly": false, + "value": "60" + }, + { + "key": "WebSocketPingInterval", + "readonly": false, + "value": "60" + }, + { + "key": "LocalAuthListEnabled", + "readonly": false, + "value": "false" + }, + { + "key": "LocalAuthListMaxLength", + "readonly": true, + "value": "6" + }, + { + "key": "SendLocalListMaxLength", + "readonly": true, + "value": "6" + }, + { + "key": "ChargeProfileMaxStackLevel", + "readonly": true, + "value": "3" + }, + { + "key": "UnlockConnectorOnEVSideDisconnect", + "readonly": false, + "value": "1" + }, + { + "key": "SendJCMeterValuesType", + "readonly": true, + "value": "1" + }, + { + "key": "ChargingScheduleAllowedChargingRateUnit", + "readonly": true, + "value": "Power" + }, + { + "key": "ChargingScheduleMaxPeriods", + "readonly": true, + "value": "3" + }, + { + "key": "MaxChargingProfilesInstalled", + "readonly": true, + "value": "1" + }, + { + "key": "LocalListVersion", + "readonly": true, + "value": "-1" + }, + { + "key": "MeterValuesAlignedData", + "readonly": false, + "value": "Energy.Active.Import.Register,Power.Active.Import,SoC,Voltage,Current.Import" + }, + { + "key": "MeterValuesSampledData", + "readonly": false, + "value": "Energy.Active.Import.Register,Power.Active.Import,SoC,Voltage,Current.Import" + }, + { + "key": "StopTxnAlignedData", + "readonly": false, + "value": "SoC" + }, + { + "key": "StopTxnSampledData", + "readonly": false, + "value": "Energy.Active.Import.Register" + }, + { + "key": "ConnectorPhaseRotation", + "readonly": false, + "value": "RST" + }, + { + "key": "SupportedFeatureProfiles", + "readonly": true, + "value": "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" + }, + { + "key": "Url", + "readonly": false, + "value": "http://10.0.10.203:9000" + }, + { + "key": "Vendor", + "readonly": true, + "value": "JC" + }, + { + "key": "Model", + "readonly": true, + "value": "MultiSocketCharger" + }, + { + "key": "TimeZone", + "readonly": false, + "value": "0" + }, + { + "key": "ProtocolName", + "readonly": true, + "value": "ocpp1.6" + }, + { + "key": "QRCodeTextOfConnector-1", + "readonly": false, + "value": "" + }, + { + "key": "QRCodeTextOfConnector-2", + "readonly": false, + "value": "" + }, + { + "key": "QRCodeTextOfConnector-3", + "readonly": false, + "value": "" + }, + { + "key": "AuthorizationKey", + "readonly": false, + "value": "" + }, + { + "key": "AuthorizationUser", + "readonly": true, + "value": "" + }, + { + "key": "CpoName", + "readonly": false, + "value": "" + }, + { + "key": "OutputLimitRate", + "readonly": false, + "value": "100" + }, + { + "key": "PeakPrice", + "readonly": false, + "value": "1.0000" + }, + { + "key": "OffPeakPrice", + "readonly": false, + "value": "0.5000" + }, + { + "key": "IdleFeePerMinute", + "readonly": false, + "value": "0.0100" + }, + { + "key": "IdleTime", + "readonly": false, + "value": "5" + }, + { + "key": "MacEnabled", + "readonly": false, + "value": "true" + }, + { + "key": "FreeChargeMode", + "readonly": false, + "value": "false" + }, + { + "key": "KeepConnectOTAServer", + "readonly": false, + "value": "true" + }, + { + "key": "DataTransferVendorId", + "readonly": false, + "value": "" + }, + { + "key": "MeterValuesAlignedDataMaxLength", + "readonly": true, + "value": "5" + }, + { + "key": "MeterValuesSampledDataMaxLength", + "readonly": true, + "value": "5" + }, + { + "key": "StopTxnAlignedDataMaxLength", + "readonly": true, + "value": "5" + }, + { + "key": "StopTxnSampledDataMaxLength", + "readonly": true, + "value": "5" + }, + { + "key": "SupportedFeatureProfilesMaxLength", + "readonly": true, + "value": "6" + }, + { + "key": "ReserveConnectorZeroSupported", + "readonly": true, + "value": "false" + }, + { + "key": "ConnectorSwitch3to1PhaseSupported", + "readonly": true, + "value": "false" + }, + { + "key": "ChargePointID", + "readonly": false, + "value": "eu092025" + } + ], + "unknown_keys": null, + "trigger_status_notification": "Accepted", + "connectors_seen": { + "0": "Available", + "1": "Preparing", + "2": "Available" + } +} \ No newline at end of file diff --git a/discovering/events.jsonl b/discovering/events.jsonl new file mode 100644 index 0000000..29207b2 --- /dev/null +++ b/discovering/events.jsonl @@ -0,0 +1,61 @@ +{"time": "2026-07-09T14:49:55.301899+00:00", "event": "connected", "cp": "TESTCP", "client": "Address(host='127.0.0.1', port=52661)", "subprotocols": ["ocpp1.6"]} +{"time": "2026-07-09T14:49:55.311317+00:00", "event": "BootNotification", "cp": "TESTCP", "vendor": "FakeVendor", "model": "FakeModel-7kW", "firmware_version": "0.0.1"} +{"time": "2026-07-09T14:49:55.318486+00:00", "event": "Authorize", "cp": "TESTCP", "id_tag": "CARD-TEST-123", "result": "Accepted"} +{"time": "2026-07-09T14:50:00.334616+00:00", "event": "StatusNotification", "cp": "TESTCP", "connector": 1, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T14:50:03.389613+00:00", "event": "connected", "cp": "eu092025", "client": "Address(host='10.0.10.152', port=44810)", "subprotocols": ["ocpp1.6"]} +{"time": "2026-07-09T14:50:08.719261+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 0, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T14:50:08.926940+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T14:50:09.132883+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T14:50:15.331029+00:00", "event": "disconnected", "cp": "TESTCP"} +{"time": "2026-07-09T14:54:16.567013+00:00", "event": "connected", "cp": "eu092025", "client": "Address(host='10.0.10.152', port=43000)", "subprotocols": ["ocpp1.6"]} +{"time": "2026-07-09T14:54:21.741178+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 0, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T14:54:21.903108+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T14:54:22.109657+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T15:02:59.819374+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Preparing", "error": "NoError"} +{"time": "2026-07-09T15:07:19.906156+00:00", "event": "Authorize", "cp": "eu092025", "id_tag": "1000000000000393", "result": "Accepted"} +{"time": "2026-07-09T15:07:20.139915+00:00", "event": "StartTransaction", "cp": "eu092025", "connector": 2, "id_tag": "1000000000000393", "meter_start": 3513857, "result": "Accepted", "tx": 1} +{"time": "2026-07-09T15:07:20.323299+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Charging", "error": "NoError"} +{"time": "2026-07-09T15:07:20.906172+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:07:19.445Z", "sampled_value": [{"value": "0.0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3513857", "context": "Transaction.Begin", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "0", "context": "Transaction.Begin", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "0.0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 1} +{"time": "2026-07-09T15:07:43.370964+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Preparing", "error": "NoError"} +{"time": "2026-07-09T15:08:21.093068+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:08:20.617277826Z", "sampled_value": [{"value": "98.8", "context": "Sample.Periodic", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3514087", "context": "Sample.Periodic", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "30580", "context": "Sample.Periodic", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "61", "context": "Sample.Periodic", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "309.6", "context": "Sample.Periodic", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 1} +{"time": "2026-07-09T15:08:58.365193+00:00", "event": "StartTransaction", "cp": "eu092025", "connector": 1, "id_tag": "app-remote", "meter_start": 405382, "result": "Accepted", "tx": 2} +{"time": "2026-07-09T15:08:58.668936+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Charging", "error": "NoError"} +{"time": "2026-07-09T15:08:59.044085+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 1, "values": [{"timestamp": "2026-07-09T15:08:57.720Z", "sampled_value": [{"value": "0.0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "405382", "context": "Transaction.Begin", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "0", "context": "Transaction.Begin", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "0.0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 2} +{"time": "2026-07-09T15:09:21.178130+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:09:20.728656493Z", "sampled_value": [{"value": "98.6", "context": "Sample.Periodic", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3514622", "context": "Sample.Periodic", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "30660", "context": "Sample.Periodic", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "62", "context": "Sample.Periodic", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "311.0", "context": "Sample.Periodic", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 1} +{"time": "2026-07-09T15:09:59.338172+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 1, "values": [{"timestamp": "2026-07-09T15:09:58.900267471Z", "sampled_value": [{"value": "0.0", "context": "Sample.Periodic", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "405382", "context": "Sample.Periodic", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "0", "context": "Sample.Periodic", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "64", "context": "Sample.Periodic", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "0.0", "context": "Sample.Periodic", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 2} +{"time": "2026-07-09T15:10:09.353518+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Finishing", "error": "NoError"} +{"time": "2026-07-09T15:10:10.392443+00:00", "event": "StopTransaction", "cp": "eu092025", "tx": 2, "meter_stop": 405731, "delivered_wh": 349, "id_tag": "app-remote", "reason": "Remote", "transaction_data": [{"timestamp": "2026-07-09T15:10:08.231Z", "sampled_value": [{"value": "405731", "context": "Transaction.End", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}]}]} +{"time": "2026-07-09T15:10:10.655340+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 1, "values": [{"timestamp": "2026-07-09T15:10:08.231Z", "sampled_value": [{"value": "0.0", "context": "Transaction.End", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "405731", "context": "Transaction.End", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "0", "context": "Transaction.End", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "64", "context": "Transaction.End", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "0.0", "context": "Transaction.End", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 2} +{"time": "2026-07-09T15:10:21.181272+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:10:20.751714927Z", "sampled_value": [{"value": "98.4", "context": "Sample.Periodic", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3515115", "context": "Sample.Periodic", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "30680", "context": "Sample.Periodic", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "63", "context": "Sample.Periodic", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "311.8", "context": "Sample.Periodic", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 1} +{"time": "2026-07-09T15:11:21.161004+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:11:20.752496181Z", "sampled_value": [{"value": "98.3", "context": "Sample.Periodic", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3515617", "context": "Sample.Periodic", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "30640", "context": "Sample.Periodic", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "65", "context": "Sample.Periodic", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "311.8", "context": "Sample.Periodic", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 1} +{"time": "2026-07-09T15:11:26.454939+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Finishing", "error": "NoError"} +{"time": "2026-07-09T15:11:27.967000+00:00", "event": "StopTransaction", "cp": "eu092025", "tx": 1, "meter_stop": 3515664, "delivered_wh": 1807, "id_tag": "1000000000000393", "reason": "Remote", "transaction_data": [{"timestamp": "2026-07-09T15:11:26.858Z", "sampled_value": [{"value": "3515664", "context": "Transaction.End", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}]}]} +{"time": "2026-07-09T15:11:28.173805+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:11:26.858Z", "sampled_value": [{"value": "0.0", "context": "Transaction.End", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3515664", "context": "Transaction.End", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "0", "context": "Transaction.End", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "65", "context": "Transaction.End", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "0.0", "context": "Transaction.End", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 1} +{"time": "2026-07-09T15:12:06.504623+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T15:12:11.528746+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Preparing", "error": "NoError"} +{"time": "2026-07-09T15:12:31.966934+00:00", "event": "Authorize", "cp": "eu092025", "id_tag": "1000000000000393", "result": "Accepted"} +{"time": "2026-07-09T15:12:32.272632+00:00", "event": "StartTransaction", "cp": "eu092025", "connector": 2, "id_tag": "1000000000000393", "meter_start": 3515664, "result": "Accepted", "tx": 3} +{"time": "2026-07-09T15:12:32.450600+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Charging", "error": "NoError"} +{"time": "2026-07-09T15:12:33.053501+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:12:31.679Z", "sampled_value": [{"value": "0.0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3515664", "context": "Transaction.Begin", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "0", "context": "Transaction.Begin", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "0.0", "context": "Transaction.Begin", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 3} +{"time": "2026-07-09T15:13:33.234090+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:13:32.875985191Z", "sampled_value": [{"value": "129.3", "context": "Sample.Periodic", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3516035", "context": "Sample.Periodic", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "40690", "context": "Sample.Periodic", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "65", "context": "Sample.Periodic", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "314.7", "context": "Sample.Periodic", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 3} +{"time": "2026-07-09T15:13:56.469910+00:00", "event": "Authorize", "cp": "eu092025", "id_tag": "1000000000000395", "result": "Accepted"} +{"time": "2026-07-09T15:14:33.303145+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:14:32.970773241Z", "sampled_value": [{"value": "121.2", "context": "Sample.Periodic", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3516671", "context": "Sample.Periodic", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "38050", "context": "Sample.Periodic", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "67", "context": "Sample.Periodic", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "314.0", "context": "Sample.Periodic", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 3} +{"time": "2026-07-09T15:14:38.019887+00:00", "event": "Authorize", "cp": "eu092025", "id_tag": "1000000000000395", "result": "Accepted"} +{"time": "2026-07-09T15:15:33.369007+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:15:33.061647792Z", "sampled_value": [{"value": "121.2", "context": "Sample.Periodic", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3517340", "context": "Sample.Periodic", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "38050", "context": "Sample.Periodic", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "68", "context": "Sample.Periodic", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "314.0", "context": "Sample.Periodic", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 3} +{"time": "2026-07-09T15:16:31.502080+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Finishing", "error": "NoError"} +{"time": "2026-07-09T15:16:32.612265+00:00", "event": "StopTransaction", "cp": "eu092025", "tx": 3, "meter_stop": 3517928, "delivered_wh": 2264, "id_tag": "1000000000000393", "reason": "Remote", "transaction_data": [{"timestamp": "2026-07-09T15:16:31.628Z", "sampled_value": [{"value": "3517928", "context": "Transaction.End", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}]}]} +{"time": "2026-07-09T15:16:32.739682+00:00", "event": "MeterValues", "cp": "eu092025", "connector": 2, "values": [{"timestamp": "2026-07-09T15:16:31.628Z", "sampled_value": [{"value": "0.0", "context": "Transaction.End", "format": "Raw", "measurand": "Current.Import", "location": "Outlet", "unit": "A"}, {"value": "3517928", "context": "Transaction.End", "format": "Raw", "measurand": "Energy.Active.Import.Register", "location": "Outlet", "unit": "Wh"}, {"value": "0", "context": "Transaction.End", "format": "Raw", "measurand": "Power.Active.Import", "location": "Outlet", "unit": "W"}, {"value": "69", "context": "Transaction.End", "format": "Raw", "measurand": "SoC", "location": "Outlet", "unit": "Percent"}, {"value": "0.0", "context": "Transaction.End", "format": "Raw", "measurand": "Voltage", "location": "Outlet", "unit": "V"}]}], "transaction_id": 3} +{"time": "2026-07-09T15:16:37.120878+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T15:22:11.084171+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T15:22:14.593031+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Preparing", "error": "NoError"} +{"time": "2026-07-09T15:32:56.678733+00:00", "event": "disconnected", "cp": "eu092025"} +{"time": "2026-07-09T15:33:45.785808+00:00", "event": "connected", "cp": "eu092025", "client": "Address(host='10.0.10.152', port=33650)", "subprotocols": ["ocpp1.6"]} +{"time": "2026-07-09T15:33:46.288738+00:00", "event": "BootNotification", "cp": "eu092025", "vendor": "SimpleCharge", "model": "MultiSocketCharger", "charge_point_serial_number": "24310588", "firmware_version": "1.24.0620.1", "iccid": "", "imsi": ""} +{"time": "2026-07-09T15:33:47.696131+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 0, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T15:33:49.711246+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T15:33:49.921913+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T15:33:51.124034+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Preparing", "error": "NoError"} +{"time": "2026-07-09T15:33:51.234093+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 0, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T15:33:51.443211+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 2, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T16:56:22.781138+00:00", "event": "StatusNotification", "cp": "eu092025", "connector": 1, "status": "Available", "error": "NoError"} +{"time": "2026-07-09T17:45:22.815009+00:00", "event": "disconnected", "cp": "eu092025"} diff --git a/discovering/requirements.txt b/discovering/requirements.txt index 42fc470..9c0f798 100644 --- a/discovering/requirements.txt +++ b/discovering/requirements.txt @@ -1,4 +1,6 @@ attrs==26.1.0 +fastapi==0.139.0 +uvicorn==0.51.0 jsonschema==4.26.0 jsonschema-specifications==2025.9.1 ocpp==2.1.0 diff --git a/discovering/seen_tags.json b/discovering/seen_tags.json new file mode 100644 index 0000000..dd80725 --- /dev/null +++ b/discovering/seen_tags.json @@ -0,0 +1,35 @@ +{ + "CARD-TEST-123": { + "count": 2, + "first_seen": "2026-07-09T13:48:25.276914+00:00", + "contexts": [ + "Authorize (card/app/autocharge)" + ], + "last_seen": "2026-07-09T14:49:55.317640+00:00" + }, + "1000000000000393": { + "count": 4, + "first_seen": "2026-07-09T15:07:19.905448+00:00", + "contexts": [ + "Authorize (card/app/autocharge)", + "StartTransaction (connector 2)" + ], + "last_seen": "2026-07-09T15:12:32.270138+00:00" + }, + "app-remote": { + "count": 1, + "first_seen": "2026-07-09T15:08:58.363084+00:00", + "contexts": [ + "StartTransaction (connector 1)" + ], + "last_seen": "2026-07-09T15:08:58.363112+00:00" + }, + "1000000000000395": { + "count": 2, + "first_seen": "2026-07-09T15:13:56.468848+00:00", + "contexts": [ + "Authorize (card/app/autocharge)" + ], + "last_seen": "2026-07-09T15:14:38.018675+00:00" + } +} \ No newline at end of file diff --git a/discovering/station.py b/discovering/station.py index b550203..6b8385f 100644 --- a/discovering/station.py +++ b/discovering/station.py @@ -19,6 +19,18 @@ Workflow: 3. Move the ones you want into "authorized" in station_config.json, name them. 4. Set "learn_mode": false and restart -> only your ids are accepted. +Discovery API (same port 9000 the charger dials — http://:9000, docs at /docs): + GET /status connected chargers, guns, transactions, auth events + GET /events?limit=100&event=X tail the permanent event journal (events.jsonl) + GET /tags seen + authorized idTags + POST /probe GetConfiguration + trigger StatusNotification, + saved to discovery_.json (also auto-runs on connect) + POST /start?id_tag=X&connector=1 RemoteStartTransaction + POST /stop/{tx} or POST /stop RemoteStopTransaction (no tx = the only active one) + POST /trigger/{status|meter|heartbeat|boot}?connector=N + POST /unlock/{connector} UnlockConnector + POST /setconfig?key=K&value=V ChangeConfiguration (e.g. MeterValueSampleInterval) + Run: venv/Scripts/python station.py """ @@ -28,8 +40,10 @@ import logging from collections import deque from datetime import datetime, timezone from pathlib import Path +from typing import Optional -import websockets +import uvicorn +from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect from ocpp.routing import on from ocpp.v16 import ChargePoint as OcppChargePoint @@ -38,12 +52,14 @@ from ocpp.v16.enums import ( Action, AuthorizationStatus, DataTransferStatus, + MessageTrigger, RegistrationStatus, ) HERE = Path(__file__).resolve().parent CONFIG_PATH = HERE / "station_config.json" SEEN_PATH = HERE / "seen_tags.json" +EVENTS_PATH = HERE / "events.jsonl" logging.basicConfig( level=logging.INFO, @@ -79,6 +95,17 @@ def load_config() -> dict: CONFIG = load_config() +def record_event(event: str, cp_id: str, **data) -> None: + """Append one JSON line to events.jsonl — the permanent journal of everything + the charger tells us (and what we told it). Survives restarts; grep/ingest later.""" + entry = {"time": now(), "event": event, "cp": cp_id, **data} + try: + with EVENTS_PATH.open("a", encoding="utf-8") as f: + f.write(json.dumps(entry, ensure_ascii=False, default=str) + "\n") + except Exception: + log.exception("failed to journal event %r", event) + + def record_seen(id_tag: str, context: str) -> None: """Append/refresh an entry in seen_tags.json so you can harvest ids later.""" try: @@ -123,6 +150,8 @@ def decide(id_tag: str, context: str) -> AuthorizationStatus: class ChargePoint(OcppChargePoint): @on(Action.boot_notification) async def on_boot_notification(self, charge_point_vendor, charge_point_model, **kwargs): + self.boot_info = {"vendor": charge_point_vendor, "model": charge_point_model, **kwargs} + record_event("BootNotification", self.id, **self.boot_info) log.info("BootNotification: vendor=%r model=%r extra=%r", charge_point_vendor, charge_point_model, kwargs) return call_result.BootNotification( @@ -136,6 +165,8 @@ class ChargePoint(OcppChargePoint): @on(Action.status_notification) async def on_status_notification(self, connector_id, error_code, status, **kwargs): CONNECTORS[(self.id, connector_id)] = status + record_event("StatusNotification", self.id, + connector=connector_id, status=status, error=error_code) log.info("StatusNotification: connector=%s status=%s error=%s", connector_id, status, error_code) return call_result.StatusNotification() @@ -144,6 +175,7 @@ class ChargePoint(OcppChargePoint): async def on_authorize(self, id_tag, **kwargs): # RFID card tap, or app pre-auth. Plug-in autocharge sometimes lands here too. status = decide(id_tag, "Authorize (card/app/autocharge)") + record_event("Authorize", self.id, id_tag=id_tag, result=status.value) return call_result.Authorize(id_tag_info={"status": status}) @on(Action.start_transaction) @@ -160,6 +192,8 @@ class ChargePoint(OcppChargePoint): tx, connector_id, meter_start) else: tx = 0 # 0 tells the charger the transaction is not authorized + record_event("StartTransaction", self.id, connector=connector_id, + id_tag=id_tag, meter_start=meter_start, result=status.value, tx=tx) return call_result.StartTransaction( transaction_id=tx, id_tag_info={"status": status} ) @@ -168,6 +202,8 @@ class ChargePoint(OcppChargePoint): async def on_stop_transaction(self, meter_stop, timestamp, transaction_id, **kwargs): info = ACTIVE_TX.pop(transaction_id, None) used = (meter_stop - info["meter_start"]) if info else "?" + record_event("StopTransaction", self.id, tx=transaction_id, + meter_stop=meter_stop, delivered_wh=used, **kwargs) log.info("Transaction %s STOPPED (meter_stop=%s, delivered=%s Wh)", transaction_id, meter_stop, used) return call_result.StopTransaction( @@ -176,6 +212,8 @@ class ChargePoint(OcppChargePoint): @on(Action.meter_values) async def on_meter_values(self, connector_id, meter_value, **kwargs): + record_event("MeterValues", self.id, connector=connector_id, + values=meter_value, **kwargs) log.info("MeterValues: connector=%s values=%r", connector_id, meter_value) return call_result.MeterValues() @@ -217,34 +255,218 @@ async def remote_stop(transaction_id: int) -> str: return resp.status -async def on_connect(connection): - path = connection.request.path - cp_id = path.strip("/").split("/")[-1] or "unknown" - log.info("Charger connected: id=%r from %s subprotocol=%r", - cp_id, connection.remote_address, connection.subprotocol) - cp = ChargePoint(cp_id, connection) +# ---- discovery: interrogate the charger about what it is and what it supports ---- +async def interrogate(cp: ChargePoint) -> dict: + """GetConfiguration + trigger a StatusNotification per gun; save to discovery_.json. + + GetConfiguration with no keys asks for *everything* the charger exposes: + NumberOfConnectors, SupportedFeatureProfiles, meter settings, local-auth + support, ... A rejected/timed-out probe is itself a finding — record it. + """ + report = { + "charge_point": cp.id, + "probed_at": now(), + "boot_info": getattr(cp, "boot_info", None), + } + try: + resp = await cp.call(call.GetConfiguration()) + report["configuration"] = resp.configuration_key + report["unknown_keys"] = resp.unknown_key + except Exception as exc: + report["configuration_error"] = repr(exc) + try: + resp = await cp.call( + call.TriggerMessage(requested_message=MessageTrigger.status_notification) + ) + report["trigger_status_notification"] = resp.status + await asyncio.sleep(2) # give the triggered StatusNotifications time to arrive + except Exception as exc: + report["trigger_error"] = repr(exc) + report["connectors_seen"] = { + str(conn): status for (cp_id, conn), status in CONNECTORS.items() if cp_id == cp.id + } + path = HERE / f"discovery_{cp.id}.json" + path.write_text(json.dumps(report, indent=2, ensure_ascii=False), encoding="utf-8") + log.info( + "Discovery report -> %s (%d config keys, guns seen: %s)", + path.name, len(report.get("configuration") or []), + list(report["connectors_seen"]) or "none yet", + ) + return report + + +async def _auto_interrogate(cp: ChargePoint): + await asyncio.sleep(5) # let BootNotification land first + try: + await interrogate(cp) + except Exception: + log.exception("auto-interrogation of %r failed", cp.id) + + +class _WSAdapter: + """Bridge a Starlette WebSocket to the recv()/send() interface the ocpp lib expects.""" + + def __init__(self, ws: WebSocket): + self._ws = ws + + async def recv(self) -> str: + return await self._ws.receive_text() + + async def send(self, message: str) -> None: + await self._ws.send_text(message) + + async def close(self, code: int = 1000, reason: str = "") -> None: + await self._ws.close(code=code) + + +# ---- discovery HTTP API (curl / browser / phone over NetBird) ---- +api = FastAPI( + title="Charger Discovery API", + description="Poke the charger over its live OCPP socket. Interactive docs: /docs", +) + +TRIGGERABLE = { + "status": MessageTrigger.status_notification, + "meter": MessageTrigger.meter_values, + "heartbeat": MessageTrigger.heartbeat, + "boot": MessageTrigger.boot_notification, +} + + +@api.websocket("/{cp_path:path}") +async def ocpp_websocket(ws: WebSocket, cp_path: str): + """The OCPP endpoint the JC-6620 dials: ws://:9000/.""" + cp_id = cp_path.strip("/").split("/")[-1] or "unknown" + offered = [ + p.strip() + for p in ws.headers.get("sec-websocket-protocol", "").split(",") + if p.strip() + ] + if not offered: + log.warning( + "Charger %r connected WITHOUT an ocpp subprotocol header. " + "Handling it anyway so we can see its traffic.", cp_id, + ) + await ws.accept(subprotocol="ocpp1.6" if "ocpp1.6" in offered else None) + log.info("Charger connected: id=%r from %s subprotocols=%r", cp_id, ws.client, offered) + record_event("connected", cp_id, client=str(ws.client), subprotocols=offered) + cp = ChargePoint(cp_id, _WSAdapter(ws)) CONNECTED[cp_id] = cp + asyncio.create_task(_auto_interrogate(cp)) try: await cp.start() - except websockets.exceptions.ConnectionClosed: + except WebSocketDisconnect: log.info("Charger %r disconnected", cp_id) finally: + record_event("disconnected", cp_id) CONNECTED.pop(cp_id, None) + for key in [k for k in CONNECTORS if k[0] == cp_id]: + CONNECTORS.pop(key, None) + + +def _pick_cp(cp_id: Optional[str]) -> ChargePoint: + if cp_id is not None: + cp = CONNECTED.get(cp_id) + if cp is None: + raise HTTPException(404, f"charge point {cp_id!r} is not connected") + return cp + if len(CONNECTED) == 1: + return next(iter(CONNECTED.values())) + raise HTTPException(409, f"specify ?cp=; currently connected: {list(CONNECTED)}") + + +async def _ocpp(coro): + """Run an OCPP call for an HTTP handler, mapping failures to HTTP errors.""" + try: + return await coro + except HTTPException: + raise + except Exception as exc: + raise HTTPException(502, f"OCPP call failed: {exc!r}") + + +@api.get("/status") +async def api_status(): + return { + "mode": "learn" if CONFIG.get("learn_mode") else "enforce", + "connected": {cp_id: getattr(cp, "boot_info", None) for cp_id, cp in CONNECTED.items()}, + "connectors": {f"{cp_id}/{conn}": s for (cp_id, conn), s in CONNECTORS.items()}, + "active_transactions": ACTIVE_TX, + "recent_auth_events": list(AUTH_EVENTS), + } + + +@api.get("/events") +async def api_events(limit: int = 100, event: Optional[str] = None): + """Tail the event journal; filter with ?event=MeterValues etc.""" + if not EVENTS_PATH.exists(): + return [] + lines = EVENTS_PATH.read_text(encoding="utf-8").splitlines() + entries = [json.loads(line) for line in lines if line.strip()] + if event is not None: + entries = [e for e in entries if e.get("event") == event] + return entries[-limit:] + + +@api.get("/tags") +async def api_tags(): + seen = json.loads(SEEN_PATH.read_text(encoding="utf-8")) if SEEN_PATH.exists() else {} + return {"authorized": CONFIG["authorized"], "seen": seen} + + +@api.post("/probe") +async def api_probe(cp: Optional[str] = None): + return await _ocpp(interrogate(_pick_cp(cp))) + + +@api.post("/start") +async def api_start(id_tag: str = "app-remote", connector: int = 1, cp: Optional[str] = None): + status = await _ocpp(remote_start(_pick_cp(cp).id, id_tag, connector)) + return {"remote_start": status} + + +@api.post("/stop") +@api.post("/stop/{tx}") +async def api_stop(tx: Optional[int] = None): + if tx is None: + if len(ACTIVE_TX) != 1: + raise HTTPException(409, f"specify /stop/; active: {list(ACTIVE_TX)}") + tx = next(iter(ACTIVE_TX)) + status = await _ocpp(remote_stop(tx)) + return {"remote_stop": status, "transaction": tx} + + +@api.post("/trigger/{what}") +async def api_trigger(what: str, connector: Optional[int] = None, cp: Optional[str] = None): + if what not in TRIGGERABLE: + raise HTTPException(400, f"unknown trigger {what!r}; options: {list(TRIGGERABLE)}") + payload = call.TriggerMessage(requested_message=TRIGGERABLE[what], connector_id=connector) + resp = await _ocpp(_pick_cp(cp).call(payload)) + return {"trigger": what, "status": resp.status} + + +@api.post("/unlock/{connector}") +async def api_unlock(connector: int, cp: Optional[str] = None): + resp = await _ocpp(_pick_cp(cp).call(call.UnlockConnector(connector_id=connector))) + return {"unlock": connector, "status": resp.status} + + +@api.post("/setconfig") +async def api_setconfig(key: str, value: str, cp: Optional[str] = None): + resp = await _ocpp(_pick_cp(cp).call(call.ChangeConfiguration(key=key, value=value))) + return {"key": key, "value": value, "status": resp.status} async def main(): - def select_subprotocol(connection, subprotocols): - return "ocpp1.6" - - server = await websockets.serve( - on_connect, "0.0.0.0", 9000, - subprotocols=["ocpp1.6"], - select_subprotocol=select_subprotocol, - ) mode = "LEARN (accepting & recording new ids)" if CONFIG["learn_mode"] else "ENFORCING allowlist" - log.info("Private CSMS on ws://0.0.0.0:9000/ | mode: %s | %d authorized id(s)", - mode, len(CONFIG["authorized"])) - await server.wait_closed() + log.info( + "Private CSMS on ws://0.0.0.0:9000/ | discovery API http://0.0.0.0:9000/docs" + " | mode: %s | %d authorized id(s)", + mode, len(CONFIG["authorized"]), + ) + await uvicorn.Server( + uvicorn.Config(api, host="0.0.0.0", port=9000, log_config=None) + ).serve() if __name__ == "__main__": diff --git a/discovering/station_config.json b/discovering/station_config.json index b61a1fa..76421c1 100644 --- a/discovering/station_config.json +++ b/discovering/station_config.json @@ -1,4 +1,17 @@ { "learn_mode": true, - "authorized": {} + "authorized": { + "1000000000000393": { + "name": "RFID card A (tapped first, 2026-07-09)", + "kind": "card" + }, + "app-remote": { + "name": "Web/app remote start token", + "kind": "app" + }, + "1000000000000395": { + "name": "RFID card B (tapped second, 2026-07-09)", + "kind": "card" + } + } } \ No newline at end of file