|
| 1 | +# Use Case: Managing EV Charging Stations |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +### System |
| 6 | + |
| 7 | +The system is an IoT device management workflow specifically designed for Electric Vehicle (EV) charging stations. It utilizes the Serverless Workflow DSL to automate the monitoring, management, and maintenance of EV charging units, ensuring they operate efficiently and are available for users. |
| 8 | + |
| 9 | +### Actors |
| 10 | + |
| 11 | +- **EV Drivers:** Individuals who use electric vehicles and need charging services. |
| 12 | +- **Charging Station Operators:** Businesses or entities managing the charging stations. |
| 13 | +- **IoT Devices:** Sensors and controllers in the charging stations that provide real-time data. |
| 14 | +- **Cloud Services:** External systems for storing data and providing analytics. |
| 15 | + |
| 16 | +### Goals |
| 17 | + |
| 18 | +- **Automate Charging Management:** Streamline the management of charging sessions, including starting, stopping, and monitoring. |
| 19 | +- **Monitor Station Health:** Enable real-time monitoring of the charging stations to detect and address issues proactively. |
| 20 | +- **Enhance User Experience:** Provide seamless experiences for EV drivers while charging their vehicles. |
| 21 | + |
| 22 | +### Preconditions |
| 23 | + |
| 24 | +- The workflow assumes that the charging stations are equipped with IoT devices that can send and receive events. |
| 25 | +- An appropriate cloud infrastructure is in place to handle the data from charging sessions and device statuses. |
| 26 | + |
| 27 | +## Scenario |
| 28 | + |
| 29 | +### Triggers |
| 30 | + |
| 31 | +The workflow is triggered when: |
| 32 | + |
| 33 | +- An EV charging session starts. |
| 34 | +- An EV charging session ends. |
| 35 | +- The charging station reports an error. |
| 36 | + |
| 37 | +### Flow Breakdown |
| 38 | + |
| 39 | + |
| 40 | +### Visualization |
| 41 | + |
| 42 | +The following diagram represents the high-level flow of the workflow: |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +### Example |
| 47 | + |
| 48 | +```yaml |
| 49 | +document: |
| 50 | + dsl: '1.0.0' |
| 51 | + namespace: default |
| 52 | + name: managing-ev-charging-stations |
| 53 | + version: '0.1.0' |
| 54 | +schedule: |
| 55 | + on: |
| 56 | + any: |
| 57 | + - with: |
| 58 | + type: com.ev-power-supplier.charging-station.card-scanned.v1 |
| 59 | + - with: |
| 60 | + type: com.ev-power-supplier.charging-station.faulted.v1 |
| 61 | +do: |
| 62 | + |
| 63 | + - initialize: |
| 64 | + set: |
| 65 | + event: ${ $workflow.input[0].data } |
| 66 | + export: |
| 67 | + as: .event |
| 68 | + |
| 69 | + - handleStationEvents: |
| 70 | + switch: |
| 71 | + - sessionStarted: |
| 72 | + when: .event.type == "com.ev-power-supplier.charging-station.card-scanned.v1" |
| 73 | + then: tryGetActiveSession |
| 74 | + - stationError: |
| 75 | + when: .event.type == "com.ev-power-supplier.charging.station-faulted.v1" |
| 76 | + then: handleError |
| 77 | + then: raiseUnsupportedEventError |
| 78 | + |
| 79 | + - tryGetActiveSession: |
| 80 | + try: |
| 81 | + - getSessionForCard: |
| 82 | + call: http |
| 83 | + with: |
| 84 | + method: get |
| 85 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/session/{cardId} |
| 86 | + - setSessionInfo: |
| 87 | + set: |
| 88 | + session: ${ .session } |
| 89 | + catch: |
| 90 | + errors: |
| 91 | + with: |
| 92 | + status: 404 |
| 93 | + |
| 94 | + - handleActiveSession: |
| 95 | + switch: |
| 96 | + - sessionInProgress: |
| 97 | + when: .session != null |
| 98 | + then: endSession |
| 99 | + - noActiveSession: |
| 100 | + then: tryAquireSlot |
| 101 | + |
| 102 | + - tryAquireSlot: |
| 103 | + try: |
| 104 | + - acquireSlot: |
| 105 | + call: http |
| 106 | + with: |
| 107 | + method: post |
| 108 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId} |
| 109 | + body: |
| 110 | + card: ${ $context.card } |
| 111 | + export: |
| 112 | + as: '$context + { slot: .slot }' |
| 113 | + catch: |
| 114 | + errors: |
| 115 | + with: |
| 116 | + status: 400 |
| 117 | + when: .detail == "No charging slots available" |
| 118 | + do: |
| 119 | + - noSlotsAvailable: |
| 120 | + call: http |
| 121 | + with: |
| 122 | + method: post |
| 123 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/leds/main |
| 124 | + body: |
| 125 | + action: flicker |
| 126 | + color: red |
| 127 | + duration: 3000 |
| 128 | + then: end |
| 129 | + |
| 130 | + - startSession: |
| 131 | + do: |
| 132 | + - initialize: |
| 133 | + set: |
| 134 | + session: |
| 135 | + card: ${ $context.card } |
| 136 | + slotNumber: ${ $context.slot.number } |
| 137 | + export: |
| 138 | + as: '$context + { session: . }' |
| 139 | + - feedBack: |
| 140 | + call: http |
| 141 | + with: |
| 142 | + method: post |
| 143 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/leds/{slotNumber} |
| 144 | + body: |
| 145 | + action: 'on' |
| 146 | + color: blue |
| 147 | + - lockSlot: |
| 148 | + call: http |
| 149 | + with: |
| 150 | + method: put |
| 151 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/slot/{slotNumber}/lock |
| 152 | + - start: |
| 153 | + call: http |
| 154 | + with: |
| 155 | + method: put |
| 156 | + endpoint: https://ev-power-supplier.com/api/v2/sessions/{sessionId}/start |
| 157 | + - notify: |
| 158 | + emit: |
| 159 | + event: |
| 160 | + with: |
| 161 | + source: https://ev-power-supplier.com |
| 162 | + type: com.ev-power-supplier.charging-station.session-started.v1 |
| 163 | + data: ${ $context.session } |
| 164 | + |
| 165 | + - endSession: |
| 166 | + do: |
| 167 | + - end: |
| 168 | + call: http |
| 169 | + with: |
| 170 | + method: put |
| 171 | + endpoint: https://ev-power-supplier.com/api/v2/sessions/{sessionId}/end |
| 172 | + - processPayment: |
| 173 | + call: http |
| 174 | + with: |
| 175 | + method: put |
| 176 | + endpoint: https://ev-power-supplier.com/api/v2/sessions/{sessionId}/pay |
| 177 | + - unlockSlot: |
| 178 | + call: http |
| 179 | + with: |
| 180 | + method: put |
| 181 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/slot/{slotNumber}/unlock |
| 182 | + - feedBack: |
| 183 | + call: http |
| 184 | + with: |
| 185 | + method: post |
| 186 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/leds/{slotNumber} |
| 187 | + body: |
| 188 | + action: flicker |
| 189 | + color: white |
| 190 | + duration: 3000 |
| 191 | + - notify: |
| 192 | + emit: |
| 193 | + event: |
| 194 | + with: |
| 195 | + source: https://ev-power-supplier.com |
| 196 | + type: com.ev-power-supplier.charging-station.session-ended.v1 |
| 197 | + data: ${ $context.session } |
| 198 | + then: end |
| 199 | + |
| 200 | + - handleError: |
| 201 | + do: |
| 202 | + - contactSupport: |
| 203 | + call: http |
| 204 | + with: |
| 205 | + method: post |
| 206 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/support |
| 207 | + body: |
| 208 | + error: ${ $context.event.data.error } |
| 209 | + - feedBack: |
| 210 | + call: http |
| 211 | + with: |
| 212 | + method: post |
| 213 | + endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/leds/main |
| 214 | + body: |
| 215 | + action: 'on' |
| 216 | + color: red |
| 217 | + - notify: |
| 218 | + emit: |
| 219 | + event: |
| 220 | + with: |
| 221 | + source: https://ev-power-supplier.com |
| 222 | + type: com.ev-power-supplier.charging-station.out-of-order.v1 |
| 223 | + data: ${ $context.event.data.error } |
| 224 | + then: end |
| 225 | + |
| 226 | + - raiseUnsupportedEventError: |
| 227 | + raise: |
| 228 | + error: |
| 229 | + type: https://serverlessworkflow.io/spec/1.0.0/errors/runtime |
| 230 | + status: 400 |
| 231 | + title: Unsupported Event |
| 232 | + detail: ${ "The specified station event '\($context.event.type)' is not supported in this context" } |
| 233 | + then: end |
| 234 | +``` |
| 235 | +
|
| 236 | +## Conclusion |
| 237 | +
|
| 238 | +This use case highlights the capabilities of Serverless Workflow in managing EV charging stations effectively. By automating charging sessions and monitoring station health, organizations can enhance user experiences for EV drivers while ensuring that their charging infrastructure operates efficiently. Leveraging Serverless Workflow enables responsive and scalable management solutions in the evolving landscape of electric vehicle infrastructure. |
0 commit comments