Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Latest commit

 

History

History
130 lines (80 loc) · 5.77 KB

overview.md

File metadata and controls

130 lines (80 loc) · 5.77 KB

Goal

  • Get an email when my plants need water and/or fertilizer.
  • Make my plants happy.
  • Collect some data for the sake of data colleciton.

Architecture

The basic idea for the plantgateway is to read the sensor data from the Xiaomi Mi plant sensors via Bluetooth LE and send it via MQTT to the home automation server.

architecture

This should help to word around the limited range of Bluetooth LE. It will also allow to collect the sensor data from different location in one single home automation system.

Hardware

Here's the list of hardware components I'm using.

Sensors

I'm using the Xiaomi Mi plant sensors. The cost about 12 EUR when ordering from China.

Note: If you order it from China, you might have to pay for import tax.

Sensor

Features:

  • Bluetooth LE interface
  • integrated coin cell battery, should last a year
  • It can measure these values
    • moisture in %
    • conductivity in us/cm (which is somehow related to fertilizer)
    • temperature in °C
    • brightness in lux
  • security
    • None.
    • Seariously, none.
    • Really anyone in range can read the sensors.

Bluetooth LE adapter

For the machines that do not have an integrated Bluetooth LE adapter, I'm using a [LogiLink BT0015 USB bluetooth V4.0 EDR Class1 Micro](https://www.amazon.de/gp/product/B0096Y2HFW/ref=ox_sc_act_title_2?ie=UTF8&psc=1&smid=A3JWKAKR8XB7XF Gateway). But basically any Bluetooth LE adapter that is supported by the linux kernel should do.

Gateway

Since the range of Bluetooth LE is quite limited. In my apartment the range is about 5 meters and might go through one wall if I'm lucky. So I need some gateway near the sensors.

In my current solution I'm using a Rasberry Pi to read the sensor data via Bluetooth LE.

In my planned solution I want to use a C.H.I.P to do the same thing in a smaller and cheaper way.

  • ARM chip, runs Linux
  • Has WiFi and Bluetooth LE integrated
  • Costs only 9 $
  • But these devices out of stock at the moment, so I'll have to wait

Home Automation server

Use whatever you want, I have a Turris Omnia router running OpenWRT.

Software

And this is the software setup for the hardeware mentioned above.

plantgateway

The plantgateway (this project) reads the sensor data via Bluetooth LE and sends it via MQTT to the home automation server.

Home Automation solution

I'm running Home Assistant on Alpine Linux inside a LXC container. Alpine Linux has a very small footprint and is well suited to be used in containers.

About Home Assistant:

  • Like:
    • Python based
    • Many plugins available
    • Easier to set up and maintain than FHEM (what I used before)
    • does what it's supposed to do
  • Dislike:
    • no real complaints so far...

There is now the component plant monitor available as part of Home Assistant. It will monitor the status of your plants and you can trigger notifications in case of problems.

MQTT server

I'm using mosquitto, again running on Alpine Linux inside a LXC container)

Security:

  • available as package in Alpine Linux
  • authentication via username and password
  • TLS encryption, based on certificates from Let's Encrypt
    • The ACME client is also available as package on Alpine Linux and works out of the box
  • remark: some MQTT clients (e.g. from FHEM) do not support client certificates, but all do support TLS and username/password

If you are running MQTT for critical applications, you might want to monitor the MQTT server from Nagios/Icinga2.

Devleopment tools / libraries

To help with the devleopment I can recommend these tools:

Debugging MQTT

To debug mqtt related things, I'm using MQTT.fx. This tool allows you to send and receive messages via MQTT. It helps to figure out, if you really did what you wanted to do.

reverse engineering the bluetooth communication

You can reverse engieer the protocol by just watching the Xiaomi Plant app:

  1. Enable the Bluetooth HCI logging on your phone (On your Android phone go to settings -> developer options -> enable bluetooth HCI logging)
  2. Install and run the Flower care App and perform the operations you want to reverse engineer.
  3. Download the /sdcard/hci.log file from the phone to a PC
  4. Open the log file in Wireshark and guess what's going on
  5. Implement the operations yourself to see if you got the right commands
  6. Then implement a nice API around that for everyone to use and publish it :)

A lot of valueable information about the sensor and the protocol can be found here in this blog post.

bluepy

For the communication via Bluetooth LE I'm using bluepy. It offers access to the GATT protocol in a straight forward way. This is much more convenient than writing a command line wrapper for the linux command gatttool.

paho-mqtt

For the communication with the MQTT server there is also a very convenient library for python: paho-mqtt It also offers a very easy solution for publishing data.