Skip to content

ClearBlade/CANBus-IA-Adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CAN Adapter with Intelligent Assets integration

This is an updated version of the CAN adapter that uses ClearBlade service account authentication instead of device authentication.

Features

  • 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

Configuration

Required Environment Variables

  • CB_SYSTEM_KEY: ClearBlade system key
  • CB_SYSTEM_SECRET: ClearBlade system secret
  • CB_SERVICE_ACCOUNT: ClearBlade service account name
  • CB_SERVICE_ACCOUNT_TOKEN: ClearBlade service account token

Command Line Arguments

./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"}]'

Example Usage

  1. 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"
  1. Run the adapter:
go run . \
  --canInterfaces='[{"interface":"can0","bitrate":500000,"dbc_file":"obd2.dbc"}]'

MQTT Topics

Subscribes to:

  • canbus/{channel}/send - Receives raw CAN frames from simulators or other sources

Publishes to:

  • canbus/{channel}/adapterread - Sends decoded CAN messages to ClearBlade Edge

Message Formats

Input Format (canbus/{channel}/send)

{
  "id": 2024,
  "can_data": "0000001C00000000"
}

Output Format (canbus/{channel}/adapterread)

{
  "id": 2024,
  "data": {
    "S1_PID_11_ThrottlePosition": 28.049776
  },
  "timestamp": 1640995200000000000
}

Service Account Setup

  1. 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
  2. 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

Building

cd can-adapter/v2
go build -o adapter_v2 .

Testing

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.

Differences from V1

  • 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

Troubleshooting

Common Issues

  1. Authentication Failed:

    • Verify your service account and token are correct
    • Check that the service account has the necessary permissions
  2. Connection Lost:

    • Verify your platform URL and messaging URL are correct
    • Check network connectivity to ClearBlade Edge
  3. DBC File Not Found:

    • Ensure the DBC file path is correct
    • Check file permissions
  4. CAN Interface Not Available:

    • Ensure the CAN interface is properly configured
    • Check that the interface name matches your system

Debug Mode

Set the log level to debug for more detailed output:

go run . --logLevel=debug

About

CAN bus adapter with Intelligent Assets integration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages