GithubHelp home page GithubHelp logo

node-ultimatron-battery's Introduction

Ultimatron battery BMS

Javascript interface for Ultimatron battery BMS via BLE. Using node-ble under the hood. Allows getting battery information update and managing charge and discharge statuses.

Obtaining battery MAC address

The simplest way is to scan for all devices without duplicates:

sudo hcitool -i hci0 lescan | head -n 100 | sort -u

Battery would have a name like '12100AE2100111'.

Usage

  // discover all battery instances, timing out scan after 60 seconds
  const batteries = await UltimatronBattery.findAll(60000)

  // discover up to 3 batterries or timing out scan after 60 seconds
  const batteries = await UltimatronBattery.findAll(60000, 3)

  // Find a specific battery by name
  const battery = await UltimatronBattery.forName('12100AE2100111')

  // Use battery in a shared mode, so status polling will disconnect 
  // between updates and won't exlusively keep the BLE connection 
  // Also sets interval between updates to 5 minutes
  const battery = await UltimatronBattery.forName('12100AE2100111', true, 60000, 5*60*1000)

  // Subscribes on battery state updates
  // Updates happen periodically even if state remains the same
  battery.onStateUpdate((state: BatteryState) => {
    console.log(`Battery state updated to ${state}`)
  }

  // enable discharging
  await battery.toggleDischarging(true)

  // get cached state and voltage
  console.log("Battery state:", battery.getState())

  // release the BLE connection of the device
  device.disconnect()

Troubleshooting

If the battery disconnects immediatly after BLE connection was established it might require increasing BLE timesouts (for HCI0 device):

$ sudo sh -c "/bin/echo 100 > /sys/kernel/debug/bluetooth/hci0/conn_max_interval"^C
$ sudo sh -c "/bin/echo 99 > /sys/kernel/debug/bluetooth/hci0/conn_latency"
$ sudo sh -c "/bin/echo 10 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval"

node-ultimatron-battery's People

Contributors

sergkh avatar

Stargazers

Marco Raffael avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.