|
| 1 | +# Node ETX Client Sample |
| 2 | + |
| 3 | +This repository serves as a practical guide for developers looking to get started with the Verizon ETX platform in Node. It offers a selection of concise, self-contained examples designed to help you quickly understand core V2X concepts—such as mTLS authentication, J2735 message transcoding, and geographic topic routing. |
| 4 | + |
| 5 | +## Running Examples |
| 6 | + |
| 7 | +This version of the client sample has been tested against **v22.16.0**. It utilizes the `j2735codec` for transcoding between JER (JSON) and UPER (Binary) formats. |
| 8 | + |
| 9 | +**NOTE**: All references to the project root refer to `etx/examples/node/`. This is where **ALL** the examples should be executed from. |
| 10 | + |
| 11 | +### Prerequisite - Setup |
| 12 | + |
| 13 | +The fastest way to get started is to download the packages from release. The latest release can be [found here](https://github.com/5GRealityLab/etx-starter-kit/releases/latest). |
| 14 | + |
| 15 | +The file to download will look like: `node-etx-sample-x.x.x.zip`, where x.x.x is the version fo the project. |
| 16 | + |
| 17 | +1. **Install Dependencies**: |
| 18 | + |
| 19 | + **Install With Pip** |
| 20 | + |
| 21 | + ```bash |
| 22 | + curl -L -O https://github.com/5GRealityLab/etx-starter-kit/releases/latest/download/node-etx-sample-x.x.x.zip |
| 23 | + unzip node-etx-sample-x.x.x.zip -d node-etx-sample |
| 24 | + cd node-etx-sample |
| 25 | + npm install ./j2735codec/j2735codec-*.tgz |
| 26 | + |
| 27 | + # Ready to Run! |
| 28 | + ``` |
| 29 | + |
| 30 | +2. **Environment Configuration**: Create a `config.json` file to start using the examples. The [`config.json.example`](./config.json.example) file provides a good starting point. |
| 31 | + |
| 32 | + Here are some pointers on what to fill out for the fields in the JSON. |
| 33 | + |
| 34 | + | Section | Field | Type | Description | |
| 35 | + | :--- | :--- | :--- | :--- | |
| 36 | + | **Root** | `logLevel` | String | Controls the verbosity of the console output (e.g., `DEBUG`, `INFO`, `WARN`, `ERROR`). | |
| 37 | + | | `certDir` | String | The local directory where security certificates and keys are generated after registration completes. | |
| 38 | + | **identity** | `user` | String | Your Verizon ThingSpace account username. | |
| 39 | + | | `password` | String | Your Verizon ThingSpace account password. | |
| 40 | + | | `token` | String | The Base64 encoded Application Token (Client ID:Client Secret) from ThingSpace. | |
| 41 | + | **attributes**| `clientType` | String | The broad category of the client (e.g., `Vehicle`, `VulnerableRoadUser`, etc). | |
| 42 | + | | `clientSubType` | String | The specific type of vehicle (e.g., `PassengerCar`, `Truck`, `Radar`, etc). | |
| 43 | + | | `vendorId` | String | An identifier for the software or hardware provider. | |
| 44 | + | **location** | `lat` | Float | The initial latitude for the device (used during registration/geofencing). | |
| 45 | + | | `lon` | Float | The initial longitude for the device. | |
| 46 | + |
| 47 | +**Note: The latitude and longitude determines which edge server you will conenct to.** |
| 48 | + |
| 49 | +**Note: The `Endpoints` section in the config is optional and does not have to be filled out or included in the final `config.json`.** |
| 50 | +```json |
| 51 | +"endpoints": { |
| 52 | + "oauthUrl": "https://thingspace.verizon.com/api/ts/v1/oauth2/token", |
| 53 | + "sessionUrl": "https://thingspace.verizon.com/api/m2m/v1/session/login", |
| 54 | + "oauthTimeout": 30000, |
| 55 | + "registrationUrl": "https://imp.thingspace.verizon.com", |
| 56 | + "registrationTimeout": 45000 |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +#### Supported Arguments |
| 61 | + |
| 62 | +The following command line arguments are supported by all examples in the next section. |
| 63 | + |
| 64 | +| Arg | Required | Default | Description | |
| 65 | +| :--- | :--- | :--- | :--- | |
| 66 | +| --log-level | False | DEBUG | Controls the verbosity of the console output (e.g., `DEBUG`, `INFO`, `WARN`, `ERROR`). | |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +### 0. Registration Example |
| 71 | + |
| 72 | +The registration example is a precursor to performing any other operations on ETX. This step retrieves a unique **Device ID** and the **mTLS certificates** (CA, Certificate, and Private Key) required to connect. |
| 73 | + |
| 74 | +**IMPORTANT**: Each vendor ID has a fixed quota of device IDs. Always keep track of your registrations and deregister when finished. |
| 75 | + |
| 76 | +#### How to Run |
| 77 | +```bash |
| 78 | +npm run registration -- --config config.json --cert-dir ./certs |
| 79 | +``` |
| 80 | + |
| 81 | +**Output**: The above command generates a JSON "Identity Artifact" in the `./certs/` folder. This file contains everything needed to "re-hydrate" your identity in the following examples. |
| 82 | + |
| 83 | +#### Supported Arguments |
| 84 | + |
| 85 | +| Arg | Required | Default | Description | |
| 86 | +| :--- | :--- | :--- | :--- | |
| 87 | +| --cert-dir| False | ./cert/ | The local directory where security certificates and keys are generated after registration completes. | |
| 88 | +| --config | False | config.json | The configuration file to use for registration. | |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +### 1. Deregistration Examples |
| 93 | + |
| 94 | +The deregistration example removes the registered device from ETX. Every vendor ID is has a limited number of device IDs. The deregistration process removes a unique device ID from circulation. This will also remove the files in the folder that contain the registration information. |
| 95 | + |
| 96 | +#### How to Run |
| 97 | + |
| 98 | +The command format to run this example (from the project root): |
| 99 | +```bash |
| 100 | +npm run deregistration -- --device-files ./certs/20260119_0101_f355703d.json |
| 101 | +``` |
| 102 | + |
| 103 | +#### Supported Arguments |
| 104 | + |
| 105 | +| Arg | Required | Default | Description | |
| 106 | +| :--- | :--- | :--- | :--- | |
| 107 | +| --device-file | False | config.json | The configuration file to use for registration. | |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +### 2. Private Loopback Example |
| 112 | + |
| 113 | +A diagnostic tool to verify bidirectional private communication. |
| 114 | + |
| 115 | +1. Connects to the ETX platform and acquires a Session ID. |
| 116 | +2. Subscribes to its own unique **Private Topic**. |
| 117 | +3. Publishes a BSM to itself to verify the mTLS loop is closed. |
| 118 | + |
| 119 | +#### How to Run |
| 120 | +```bash |
| 121 | +npm run loopback -- --device-file ./certs/20260119_0101_f355703d.json --count 5 |
| 122 | +``` |
| 123 | +#### Supported Arguments |
| 124 | + |
| 125 | +| Arg | Required | Default | Description | |
| 126 | +| :--- | :--- | :--- | :--- | |
| 127 | +| --device-file | True | - | The device file to use for ETX connection. | |
| 128 | +| --count | False | 5 | The number of loopback messages to send. | |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +### 3. Speed Monitor Example (RSU/App) |
| 133 | + |
| 134 | +Demonstrates a "Virtual Speed Trap" application. |
| 135 | +1. **Geohashing**: Subscribes to regional topics by delimiting geohashes (e.g., `d/r/5/r/9/y`). |
| 136 | +2. **Real-time Analytics**: Decodes BSMs from all vehicles in the neighborhood. |
| 137 | +3. **Targeted Advisory**: If a vehicle exceeds the `--limit`, it sends a **TIM (Traveler Information Message)** warning directly to that specific vehicle's private topic. |
| 138 | + |
| 139 | +#### How to Run |
| 140 | +```bash |
| 141 | +npm run speedmon -- --device-file ./certs/20260119_0101_f355703d.json --limit 25 |
| 142 | +``` |
| 143 | + |
| 144 | +#### Supported Arguments |
| 145 | + |
| 146 | +| Arg | Required | Default | Description | |
| 147 | +| :--- | :--- | :--- | :--- | |
| 148 | +| --device-file | True | - | The device file to use for ETX connection. | |
| 149 | +| --lat | False | - | The default value is defined in the registration config file. | |
| 150 | +| --lon | False | - | The default value is defined in the registraiton config file. | |
| 151 | +| --limit | False | 25 | The speed limit in mph to send out warnings. | |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +### 4. Vehicle Example (OBU) |
| 156 | + |
| 157 | +Simulates a mobile entity (On-Board Unit). It demonstrates the "Public Broadcast" pattern used in real-world V2X. |
| 158 | +1. **Session Handshake**: Connects and retrieves a Session ID from `vzimp/1/ClientInfo`. |
| 159 | +2. **Periodic Broadcast**: Runs a background thread to publish BSMs to the `GeoRelevance` topic at 1Hz. |
| 160 | +3. **Regional Listening**: Subscribes to regional safety messages (TIM, SPaT, MAP). |
| 161 | + |
| 162 | +#### How to Run |
| 163 | +```bash |
| 164 | +npm run vehicle -- --device-file ./certs/20260119_0101_f355703d.json --speed 25 |
| 165 | +``` |
| 166 | + |
| 167 | +**Note**: You can try running both the speed monitor and vehicle example together to see when TIM messages are sent to warn the vehicle of speed limit violations. **Remember to use two different registration profiles! One for the monitor and one for the vehicle.** |
| 168 | + |
| 169 | +#### Supported Arguments |
| 170 | + |
| 171 | +| Arg | Required | Default | Description | |
| 172 | +| :--- | :--- | :--- | :--- | |
| 173 | +| --device-file | True | - | The device file to use for ETX connection. | |
| 174 | +| --lat | False | - | The default value is defined in the registration config file. | |
| 175 | +| --lon | False | - | The default value is defined in the registraiton config file. | |
| 176 | +| --speed | False | 30 | The speed in which the vehicle is traveling at. | |
| 177 | +--- |
| 178 | + |
| 179 | +### Install and Running From Source (For Project Contributors) |
| 180 | + |
| 181 | +It is possible to run the examples directly from this project as well. Check the prequisites for the building the [language bindings here](/README.md#2-source-install). |
| 182 | + |
| 183 | +```bash |
| 184 | +git clone https://github.com/5GRealityLab/etx-starter-kit.git |
| 185 | +cd etx-starter-kit |
| 186 | +make install-js |
| 187 | +cd etx/examples/node |
| 188 | + |
| 189 | +# Run examples above |
| 190 | + |
| 191 | +``` |
| 192 | + |
| 193 | +--- |
| 194 | + |
| 195 | +### FAQ |
| 196 | + |
| 197 | +**What is the difference between Public and Private topics?** Public topics (`GeoRelevance` or `Regional`) are for one-to-many broadcasts based on location. Private topics are for one-to-one communication targeted at a specific `SessionID`. |
| 198 | + |
| 199 | +**Why use two separate Codecs?** V2X clients are multi-threaded. The MQTT library handles incoming messages on a background thread while your application publishes on the main thread. Using separate `Codec` instances prevents race conditions. |
| 200 | + |
| 201 | +**How do I clean up my device?** Please refer to the `0_deregistration_example` to remove your device ID from the system and reclaim your quota. |
0 commit comments