Skip to content

Commit d3aa848

Browse files
authored
Merge pull request #331 from ct-Open-Source/development
Release v2.1.0
2 parents 6860d5b + e32199b commit d3aa848

13 files changed

+231
-186
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,10 @@ node_modules/
108108
*.bin
109109
device-info.txt
110110
scripts/smartconfig/package-lock.json
111+
112+
# firmware backups directory
113+
backups/
114+
115+
# flag files
116+
eula_accepted
117+

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ On January 28th, 2019, Tuya started [distributing a patch](https://www.heise.de/
4949
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.
5050

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

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

7877
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.
7978

79+
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.
80+
8081
Binary requirements:
8182
* full binary including first-stage bootloader
8283
* maximum filesize 512KB for first flash
8384

84-
3. Start flashing process
85+
2. Start flashing process
8586

8687
# curl http://10.42.42.42/flash3
8788

88-
Alternatively you can request a certain file to be requested and flashed by the device:
89+
Alternatively you can request a certain file to be requested and flashed by the device:
8990

90-
# curl http://10.42.42.42/flash3?url=http://10.42.42.1/files/thirdparty.bin
91+
# curl http://10.42.42.42/flash3?url=http://10.42.42.1/files/certain_file.bin
9192

92-
4. Initial Configuration
93+
3. Initial Configuration
9394

9495
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.
9596

97+
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.
98+
9699
## CONTRIBUTING
97100

98101
This project is currently maintained by Colin Kuebler @kueblc

config.txt

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# Please input the good wlan device (most of the time it is wlan0 or wlan1)
1+
# Please input the wlan device to be used (most of the time it is wlan0 or wlan1)
22
WLAN=wlan0
33

4-
# The ETH device should be connected to the internet but it should also work if it is a local network only
5-
ETH=eth0
6-
7-
# Here you could change the WIFI-name and password but most likely most scripts won't work after
4+
# Here you could change the WIFI-name but most likely most scripts won't work after
85
# Because the WIFI-credentials are hardcoded in the esp8266-ota-flash-convert
96
AP=vtrust-flash
10-
PASS=flashmeifyoucan
7+
GATEWAY=10.42.42.1

files/espurna-base.bin

406 KB
Binary file not shown.

install_prereq.sh

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
set -e
44

55
sudo apt-get update
6-
sudo apt-get upgrade -y
7-
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
8-
sudo -H pip3 install paho-mqtt tornado git+https://github.com/M4dmartig4n/sslpsk.git pycrypto
9-
sudo -H pip2 install git+https://github.com/M4dmartig4n/sslpsk.git pycrypto
6+
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
7+
8+
PY3_DEPENDENCIES="paho-mqtt pyaes tornado git+https://github.com/M4dmartig4n/sslpsk.git pycrypto"
9+
PY2_DEPENDENCIES="git+https://github.com/M4dmartig4n/sslpsk.git pycrypto"
10+
11+
if python3 -c 'import sys; exit(0) if sys.version_info.major == 3 and sys.version_info.minor < 7 else exit(1)' ;
12+
then
13+
sudo -H pip3 install $PY3_DEPENDENCIES
14+
sudo -H pip2 install $PY2_DEPENDENCIES
15+
else
16+
sudo -H python3 -m pip install $PY3_DEPENDENCIES
17+
sudo -H python2 -m pip install $PY2_DEPENDENCIES
18+
fi
1019

1120
echo "Ready to start upgrade"

scripts/fake-registration-server.py

+39-33
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@
1111
from tornado.options import define, options, parse_command_line
1212

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

1718
import os
19+
import signal
20+
21+
def exit_cleanly(signal, frame):
22+
print("Received SIGINT, exiting...")
23+
exit(0)
24+
25+
signal.signal(signal.SIGINT, exit_cleanly)
1826

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

65-
class SchemaHandler(object):
66-
def __init__(self):
67-
self.notifier = tornado.locks.Condition()
68-
self.activated_ids = {}
69-
70-
def get(self, gwId):
71-
# first try extended schema, otherwise minimal schema
72-
schema_key_count = 1 if gwId in self.activated_ids else 10
73-
# record that this gwId has been seen
74-
self.activated_ids[gwId] = True
75-
self.notifier.notify_all()
76-
return jsonstr([
77-
{"mode":"rw","property":{"type":"bool"},"id":1,"type":"obj"}] * schema_key_count)
78-
79-
schema = SchemaHandler()
80-
8173
class JSONHandler(tornado.web.RequestHandler):
74+
activated_ids = {}
8275
def get(self):
8376
self.post()
8477
def reply(self, result=None, encrypted=False):
@@ -134,26 +127,32 @@ def post(self):
134127
if(a == "s.gw.token.get"):
135128
print("Answer s.gw.token.get")
136129
answer = {
137-
"gwApiUrl": "http://10.42.42.1/gw.json",
130+
"gwApiUrl": "http://" + options.addr + "/gw.json",
138131
"stdTimeZone": "-05:00",
139132
"mqttRanges": "",
140133
"timeZone": "-05:00",
141-
"httpsPSKUrl": "https://10.42.42.1/gw.json",
142-
"mediaMqttUrl": "10.42.42.1",
143-
"gwMqttUrl": "10.42.42.1",
134+
"httpsPSKUrl": "https://" + options.addr + "/gw.json",
135+
"mediaMqttUrl": options.addr,
136+
"gwMqttUrl": options.addr,
144137
"dstIntervals": [] }
145138
if encrypted:
146-
answer["mqttsUrl"] = "10.42.42.1"
147-
answer["mqttsPSKUrl"] = "10.42.42.1"
148-
answer["mediaMqttsUrl"] = "10.42.42.1"
149-
answer["aispeech"] = "10.42.42.1"
139+
answer["mqttsUrl"] = options.addr
140+
answer["mqttsPSKUrl"] = options.addr
141+
answer["mediaMqttsUrl"] = options.addr
142+
answer["aispeech"] = options.addr
150143
self.reply(answer)
151-
#os.system("killall smartconfig.js")
144+
os.system("pkill -f smartconfig/main.py")
152145

153146
elif(".active" in a):
154147
print("Answer s.gw.dev.pk.active")
148+
# first try extended schema, otherwise minimal schema
149+
schema_key_count = 1 if gwId in self.activated_ids else 10
150+
# record that this gwId has been seen
151+
self.activated_ids[gwId] = True
152+
schema = jsonstr([
153+
{"mode":"rw","property":{"type":"bool"},"id":1,"type":"obj"}] * schema_key_count)
155154
answer = {
156-
"schema": schema.get(gwId),
155+
"schema": schema,
157156
"uid": "00000000000000000000",
158157
"devEtag": "0000000000",
159158
"secKey": options.secKey,
@@ -175,7 +174,7 @@ def post(self):
175174
"auto": 3,
176175
"size": file_len,
177176
"type": 0,
178-
"pskUrl": "http://10.42.42.1/files/upgrade.bin",
177+
"pskUrl": "http://" + options.addr + "/files/upgrade.bin",
179178
"hmac": file_hmac,
180179
"version": "9.0.0" }
181180
self.reply(answer, encrypted)
@@ -187,7 +186,7 @@ def post(self):
187186
"type": 0,
188187
"size": file_len,
189188
"version": "9.0.0",
190-
"url": "http://10.42.42.1/files/upgrade.bin",
189+
"url": "http://" + options.addr + "/files/upgrade.bin",
191190
"md5": file_md5 }
192191
self.reply(answer, encrypted)
193192

@@ -198,7 +197,7 @@ def post(self):
198197
"fileSize": file_len,
199198
"etag": "0000000000",
200199
"version": "9.0.0",
201-
"url": "http://10.42.42.1/files/upgrade.bin",
200+
"url": "http://" + options.addr + "/files/upgrade.bin",
202201
"md5": file_md5 }
203202
self.reply(answer, encrypted)
204203

@@ -239,15 +238,22 @@ def main():
239238
(r"/gw.json", JSONHandler),
240239
(r"/d.json", JSONHandler),
241240
('/files/(.*)', FilesHandler, {'path': str('../files/')}),
242-
(r".*", tornado.web.RedirectHandler, {"url": "http://10.42.42.1/", "permanent": False}),
241+
(r".*", tornado.web.RedirectHandler, {"url": "http://" + options.addr + "/", "permanent": False}),
243242
],
244243
#template_path=os.path.join(os.path.dirname(__file__), "templates"),
245244
#static_path=os.path.join(os.path.dirname(__file__), "static"),
246245
debug=options.debug,
247246
)
248-
app.listen(options.port)
249-
print("Listening on port "+str(options.port))
250-
tornado.ioloop.IOLoop.current().start()
247+
try:
248+
app.listen(options.port, options.addr)
249+
print("Listening on " + options.addr + ":" + str(options.port))
250+
tornado.ioloop.IOLoop.current().start()
251+
except OSError as err:
252+
print("Could not start server on port " + str(options.port))
253+
if err.errno is 98: # EADDRINUSE
254+
print("Close the process on this port and try again")
255+
else:
256+
print(err)
251257

252258

253259
if __name__ == "__main__":

scripts/hostapd.conf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# interface file to control hostapd from tuya-convert
2+
ctrl_interface=hostapd_ctrl
3+
4+
# our AP SSID
5+
ssid=vtrust-flash
6+
7+
# manually specify channel, as ACS may not work on some systems
8+
channel=1
9+
10+
# set log level to info to cut down on noise
11+
logger_stdout_level=4

scripts/psk-frontend.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def data_ready_cb(self, s):
8787

8888

8989
def main():
90-
proxies = [PskFrontend('', 443, '127.0.0.1', 80), PskFrontend('', 8886, '127.0.0.1', 1883)]
90+
gateway = '10.42.42.1'
91+
proxies = [PskFrontend(gateway, 443, gateway, 80), PskFrontend(gateway, 8886, gateway, 1883)]
9192

9293

9394
while True:

0 commit comments

Comments
 (0)