Skip to content

Release v2.1.0 #331

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

Merged
merged 60 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
c772997
Fix for #138
PeteLawler May 15, 2019
fcbb350
Added option for specifying the server bind addr, defaulting to 10.42…
kueblc Jul 2, 2019
0e7c1f0
Modify dnsmasq config to only bind to 10.42.42.1 as suggested in #187
kueblc Jul 2, 2019
48bdc07
Added config for mosquitto so it only binds to 10.42.42.1
kueblc Jul 2, 2019
9c8db57
Added a check to ensure that the configured network interface exists
kueblc Jul 2, 2019
d11f94f
Backup hostapd config #61
kueblc Jul 2, 2019
54af5eb
Check for wpa_supplicant #19 #84 #172 #208 and many more
kueblc Jul 2, 2019
d754802
Added auto-retry to smartconfig, make 10 attempts before exiting
kueblc Jul 4, 2019
22bdbb5
Exit server cleanly on SIGINT (^C) to reduce error message noise
kueblc Jul 4, 2019
84ad972
User only needs to agree to the EULA once
kueblc Aug 7, 2019
3b1c5ed
Offer to flash another device, restarting the procedure automatically
kueblc Aug 7, 2019
e3b4982
Start and stop smart-config as a fork instead of a screen
kueblc Aug 7, 2019
497bedb
Add a delay after starting the AP to allow time for the network inter…
kueblc Aug 7, 2019
f345e18
Only print out smart config parameters once
kueblc Aug 7, 2019
b55299d
Clean up smartconfig and prompt user to retry if device fails to appe…
kueblc Aug 7, 2019
4b9b1a0
Download backups and info to a backup directory with timestamped subd…
kueblc Aug 7, 2019
a81da2b
Added backups folder to gitignore
kueblc Aug 7, 2019
4c3fba4
Increased timeout for devices to appear to ~60s
kueblc Aug 7, 2019
41df188
Ignore "flag files" from git
kueblc Aug 7, 2019
5114b1e
Merge branch 'master' into fix-net-inf
kueblc Sep 21, 2019
30a0b91
Merge branch 'repeat-smartconfig' into improve-flow
kueblc Sep 21, 2019
153c8ed
Start dnsmasq with command line options rather than a config file
kueblc Sep 26, 2019
5e773f0
Wait for AP to come online by pinging the gateway instead of sleep
kueblc Oct 2, 2019
0c3e2d8
Use pkill to find and cancel smartconfig process, both in start_flash…
kueblc Oct 2, 2019
a3010a0
Add newline after AP comes online
kueblc Oct 2, 2019
0b48aba
Merge branch 'master' into improve-flow
kueblc Oct 3, 2019
4b3138b
Use silent flag on curl instead of throwing stderr away
kueblc Oct 3, 2019
7acc711
Direct user to check log files only if the device did not reappear
kueblc Oct 3, 2019
0f8764f
Revert changes to mosquitto, apparently the config is not respected a…
kueblc Oct 3, 2019
e1126b8
Closing AP should be the last thing we do, as the other scripts are b…
kueblc Oct 3, 2019
4cc1e2e
Don't modify NetworkManager.conf, just stop NetworkManager temporarily
kueblc Oct 3, 2019
8d3de79
Merge branch 'master' into fix-net-inf
kueblc Oct 3, 2019
b4e893c
Removed ETH and added GATEWAY to config
kueblc Oct 3, 2019
5bd8e45
Wait for gateway to be available before starting web server et al
kueblc Oct 3, 2019
155dfda
Merge branch 'master' into fix-net-inf
kueblc Oct 4, 2019
ec789ad
Fix for #191 with thanks to @linusbarth
kueblc Oct 4, 2019
7d56bba
Merge branch 'master' into patch-1
kueblc Oct 4, 2019
7076363
Connect psk frontend to gateway instead of 0.0.0.0 to mitigate potent…
kueblc Oct 5, 2019
2fe5cd4
A simple dictionary to track activated ids, instead of a boilerplate …
kueblc Oct 5, 2019
d9a29ca
Merge branch 'improve-flow' into development
kueblc Oct 5, 2019
8b799fe
Merge branch 'fix-net-inf' into development
kueblc Oct 5, 2019
b8a50aa
Merge branch 'fix-191' into development
kueblc Oct 5, 2019
da75a2f
Merge branch 'simple-dict' into development
kueblc Oct 5, 2019
f721961
Change smartconfig notice, fixing typo
kueblc Oct 5, 2019
77503d6
Merge remote-tracking branch 'PeteLawler/patch-1' into development
kueblc Oct 5, 2019
69ea7d3
Added python-wheel for python2 package install, thanks to @ErwanMAS
kueblc Oct 6, 2019
ec43e49
Replace hardcoded gateway with supplied argument
kueblc Oct 10, 2019
60f2bad
Documenting ESPurna image
xoseperez Oct 10, 2019
688c9bb
Fix text type and revert whitespace changes
xoseperez Oct 10, 2019
504c4e2
ESPurna binary
xoseperez Oct 10, 2019
e3168b8
Remove hostapd.conf writer from setup_ap, and instead include a stati…
kueblc Oct 12, 2019
4bda03f
Remove mentions of password
kueblc Oct 12, 2019
5e3db7e
Added check for AP mode support
kueblc Oct 12, 2019
7d9dbae
Fix whitespace
kueblc Oct 12, 2019
8a9719d
Merge pull request #309 from xoseperez/espurna
kueblc Oct 12, 2019
ce30b6e
Merge branch 'fix-net-inf' into development
kueblc Oct 12, 2019
8eb7e25
Do not force an upgrade of existing packages on install, per #315
kueblc Oct 12, 2019
4f8e380
Merge branch 'no-pw' into development
kueblc Oct 14, 2019
8c5b4da
Organized setup_ap into three functions, check_config, setup, and cle…
kueblc Oct 14, 2019
e32199b
Merge branch 'master' into development
kueblc Oct 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ node_modules/
*.bin
device-info.txt
scripts/smartconfig/package-lock.json

# firmware backups directory
backups/

# flag files
eula_accepted

13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ On January 28th, 2019, Tuya started [distributing a patch](https://www.heise.de/
Follow the instructions in the start_flash script. It will install our flash loader onto the ESP and connect to the access point created by your wifi adapter.

WIFI: vtrust-flash
PASS: flashmeifyoucan
IP: 10.42.42.42
A backup of the original firmware will be created and stored locally

Expand Down Expand Up @@ -77,22 +76,26 @@ BE SURE THE FIRMWARE FITS YOUR DEVICE!

Currently a Tasmota [v6.5.0](https://github.com/arendst/Sonoff-Tasmota/releases/tag/v6.5.0) `sonoff-basic.bin` build is included. In this Tasmota firmware variant, many features and most sensors are disabled. Tasmota strongly recommendeds to update to a [current version](http://thehackbox.org/tasmota) of a "full featured" variant (e.g., `sonoff.bin`). This can be accomplished via OTA after the Tuya-Convert process completes successfully. Please note that while we include this for your convenience, we are not affliated with the Tasmota project and cannot provide support for post installation issues. Please refer to [the respective project](https://github.com/arendst/Sonoff-Tasmota) for configuration and support.

An ESPurna [1.13.5](https://github.com/xoseperez/espurna/releases/tag/1.13.5) binary is also included (`espurna-base.bin`). Like before, the binary included does not have any specific hardware defined. Once flashed using Tuya-Convert you can update to the device-specific version via any of the means that ESPurna provides (OTA, web interface update, update via telnet or MQTT). Please refer to the [ESPurna project page](http://espurna.io) for more info and support.

Binary requirements:
* full binary including first-stage bootloader
* maximum filesize 512KB for first flash

3. Start flashing process
2. Start flashing process

# curl http://10.42.42.42/flash3

Alternatively you can request a certain file to be requested and flashed by the device:
Alternatively you can request a certain file to be requested and flashed by the device:

# curl http://10.42.42.42/flash3?url=http://10.42.42.1/files/thirdparty.bin
# curl http://10.42.42.42/flash3?url=http://10.42.42.1/files/certain_file.bin

4. Initial Configuration
3. Initial Configuration

If you flashed the included Tasmota firmware file, it will broadcast a `sonoff-xxxx` access point (AP) when the device boots. Connect to this AP and open the browser to 192.168.4.1 to configure the device's Wi-Fi credentials. When entering the Wi-Fi password, click the checkbox to view the password you enter to ensure that it is correct and that your mobile device has not inadvertently capitalized the first letter if it is supposed to be lower case nor autocorrected what you entered. ~~Double~~ **Triple check the Wi-Fi credentials** before clicking **Save** to apply the settings.

If you flashed the included ESPurna fimaware file, the procedure will be very similar. The device will broadcast a `ESPURNA-XXXXXX` access point. You will have to connect to it using the default password: `fibonacci`. Once connected open the browser to 192.168.4.1 and follow the initial configuration instructions. Then go to the WIFI tab and configure your home WiFi connection (remember to save) or go to the ADMIN tab to upgrade the firmware to the device-specific image.

## CONTRIBUTING

This project is currently maintained by Colin Kuebler @kueblc
Expand Down
9 changes: 3 additions & 6 deletions config.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Please input the good wlan device (most of the time it is wlan0 or wlan1)
# Please input the wlan device to be used (most of the time it is wlan0 or wlan1)
WLAN=wlan0

# The ETH device should be connected to the internet but it should also work if it is a local network only
ETH=eth0

# Here you could change the WIFI-name and password but most likely most scripts won't work after
# Here you could change the WIFI-name but most likely most scripts won't work after
# Because the WIFI-credentials are hardcoded in the esp8266-ota-flash-convert
AP=vtrust-flash
PASS=flashmeifyoucan
GATEWAY=10.42.42.1
Binary file added files/espurna-base.bin
Binary file not shown.
17 changes: 13 additions & 4 deletions install_prereq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
set -e

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y dnsmasq hostapd screen curl python-pip python3-pip python-setuptools python3-setuptools python3-wheel python-dev python3-dev mosquitto haveged net-tools libssl-dev
sudo -H pip3 install paho-mqtt tornado git+https://github.com/M4dmartig4n/sslpsk.git pycrypto
sudo -H pip2 install git+https://github.com/M4dmartig4n/sslpsk.git pycrypto
sudo apt-get install -y dnsmasq hostapd screen curl python-pip python3-pip python-setuptools python3-setuptools python-wheel python3-wheel python-dev python3-dev mosquitto haveged net-tools libssl-dev

PY3_DEPENDENCIES="paho-mqtt pyaes tornado git+https://github.com/M4dmartig4n/sslpsk.git pycrypto"
PY2_DEPENDENCIES="git+https://github.com/M4dmartig4n/sslpsk.git pycrypto"

if python3 -c 'import sys; exit(0) if sys.version_info.major == 3 and sys.version_info.minor < 7 else exit(1)' ;
then
sudo -H pip3 install $PY3_DEPENDENCIES
sudo -H pip2 install $PY2_DEPENDENCIES
else
sudo -H python3 -m pip install $PY3_DEPENDENCIES
sudo -H python2 -m pip install $PY2_DEPENDENCIES
fi

echo "Ready to start upgrade"
72 changes: 39 additions & 33 deletions scripts/fake-registration-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
from tornado.options import define, options, parse_command_line

define("port", default=80, help="run on the given port", type=int)
define("addr", default="10.42.42.1", help="run on the given ip", type=str)
define("debug", default=True, help="run in debug mode")
define("secKey", default="0000000000000000", help="key used for encrypted communication")

import os
import signal

def exit_cleanly(signal, frame):
print("Received SIGINT, exiting...")
exit(0)

signal.signal(signal.SIGINT, exit_cleanly)

from Crypto.Cipher import AES
pad = lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16)
Expand Down Expand Up @@ -62,23 +70,8 @@ class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("You are connected to vtrust-flash")

class SchemaHandler(object):
def __init__(self):
self.notifier = tornado.locks.Condition()
self.activated_ids = {}

def get(self, gwId):
# first try extended schema, otherwise minimal schema
schema_key_count = 1 if gwId in self.activated_ids else 10
# record that this gwId has been seen
self.activated_ids[gwId] = True
self.notifier.notify_all()
return jsonstr([
{"mode":"rw","property":{"type":"bool"},"id":1,"type":"obj"}] * schema_key_count)

schema = SchemaHandler()

class JSONHandler(tornado.web.RequestHandler):
activated_ids = {}
def get(self):
self.post()
def reply(self, result=None, encrypted=False):
Expand Down Expand Up @@ -134,26 +127,32 @@ def post(self):
if(a == "s.gw.token.get"):
print("Answer s.gw.token.get")
answer = {
"gwApiUrl": "http://10.42.42.1/gw.json",
"gwApiUrl": "http://" + options.addr + "/gw.json",
"stdTimeZone": "-05:00",
"mqttRanges": "",
"timeZone": "-05:00",
"httpsPSKUrl": "https://10.42.42.1/gw.json",
"mediaMqttUrl": "10.42.42.1",
"gwMqttUrl": "10.42.42.1",
"httpsPSKUrl": "https://" + options.addr + "/gw.json",
"mediaMqttUrl": options.addr,
"gwMqttUrl": options.addr,
"dstIntervals": [] }
if encrypted:
answer["mqttsUrl"] = "10.42.42.1"
answer["mqttsPSKUrl"] = "10.42.42.1"
answer["mediaMqttsUrl"] = "10.42.42.1"
answer["aispeech"] = "10.42.42.1"
answer["mqttsUrl"] = options.addr
answer["mqttsPSKUrl"] = options.addr
answer["mediaMqttsUrl"] = options.addr
answer["aispeech"] = options.addr
self.reply(answer)
#os.system("killall smartconfig.js")
os.system("pkill -f smartconfig/main.py")

elif(".active" in a):
print("Answer s.gw.dev.pk.active")
# first try extended schema, otherwise minimal schema
schema_key_count = 1 if gwId in self.activated_ids else 10
# record that this gwId has been seen
self.activated_ids[gwId] = True
schema = jsonstr([
{"mode":"rw","property":{"type":"bool"},"id":1,"type":"obj"}] * schema_key_count)
answer = {
"schema": schema.get(gwId),
"schema": schema,
"uid": "00000000000000000000",
"devEtag": "0000000000",
"secKey": options.secKey,
Expand All @@ -175,7 +174,7 @@ def post(self):
"auto": 3,
"size": file_len,
"type": 0,
"pskUrl": "http://10.42.42.1/files/upgrade.bin",
"pskUrl": "http://" + options.addr + "/files/upgrade.bin",
"hmac": file_hmac,
"version": "9.0.0" }
self.reply(answer, encrypted)
Expand All @@ -187,7 +186,7 @@ def post(self):
"type": 0,
"size": file_len,
"version": "9.0.0",
"url": "http://10.42.42.1/files/upgrade.bin",
"url": "http://" + options.addr + "/files/upgrade.bin",
"md5": file_md5 }
self.reply(answer, encrypted)

Expand All @@ -198,7 +197,7 @@ def post(self):
"fileSize": file_len,
"etag": "0000000000",
"version": "9.0.0",
"url": "http://10.42.42.1/files/upgrade.bin",
"url": "http://" + options.addr + "/files/upgrade.bin",
"md5": file_md5 }
self.reply(answer, encrypted)

Expand Down Expand Up @@ -239,15 +238,22 @@ def main():
(r"/gw.json", JSONHandler),
(r"/d.json", JSONHandler),
('/files/(.*)', FilesHandler, {'path': str('../files/')}),
(r".*", tornado.web.RedirectHandler, {"url": "http://10.42.42.1/", "permanent": False}),
(r".*", tornado.web.RedirectHandler, {"url": "http://" + options.addr + "/", "permanent": False}),
],
#template_path=os.path.join(os.path.dirname(__file__), "templates"),
#static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=options.debug,
)
app.listen(options.port)
print("Listening on port "+str(options.port))
tornado.ioloop.IOLoop.current().start()
try:
app.listen(options.port, options.addr)
print("Listening on " + options.addr + ":" + str(options.port))
tornado.ioloop.IOLoop.current().start()
except OSError as err:
print("Could not start server on port " + str(options.port))
if err.errno is 98: # EADDRINUSE
print("Close the process on this port and try again")
else:
print(err)


if __name__ == "__main__":
Expand Down
11 changes: 11 additions & 0 deletions scripts/hostapd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# interface file to control hostapd from tuya-convert
ctrl_interface=hostapd_ctrl

# our AP SSID
ssid=vtrust-flash

# manually specify channel, as ACS may not work on some systems
channel=1

# set log level to info to cut down on noise
logger_stdout_level=4
3 changes: 2 additions & 1 deletion scripts/psk-frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def data_ready_cb(self, s):


def main():
proxies = [PskFrontend('', 443, '127.0.0.1', 80), PskFrontend('', 8886, '127.0.0.1', 1883)]
gateway = '10.42.42.1'
proxies = [PskFrontend(gateway, 443, gateway, 80), PskFrontend(gateway, 8886, gateway, 1883)]


while True:
Expand Down
Loading