Coder Social home page Coder Social logo

govee-gateway's Introduction

govee-gateway

GitHub last commit Top language Language count Issues CodeFactor Grade

A BLE Gateway to MQTT/InfluxDB for Govee H5074 temperature sensors.

title

General info

The Govee Gateway is built based on my govee-ble-scanner (https://github.com/w1gx/govee-ble-scanner). It uses a HCI connection to scan for packets of type HCI_EVENT_PKT (04) with event types of EVT_LE_META_EVENT and extracts all advertising data from them. It then looks for AD type identifiers of 0xFF (manufacturer data), and within those for the company identifier 0x88EC, which contain the encoded temperature and humidity.For more detail about this process please refer to the wiki of the govee-ble-scanner and the Bluetooth Core Specification at https://www.bluetooth.com/specifications/bluetooth-core-specification/. Depending on the configuration, the Govee Gateway sends temperature and humidity data in configurable intervals to MQTT and/or InfluxDB.

Technology

The Govee BLE Gateway is written in C++ and tested on Raspberry Pis. Besides the standard libraries, it requires libbluetooth and - if MQTT is required - paho.mqtt.cpp.

It uses the following modules:

Setup

Prerequisites

The Govee Gateway can be installed with MQTT assistance, in which case the paho-mqtt-cpp library must be installed. Please follow the steps as described at https://github.com/eclipse/paho.mqtt.cpp. In any case, the following needs to be installed:

sudo apt-get install bluetooth bluez libbluetooth-dev

Make

The application can be built with or without mqtt support.

make without mqtt support:

make release

make with mqtt support

make release MQTT=1

generating doxygen documentation

sudo apt-get install doxygen graphviz
make doc

making the deb package

After making the release file, run the following

make deb

The deb file is in ./deb/govee-gateway.deb. To install it, run

sudo apt-get install ./deb/govee-gateway.deb

The status can then be checked within

sudo service govee-gateway status

Configuration

The system can be configured in a config file, which is located in the root of the project folder. The config file can be passed on via command line parameters (see below). It contains the MQTT and InfluxDB configuration. If a host field is left empty, logging will be disabled for the section.

; Configuration file for govee-gateway

[system]
verbosity = 1                   ;; 0=none, 1=show temp readings, 2=show BLE packets, 3=show BLE detail
logInterval = 30                ;; log interval in seconds (logging to MQTT/InfluxDB)

[mqtt]
host = localhost:1883
username =
password =
topic = govee

[influxdb]
host = 127.0.0.1
port = 8086
username =
password =
database = goveeDB
measurement = govee

[AddressMap]
E3:8E:C8:xx:xx:xx = SOMENAME    ; Family room
E3:60:58:yy:yy:yy = SOMENAME2   ; Master bedroom

The InfluxDB database must already exists, the Govee Gateway does not create databases. Also, all data is logged to mqtt (if enabled), but only data from devices that are mapped in the "AddressMap" section are logged to InfluxDB.

Running the application

from the command line

sudo ./deb/govee-gateway/usr/local/bin/govee-gateway

Usage: ./build/release/govee-gateway [options]
Options:
	-h | --help               print this message
	-c | --config <file>      path to the config file
	-i | --interval <seconds> reporting interval in seconds
	-v | --verbosity <level>  debug level

The command line options override the parameters in the config file.

as a service

If the gateway has been installed as a service (see above), the system starts it automatically.

Starting the service: sudo service govee-gateway start

Stopping the service sudo service govee-gateway stop

Note that when you run the application as a service, the configuration file in /etc (/etc/govee-gateway.conf) will be used.

Console Output

The console output depends on the verbosity level selected (see above). A higher verbosity level can help in identifying problems with sensors and packet decoding.

Level 0: No Output

Level 1: only measurements verbosity1

Level 2: BLE packets verbosity2

Level 3: BLE details verbosity3

Status

At this point the system does what I need, although I am not hundred percent confident that the battery status field is really correct. Since there is no official documentation, all I can do is monitor it, and potentially come back and correct it.

govee-gateway's People

Contributors

w1gx avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

govee-gateway's Issues

Data to InfluxDB only when running in terminal

I’ve got the program working for the most part, but can’t get it to continue to send data from my sensors to the InfluxDB.

The service shows to be running…

pi@HomePi:/ $ sudo service govee-gateway status

  • govee-gateway.service - govee-gateway service
    Loaded: loaded (/usr/local/lib/systemd/system/govee-gateway.service; enabled; vendor preset: enabled)
    Active: active (running) since Thu 2022-10-27 22:20:39 MDT; 15h ago
    Main PID: 3985 (govee-gateway)
    Tasks: 1 (limit: 4915)
    CPU: 14h 29min 52.694s
    CGroup: /system.slice/govee-gateway.service
    `-3985 /usr/local/bin/govee-gateway

Oct 27 22:20:39 HomePi systemd[1]: Started govee-gateway service.

…but the only time it sends data to InfluxDB is if I start it in the terminal, passing along the .conf file via command line parameters (which only works from within the govee-gateway directory). As soon as the terminal quits, so does saving data to Influx.

What am I missing here?

P.S. Also, what does the MA=2 signify?

Thank, Bill J

pi@HomePi:~/govee-gateway $ sudo ./deb/govee-gateway/usr/local/bin/govee-gateway ./build/release/govee-gateway -c /home/pi/govee-gateway/govee-gateway.conf

config is /home/pi/govee-gateway/govee-gateway.conf
Address mapping: E3:60:58:E0:A4:6E mapped to BASEMENT
Address mapping: E3:5E:CC:70:38:B7 mapped to CAMPER GALLEY
Address mapping: E3:5E:CC:70:FC:88 mapped to CHILLY BIN
Address mapping: E3:5E:CC:73:60:60 mapped to FREEZER
Checking connections...
InfluxDB host is 10.0.1.110... ok.
running...
Data logged. Queue#: 1. GOVEE E3:60:58:E0:A4:6E - Temp=18.70C (65.66F), Hum=29.65%, Bat=94%, RSSI= -51dBm, MA=2
Data logged. Queue#: 1. GOVEE E3:5E:CC:73:60:60 - Temp=-17.22C (1.00F), Hum=77.29%, Bat=63%, RSSI= -67dBm, MA=2
Data logged. Queue#: 1. GOVEE E3:5E:CC:70:38:B7 - Temp=19.11C (66.40F), Hum=27.69%, Bat=100%, RSSI= -71dBm, MA=2
Data logged. Queue#: 1. GOVEE E3:5E:CC:70:FC:88 - Temp=15.87C (60.57F), Hum=28.70%, Bat=78%, RSSI= -63dBm, MA=2

Lots of CPU

Running on RaspberryPi 3 B+, pulling from three Govee thermohygrometers, and writing into local Influx every 90 seconds.

govee-gateway CPU percentage is like 60%, even when I nice it way up to like 19.
It never goes into sleep. Am I doing something wrong or is this intended behavior?

Screenshot 2021-06-06 204500

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.