Thrilleratplay / GoveeWatcher

Proof of concept bluetooth broadcast decoder from Govee Thermometer/Hygrometers
MIT License
63 stars 14 forks source link

Attempting this on Raspberry Pi #1

Open CaptBeard opened 4 years ago

CaptBeard commented 4 years ago

Thanks for making this POC. I'm in the process of trying to make something to read my two Govee devices and then port that to home bridge.

I'm having an issue getting this to run on my rPi. I ran it with debug on and I'm getting this:

[ '', undefined, index: 0, input: 'Waiting to connect to bluetoothd...', groups: undefined ] Waiting to connect to bluetoothd... [ '', undefined, index: 0, input: '[bluetooth]# [NEW] Controller B8:27:EB:FA:38:19 rpi [default]\n[bluetooth]# ', groups: undefined ] [bluetooth]# [NEW] Controller B8:27:EB:FA:38:19 rpi [default] [bluetooth]#

Looks like it freezes after it turns on the BT controller.

Any help? TIA

Thrilleratplay commented 4 years ago

@CaptBeard I have been working on trying to turn this work into a Home Assistant custom component and what I have been finding is bluetooth low energy has varying levels of support. I am guessing that is output from the nodeJS version, which basically creates a shell with the command bluetoothctl scan on then scrapes and parses the output. Again, this is a proof of concept and kinda assumes things will work. If you run that command in a terminal, the output should be something like:

$> bluetoothctl scan on  

Discovery started
[CHG] Controller B8:27:EB:FA:38:19 Discovering: yes
[NEW] Device A4:C1:38:UV:WX:YZ GVH5075_WXYZ
<TIME PASSES.....WAITING....WAITING....10-30seconds later>
[CHG] Device A4:C1:38:UV:WX:YZ ManufacturerData Key: 0xec88
[CHG] Device A4:C1:38:UV:WX:YZ ManufacturerData Value:
  00 02 fe a6 60 00                                ....`.          
[CHG] Device A4:C1:38:UV:WX:YZ ManufacturerData Key: 0x004c
[CHG] Device A4:C1:38:UV:WX:YZ ManufacturerData Value:
  02 15 49 4e 54 45 4c 4c 49 5f 52 4f 43 4b 53 5f  ..INTELLI_ROCKS_
  48 57 50 75 f2 ff c2                             HWPu...  

Based on what I am reading, you may need to restart the bluetooth service or the user does not have bluetooth permissions. It is also possible that the formatting is different between versions or, most likely, I messed something up. Let me know if the output looks of bluetoothctl scan on looks similar.

CaptBeard commented 4 years ago

@Thrilleratplay It looks like it sort of works on the pi. I can see results from a bluetoothctl scan, then your node app will run. I stops every so many lines and I have to quit and re-run to see more data. I never gets to the point where it parses my Govee devices.

$> node index.js
[ '',
  undefined,
  index: 0,
  input: 'Waiting to connect to bluetoothd...',
  groups: undefined ]
Waiting to connect to bluetoothd...
Found: FF:D7:D0:E2:0C:55 (N01GF)
[bluetooth]# [NEW] Controller B8:27:EB:FA:38:19 rpi [default]
[bluetooth]# [NEW] Device 4F:4C:10:19:13:9C 4F-4C-10-19-13-9C
[bluetooth]# [NEW] Device E0:12:1D:60:E8:93 Govee_H5074_E893
[bluetooth]# [NEW] Device 37:B3:71:98:73:3A 37-B3-71-98-73-3A
[bluetooth]# [NEW] Device 7C:F2:A4:95:FC:83 7C-F2-A4-95-FC-83
[bluetooth]# [NEW] Device 44:4D:EA:D6:94:DD 44-4D-EA-D6-94-DD
[bluetooth]# [NEW] Device 5D:04:8E:ED:E3:75 5D-04-8E-ED-E3-75
[bluetooth]# [NEW] Device 4A:4A:32:DB:E8:A2 4A-4A-32-DB-E8-A2
[bluetooth]# [NEW] Device 90:DD:5D:F1:AB:C1 90-DD-5D-F1-AB-C1
[bluetooth]# [NEW] Device 88:63:DF:CF:6B:1A 88-63-DF-CF-6B-1A
[bluetooth]# [NEW] Device 18:83:29:30:49:AC 18-83-29-30-49-AC
[bluetooth]# [NEW] Device 28:1B:4E:19:DD:D1 28-1B-4E-19-DD-D1
[bluetooth]# [NEW] Device 66:4C:96:D8:29:02 66-4C-96-D8-29-02
[bluetooth]# [NEW] Device 46:28:16:91:C6:88 46-28-16-91-C6-88
[bluetooth]# 
Found: 78:9C:85:09:0D:E3 (M102EDG)
[NEW] Device AC:BC:32:73:9E:0C AC-BC-32-73-9E-0C
[bluetooth]# [NEW] Device 30:C2:03:15:37:76 30-C2-03-15-37-76
[bluetooth]# [NEW] Device 6A:98:36:5B:17:98 6A-98-36-5B-17-98
[bluetooth]# 
[ '',
  undefined,
  index: 0,
  input: '[NEW] Device 44:F4:CF:46:AD:1B 44-F4-CF-46-AD-1B\n[bluetooth]# [NEW] Device 3E:0A:5A:AF:28:8C 3E-0A-5A-AF-28-8C\n[bluetooth]# ',
  groups: undefined ]
[NEW] Device 44:F4:CF:46:AD:1B 44-F4-CF-46-AD-1B
[bluetooth]# [NEW] Device 3E:0A:5A:AF:28:8C 3E-0A-5A-AF-28-8C
[bluetooth]# 
Found: E3:37:3C:C0:D5:0C (Govee_H5074_D50C)
[NEW] Device E3:37:3C:C0:D5:0C Govee_H5074_D50C
[bluetooth]# 

This is where it stops and I have to break it and run again.

Thrilleratplay commented 4 years ago

I think I see what the issue is. The output is different and regular expression does not take into account lines starting with " [bluetooth]# ". The easier way to work around this would be on line 47 of index.js to remove that string in the sanitize function. It would look something like:

const sanitize = (str) => ransi(str).replace(/\[bluetooth\]\# /g, '').replace(/\u0001\u0002/g, '').replace(/\r/g, '');

That may take some tweaking as I haven't tested it. Currently I am busy at work and will not have time to test this on any of my pi's for a while. I hope this helps in the meantime.

Additionally, make sure you run bluetoothctl scan off before running node index.js as not to cross the streams.