Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password Support? #28

Open
alexanderloy opened this issue Sep 23, 2021 · 5 comments
Open

Password Support? #28

alexanderloy opened this issue Sep 23, 2021 · 5 comments

Comments

@alexanderloy
Copy link

Switchbot allows you to set a Password, could you add this so a password can be used?

@devWaves
Copy link

devWaves commented Sep 23, 2021

if you want to use password you can make some minor code change to the python code

Example password = 'testpassword'

Steps

  1. get the CRC32 4 byte hexadecimal value for your password ( you can use an online tool like this https://crc32.online/)
  2. testpassword = 9dcb7360
  3. Modify this part of the code ....
if act == 'Turn On':
	con.sendline('char-write-cmd ' + cmd_handle + ' 570101')
elif act == 'Turn Off':
	con.sendline('char-write-cmd ' + cmd_handle + ' 570102')
elif act == 'Press':
	con.sendline('char-write-cmd ' + cmd_handle + ' 570100')

to this...

if act == 'Turn On':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360' +'01')
elif act == 'Turn Off':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360' +'02')
elif act == 'Press':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360')

@spinachpasta
Copy link

spinachpasta commented Nov 3, 2021

https://github.com/devWaves/SwitchBot-MQTT-BLE-ESP32/blob/6276427803756c1f0b98bf3e9d8c8da78d048ad7/Arduino%20IDE%20Files/SwitchBot-BLE2MQTT-ESP32.ino#L689-L695

static byte bArrayPressPass[] = {0x57, 0x11, NULL, NULL, NULL, NULL};
static byte bArrayOnPass[] = {0x57, 0x11, NULL , NULL, NULL, NULL, 0x01};
static byte bArrayOffPass[] = {0x57, 0x11, NULL, NULL, NULL, NULL, 0x02};
static byte bArrayGetSettingsPass[] = {0x57, 0x12, NULL, NULL, NULL, NULL};
static byte bArrayHoldSecsPass[] = {0x57, 0x1F, NULL, NULL, NULL, NULL, 0x08, NULL };
//static byte bArrayBotModePass[] = {0x57, 0x13, 0x64, NULL, NULL, NULL, NULL, NULL};     // Other github documentation shows this to be the array for setting mode with password (firmware 4.5, 4.6)
static byte bArrayBotModePass[] = {0x57, 0x13, NULL, NULL, NULL, NULL, 0x64, NULL};       // The proper array to use for setting mode with password (firmware 4.9)

These implementations from SwitchBot-MQTT-BLE-ESP32 suggests that second bit should be 0x11 not 0x01 when controlling bots with password.
I only tested press signal, but other implementation seems plausible.

Thus, the correct code should be the following:(I haven't tested the python implementation yet. Tell me if this is wrong)

if act == 'Turn On':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360' +'01')
elif act == 'Turn Off':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360' +'02')
elif act == 'Press':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360')

@devWaves
Copy link

devWaves commented Nov 3, 2021

https://github.com/devWaves/SwitchBot-MQTT-BLE-ESP32/blob/6276427803756c1f0b98bf3e9d8c8da78d048ad7/Arduino%20IDE%20Files/SwitchBot-BLE2MQTT-ESP32.ino#L689-L695

static byte bArrayPressPass[] = {0x57, 0x11, NULL, NULL, NULL, NULL};
static byte bArrayOnPass[] = {0x57, 0x11, NULL , NULL, NULL, NULL, 0x01};
static byte bArrayOffPass[] = {0x57, 0x11, NULL, NULL, NULL, NULL, 0x02};
static byte bArrayGetSettingsPass[] = {0x57, 0x12, NULL, NULL, NULL, NULL};
static byte bArrayHoldSecsPass[] = {0x57, 0x1F, NULL, NULL, NULL, NULL, 0x08, NULL };
//static byte bArrayBotModePass[] = {0x57, 0x13, 0x64, NULL, NULL, NULL, NULL, NULL};     // Other github documentation shows this to be the array for setting mode with password (firmware 4.5, 4.6)
static byte bArrayBotModePass[] = {0x57, 0x13, NULL, NULL, NULL, NULL, 0x64, NULL};       // The proper array to use for setting mode with password (firmware 4.9)

These implementations from SwitchBot-MQTT-BLE-ESP32 suggests that second bit should be 0x11 not 0x01 when controlling bots with password. I only tested press signal, but other implementation seems plausible.

Thus, the correct code should be the following:(I haven't tested the python implementation yet. Tell me if this is wrong)

if act == 'Turn On':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360' +'01')
elif act == 'Turn Off':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360' +'02')
elif act == 'Press':
	con.sendline('char-write-cmd ' + cmd_handle + ' 5711' + '9dcb7360')

yep, my bad. should be 11 not 01

That small change also assumes you use the same password for all bots

@donavanbecker
Copy link
Collaborator

@spinachpasta @devWaves If you would like to submit a PR, you can.

@devWaves
Copy link

devWaves commented Nov 4, 2021

@donavanbecker I'm not using this implementation since I use my ESP32 code, I just happen to be browsing and mentioned a quick fix

The sample I provided would overwrite the default no-password option and isn't setup for dynamics password so it would take a bit more work for a full PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants