Skip to content

Instantly share code, notes, and snippets.

@nehayward
Created January 26, 2020 23:56
Show Gist options
  • Save nehayward/28e5f4e3d22b2104b1f0203ee225fb2a to your computer and use it in GitHub Desktop.
Save nehayward/28e5f4e3d22b2104b1f0203ee225fb2a to your computer and use it in GitHub Desktop.
Fellow Stagg EKG+ Bluetooth control with gatttool
set action [lindex $argv 0];
set temp [lindex $argv 1];
set on "efdd0a0000010100"
set off "efdd0a0100000100"
set writeCommand "char-write-cmd 0x000d"
spawn gatttool -b 00:1C:97:16:27:13 -I
sleep 3
set timeout -1
send -- "connect\r"
expect "Connection successful"
send -- "char-write-req 0x000e 0100\r"
expect "Characteristic value was written successfully"
send -- "char-write-cmd 0x000d efdd0b3031323334353637383930313233349a6d\r"
if { $action == "on"} {
send -- "$writeCommand $on\r"
} elseif { $action == "off"} {
send -- "$writeCommand $off\r"
} elseif { $action == "set"} {
set tempInHexidecimal [format %x $temp]
set checkSum [format %x [expr {$temp + 02}]]
set tempCommand "efdd0a0201${tempInHexidecimal}${checkSum}01"
send -- "$writeCommand $tempCommand\r"
}
send -- "exit\r"
expect eof
@tlyakhov
Copy link

Very compact shell script haha! glad you got it working, looks right to me from a control standpoint, though in a real app you will need to increment a sequence number (byte 3) once a connection is established. Also curious - from your wireshark investigation, is that first magic "init" string the same for your kettle?

@nehayward
Copy link
Author

nehayward commented Jan 27, 2020

Yup haha I need to write it in node now for HomeKit so more just prototyping.

Yeah since I open and close it each time it’s okay for right now. But your break down of the byte array helped a lot. Thanks 🙏

Yeah it is same. I was also wondering what your Bluetooth name is? So then I could abstract the MAC address part away potentially.

@tlyakhov
Copy link

I don't check for MAC/device name actually, My code just looks for any device that reports the right BLE service & characteristic UUIDs. That said, my kettle's reported device name is FELLOW82E1 and MAC address is 00:1c:97:18:82:e1, reported in Wireshark as EnzytekT_18:82:e1.

@nehayward
Copy link
Author

Oh that's clever I like that solution. I'll give that a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment