Skip to content

jonnybergdahl/Python-growcube-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-growcube-client

PyPI version PyPI pyversions PyPI license

This is an asyncio Python library to communicate with Elecrow GrowCube devices. By using this library you can communicate directly with the device, without the need to use the phone app.

Once connected to a device, the library will listen for messages from the device and use a callback function to return parsed messages to the application. The application can also send commands to the device.

Installation

pip install growcube-client

Getting started

The src/growcube_sample.py file shows how to use the library. It defines a callback function where the GrowcubeClient sends messages as they arrive from the Growcube device. To use the sample, change the HOST variable to the host name or IP address of the Growcube device. Then run the sample with:

python3 growcube_sample.py

Source code:

import asyncio
from growcube_client import GrowcubeReport, GrowcubeClient


# Define a callback function to print messages to the screen
def callback(report: GrowcubeReport) -> None:
    # Just dump the message to the console
    print(f"Received: {report.get_description()}")


async def main(host: str) -> None:
    # Create a client instance
    client = GrowcubeClient(host, callback)
    print(f"Connecting to Growcube at {HOST}")

    # Connect to the Growcube and start listening for messages
    await client.connect()

    while True:
        await asyncio.sleep(2)

if __name__ == "__main__":
    # Set host name or IP address
    HOST = "172.30.2.72"

    asyncio.run(main(HOST))

Sample script output.

Connecting to Growcube at 172.30.2.70
Received: RepDeviceVersionCmd: version 3.6, device_id 12663500
Received: RepLockstateCmd: lock_state False
Received: RepWaterStateCmd: water_warning: True
Received: RepSTHSateCmd: pump: 0, moisture: 26, humidity: 41, temperature: 24
Received: RepSTHSateCmd: pump: 1, moisture: 26, humidity: 41, temperature: 24
Received: RepSTHSateCmd: pump: 2, moisture: 30, humidity: 41, temperature: 24
Received: RepSTHSateCmd: pump: 3, moisture: 33, humidity: 41, temperature: 24

More advanced use

The src/growcube_app.py file shows how to use the library in a more advanced application.

To use the app, you need to install wxPython first, please follow the directions here.

Start the app with:

python3 growcube_app.py

You are greeted with a screen asking for the host name or IP address of the Growcube device. Enter that and click the Submit button. The app will connect to your Growcube and starts displaying received data.

You can water plants by setting a watering duration and clicking the Pump X button.

Growcube app page 1

Auto discovery

You can use the sample script src/growcube_discover.py to search for devices on your network. By default, it will search for devices on the local network, but if the devices are located in a separate subnet you can also specify that network to search in.

python3 growcube_discover.py 192.168.4.0/24

The output will look like this.

Discovering Growcube clients on subnet 172.30.2.0/24
Trying to connect to 172.30.2.1
Trying to connect to 172.30.2.2
...
Trying to connect to 172.30.2.254
Found 2 devices:
Found device: 172.30.2.71
Found device: 172.30.2.70

About

Python library for communication with Growcube devices

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published