GithubHelp home page GithubHelp logo

lucapinello / pyacaia Goto Github PK

View Code? Open in Web Editor NEW
48.0 6.0 15.0 44 KB

Python module to interact with Acaia scales via Bluetooth (BLE)

License: GNU Affero General Public License v3.0

Python 100.00%

pyacaia's Introduction

pyacaia

Python module to interact with Acaia scales (https://acaia.co/collections/coffee-scales) via Bluetooth (BLE).

Note: If you are using the Acaia Lunar 2021 edition, make sure to update the firmware, otherwise the commands will not work (e.g. tare, start timer etc).

This code was inspired by the javascript version available here https://github.com/bpowers/btscale

0. Requirements

Linux, Python (>=2.7 or >=3.5) and bluepy (https://github.com/lucapinello/bluepy) (pygatt >=4.0.3 is also partially supported https://github.com/peplin/pygatt; Pyxis not supported under pygatt)

This package has been tested on a RasperryPI ZeroW with Raspbian GNU/Linux 9 (stretch) and on Ubuntu Linux 20.04, and with the Lunar and Pyxis scales.

1. Install with:

pip install pyacaia

2. Short example

    from pyacaia import AcaiaScale
    
    scale=AcaiaScale(mac='00:1C:97:17:FD:97')
    
    scale.auto_connect() #to pick the first available
    
    # Or if you know the address use:
    # scale.connect()
    
    # battery value in percent
    print(scale.battery)

    # scale units is 'grams' or 'ounces'
    print(scale.units)

    # minutes of idle before auto-off
    print(scale.auto_off)

    # will the scale beep when a button is pressed?
    if scale.beep_on:
	print('It beeps!')
    else:
	print('It is silent!')

    # is the timer running?
    if scale.timer_running:
	print('timer is running')
	# elapsed time is in seconds, if timer is paused
	# the value will be the displayed time
	# Due to bluetooth transit time, the value
	# may be slightly different than displayed
        print('elapsed time:',scale.get_elapsed_time())

    # Tare the scale
    scale.tare()

    # Control the timer
    scale.startTimer()
    time.sleep(2)
    scale.stopTimer()
    scale.resetTimer()

    #read and print the weight every 0.5 sec for 5 sec 
    for i in range(10):
        print scale.weight # this is the property we can use to read the weigth in realtime
        time.sleep(0.5)
	# check if the scale is still connected, perhaps it was turned off?
	if not scale.connected:
	    break

    scale.disconnect()

Pyacaia now calls bluepy's Peripheral.waitForNotifications() internally. If your application uses waitForNotications() directly with 0.3.0 or earlier, that call should be removed.

By default the backend used is bluepy, but also pygatt is supported. In that case use:

scale=AcaiaScale(mac='00:1C:97:17:FD:97',backend='pygatt')

3. Other functions that may be helpful

Find and list all the acaia scales that are on and in range

addresses=find_acaia_devices()

Print BLE charachteristic of the first available acaia in the list of addresses

if addresses:
        print_acaia_characteristics(addresses[0])
    else:
        print 'No Acaia devices found'

pyacaia's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pyacaia's Issues

scale weight rollover

I'm seeing the value of scale.weight roll over back to 0 every ~650g. This happens both in positive and negative directions.

Same behavior on raspi zero w and pi 4. Same behavior on bluepy and pygatt. This is on a lunar scale. The weight from this scale does transmit correctly on a couple different mobile apps I tested.

Acaia Pearl shows up as PROCHBT001 in bluetooth devices

find_acaia_devices fails to find my Acaia Pearl because it shows up as "PROCHBT001" ... I'm not sure why this is, since I suppose yours appears as "ACAIA...", and the support documents from Acaia say it should show up as "Pearl". In any case, my Acaia android app seems to identify and auto-connect with it correctly despite its name.

Fellow Stagg EKG+ support?

Basically title. I know that the Stagg EKG+ works with Acacia Brewbar, but I have no idea if it's even remotely the same under the hood.

Pyxis scale has different API

I have done some work to figure out the new API on the Pyxis scale; most of the changes are related to UUIDs. Are you still maintaining pyacaia? I could submit a PR, but I've done all the work in bluepy and don't really want to replicate in pygatt - my first attempt at pygatt installation was not successful.

GATT question

Hi, I'm looking at this code to try and port similar functionality (interacting with a Pearl scale) to an ESP32 microcontroller.

I see your code doesn't involve any service uuids, but only characteristic uuids. I also notice that the scale does not advertise service uuids, and I am not sure how to subscribe to a characteristic without the corresponding service uuid.

Example arduino code for connecting to a BLE device looks like this:

    BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
    if (pRemoteService == nullptr) {
      Serial.print("Failed to find our service UUID: ");
      Serial.println(serviceUUID.toString().c_str());
      pClient->disconnect();
      return false;
    }
    Serial.println(" - Found our service");


    // Obtain a reference to the characteristic in the service of the remote BLE server.
    pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
    if (pRemoteCharacteristic == nullptr) {
      Serial.print("Failed to find our characteristic UUID: ");
      Serial.println(charUUID.toString().c_str());
      pClient->disconnect();
      return false;
    }
    Serial.println(" - Found our characteristic");

    // Read the value of the characteristic.
    if(pRemoteCharacteristic->canRead()) {
      std::string value = pRemoteCharacteristic->readValue();
      Serial.print("The characteristic value was: ");
      Serial.println(value.c_str());
    }

    if(pRemoteCharacteristic->canNotify())
      pRemoteCharacteristic->registerForNotify(notifyCallback);

Do you have any pointers for how to connect without the service uuid here?

thanks for the project

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.