/can-service

Simulate a BYD Battery-Box Premium HVS over CAN Bus to use a custom battery with your inverter. Controllable via MQTT.

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

can-service

hardware

  • Waveshare 2-CH CAN HAT (shop , wiki)
  • Raspberry Pi 4B

installation

/usr/sbin/ip link set can0 type can restart-ms 100
/usr/sbin/ip link set can1 type can restart-ms 100
/usr/sbin/ip link set can0 up type can bitrate 500000
/usr/sbin/ip link set can1 up type can bitrate 500000
/usr/sbin/ifconfig can0 txqueuelen 100
/usr/sbin/ifconfig can1 txqueuelen 100
  • chmod +x startscript.sh
  • sudo crontab -e and add @reboot /root/startscript.sh
  • (if running directly): run pip install -r requirements.txt in repository dir

run

directly

./service.py

docker compose

can-service:
  build: https://github.com/SunshadeCorp/can-service.git
  container_name: can-service
  depends_on:
    - mosquitto
  network_mode: host
  restart: unless-stopped
  volumes:
    - ./can-service/credentials.yaml:/usr/src/app/credentials.yaml:ro

mqtt messages

publish:

master
└─ can (running/stopped)
   ├─ available (online/offline)
   └─ [topic] ([float])

subscribe:

master
├─ can
│  ├─ start ([any])
│  ├─ stop ([any])
│  └─ [topic]
│     ├─ reset ([any])
│     └─ set ([float])
└─ relays
   └─ kill_switch (pressed)
esp-total
├─ total_voltage ([float])
└─ total_current ([float]) {positive = discharge, negative = charge}

current config.yaml topics:

battery
├─ current {positive = charge, negative = discharge}
├─ max_cell_temp
├─ min_cell_temp
├─ soc
├─ soh
├─ temp
└─ voltage
inverter
├─ battery_voltage (read only)
├─ soc (read only)
└─ timestamp (read only)
limits
├─ max_charge_current
├─ max_discharge_current
├─ max_voltage
└─ min_voltage