This is an updated version of the CAN adapter that uses ClearBlade service account authentication instead of device authentication.
- Service Account Authentication: Uses ClearBlade service accounts for secure authentication
- DBC File Support: Parses and uses DBC files for CAN message decoding
- MQTT Integration: Connects to ClearBlade Edge via MQTT
- Multiple CAN Channels: Supports multiple CAN interfaces
- Environment Variable Support: Can be configured via environment variables
CB_SYSTEM_KEY
: ClearBlade system keyCB_SYSTEM_SECRET
: ClearBlade system secretCB_SERVICE_ACCOUNT
: ClearBlade service account nameCB_SERVICE_ACCOUNT_TOKEN
: ClearBlade service account token
./adapter_v2 \
--systemKey="your-system-key" \
--systemSecret="your-system-secret" \
--serviceAccount="your-service-account" \
--serviceAccountToken="your-service-account-token" \
--platformURL="https://your-platform.clearblade.com" \
--messagingURL="your-platform.clearblade.com:1883" \
--canInterfaces='[{"interface":"can0","bitrate":500000,"dbc_file":"obd2.dbc"}]'
- Set environment variables:
export CB_SYSTEM_KEY="your-system-key"
export CB_SYSTEM_SECRET="your-system-secret"
export CB_SERVICE_ACCOUNT="your-service-account"
export CB_SERVICE_ACCOUNT_TOKEN="your-service-account-token"
- Run the adapter:
go run . \
--canInterfaces='[{"interface":"can0","bitrate":500000,"dbc_file":"obd2.dbc"}]'
canbus/{channel}/send
- Receives raw CAN frames from simulators or other sources
canbus/{channel}/adapterread
- Sends decoded CAN messages to ClearBlade Edge
{
"id": 2024,
"can_data": "0000001C00000000"
}
{
"id": 2024,
"data": {
"S1_PID_11_ThrottlePosition": 28.049776
},
"timestamp": 1640995200000000000
}
-
Create a Service Account in ClearBlade Platform:
- Go to your ClearBlade system
- Navigate to Users collection
- Create a new user with
cb_service_account: true
- Note the generated
cb_token
-
Set up the service account token:
- The
cb_token
from step 1 is your service account token - Set it as the
CB_SERVICE_ACCOUNT_TOKEN
environment variable
- The
cd can-adapter/v2
go build -o adapter_v2 .
Run the adapter in test mode:
go run . \
--testMode \
--canInterfaces='[{"interface":"can0","bitrate":500000,"dbc_file":"obd2.dbc"}]'
This will test the connection and configuration without requiring actual CAN hardware.
- Uses service account authentication instead of device authentication
- Improved error handling and logging
- Better support for different message formats
- More robust MQTT connection handling
- Environment variable support for easier deployment
-
Authentication Failed:
- Verify your service account and token are correct
- Check that the service account has the necessary permissions
-
Connection Lost:
- Verify your platform URL and messaging URL are correct
- Check network connectivity to ClearBlade Edge
-
DBC File Not Found:
- Ensure the DBC file path is correct
- Check file permissions
-
CAN Interface Not Available:
- Ensure the CAN interface is properly configured
- Check that the interface name matches your system
Set the log level to debug for more detailed output:
go run . --logLevel=debug