solispauwels / x1-p1-dosing-pump-script

Control the X1/P1 dosing pumps using nodejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

X1/P1 dosing pump control script

X1 P1

This nodejs scripts allows you to control your Bluetooth dosing pump Kamoer X1 or D-D P1 without using the official Android or iOS applications. Indeed The Android application have a very poor compatibility of devices and API version, making it unusable, for example in recent mobile phones with LineageOS.

Also there are a lot of users complains that the automatic planned dosing does not work very well and the pumps loses settings if the application is not opened regularly or on power outage. With this script on the contrary you can create what ever plan you want by simply use cron utility, which is more reliable.

This was achieved by reverse engineering, thanks on post and videos of the hacker Mike Ryan. For now only the manual dosing is supported (in complement with cron). Feel free to do a merge request if you want more functionalities of the official application.

Requirements:

  • Bluetooth configured and working on your system.
  • gatttol command.
  • NodeJs
const pump = require('./pump')

const dosing = async () => {
  await pump.start(10) // Liquid volume in ml.
  await pump.sleep() // Optional
  await pump.stop() // Optional
}

dosing()

The sleep and stop methods are optional. They are not required because the pump stop by itself. But there are user (of the official application) that complains that sometimes the manual dosing is not well stop.

You can pass to start method the volume in ml and also the calibration, or you can set them on the config.js file.

You have to set the MAC address of your pump on the config.js file, run the following command to found your MAC address:

$ sudo hcitool lescan

Using cron

To schedule a dosing, you can use regular crontab command, node-cron or even PM2. In My case I opt for PM2 with the --cron flag:

$ pm2 start index.js --cron "0 5 */10 * *" --no-autorestart
$ pm2 save

TODO

  • There is no a retry system in case of failure. In my case this is no yet needed because I use a Raspberry PI Zero W which is very close to the pump.
  • There is no yet multiple simultaneous pump support.

About

Control the X1/P1 dosing pumps using nodejs


Languages

Language:Java 82.8%Language:JavaScript 17.2%