-
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
200 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
|
||
MAGIC=$(printf "\xe9") | ||
|
||
while true; do | ||
echo | ||
echo "Available options:" | ||
echo " 0) return to stock" | ||
index=0 | ||
for file in ../files/*.bin; do | ||
# skip null glob | ||
[[ -e $file ]] || continue | ||
# get short name | ||
filename=$(basename "$file") | ||
# skip files too large or too small | ||
filesize=$(stat -c%s "$file") | ||
[[ "$filesize" -gt 0x1000 && "$filesize" -le 0x80000 ]] || continue | ||
# skip files without magic byte | ||
[[ $(head -c 1 "$file") == "$MAGIC" ]] || continue | ||
echo " $((++index))) flash $filename" | ||
options[$index]="$filename" | ||
# only show first 9 options, accessible with a single keypress | ||
if (( index == 9 )); then | ||
break | ||
fi | ||
done | ||
echo " q) quit; do nothing" | ||
echo -n "Please select 0-$index: " | ||
while true; do | ||
read -n 1 -r | ||
echo | ||
if [[ "$REPLY" =~ ^[0-9]$ && "$REPLY" -ge 0 && "$REPLY" -le $index ]]; then | ||
break | ||
fi | ||
if [[ "$REPLY" =~ ^[Qq]$ ]]; then | ||
echo "Leaving device as is..." | ||
exit | ||
fi | ||
echo -n "Invalid selection, please select 0-$index: " | ||
done | ||
|
||
if [[ "$REPLY" == 0 ]]; then | ||
if curl -s http://10.42.42.42/undo; then | ||
echo "Disconnect the device to prevent it from repeating the upgrade" | ||
echo "You will need to put the device back into pairing mode and register to use again" | ||
else | ||
echo "Could not reach the device!" | ||
fi | ||
break | ||
fi | ||
|
||
selection="${options[$REPLY]}" | ||
read -p "Are you sure you want to flash $selection? This is the point of no return [y/N] " -n 1 -r | ||
echo | ||
[[ "$REPLY" =~ ^[Yy]$ ]] || continue | ||
|
||
echo "Attempting to flash $selection, this may take a few seconds..." | ||
RESULT=$(curl -s "http://10.42.42.42/flash?url=http://10.42.42.1/files/$selection") || | ||
echo "Could not reach the device!" | ||
|
||
echo "$RESULT" | ||
if [[ "$RESULT" =~ failed || -z "$RESULT" ]]; then | ||
read -p "Do you want to try something else? [y/N] " -n 1 -r | ||
echo | ||
[[ "$REPLY" =~ ^[Yy]$ ]] || break | ||
else | ||
if [[ "$selection" == "tasmota.bin" ]]; then | ||
echo "Look for a tasmota-xxxx SSID to which you can connect and configure" | ||
echo "Be sure to configure your device for proper function!" | ||
elif [[ "$selection" == "espurna.bin" ]]; then | ||
echo "Look for an ESPURNA-XXXXXX SSID to which you can connect and configure" | ||
echo "Default password is \"fibonacci\"" | ||
echo "Be sure to upgrade to your device specific firmware for proper function!" | ||
fi | ||
echo | ||
echo "HAVE FUN!" | ||
break | ||
fi | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
# encoding: utf-8 | ||
""" | ||
tuya-discovery.py | ||
Created by kueblc on 2019-11-13. | ||
Discover Tuya devices on the LAN via UDP broadcast | ||
""" | ||
|
||
import asyncio | ||
import json | ||
|
||
from Crypto.Cipher import AES | ||
pad = lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16) | ||
unpad = lambda s: s[:-ord(s[len(s) - 1:])] | ||
encrypt = lambda msg, key: AES.new(key, AES.MODE_ECB).encrypt(pad(msg)) | ||
decrypt = lambda msg, key: unpad(AES.new(key, AES.MODE_ECB).decrypt(msg)) | ||
|
||
from hashlib import md5 | ||
udpkey = md5(b"yGAdlopoPVldABfn").digest() | ||
decrypt_udp = lambda msg: decrypt(msg, udpkey) | ||
|
||
class TuyaDiscovery(asyncio.DatagramProtocol): | ||
def datagram_received(self, data, addr): | ||
# remove message frame | ||
data = data[20:-8] | ||
# decrypt if encrypted | ||
try: | ||
data = decrypt_udp(data) | ||
except: | ||
pass | ||
# parse json | ||
try: | ||
data = json.loads(data) | ||
except: | ||
pass | ||
print(addr[0], data) | ||
|
||
def main(): | ||
loop = asyncio.get_event_loop() | ||
listener = loop.create_datagram_endpoint(TuyaDiscovery, local_addr=('0.0.0.0', 6666)) | ||
encrypted_listener = loop.create_datagram_endpoint(TuyaDiscovery, local_addr=('0.0.0.0', 6667)) | ||
loop.run_until_complete(listener) | ||
print("Listening for Tuya broadcast on UDP 6666") | ||
loop.run_until_complete(encrypted_listener) | ||
print("Listening for encrypted Tuya broadcast on UDP 6667") | ||
try: | ||
loop.run_forever() | ||
except KeyboardInterrupt: | ||
loop.stop() | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.