Skip to content

Commit

Permalink
Merge pull request #331 from ct-Open-Source/development
Browse files Browse the repository at this point in the history
Release v2.1.0
  • Loading branch information
kueblc committed Oct 23, 2019
2 parents 6860d5b + e32199b commit d3aa848
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 186 deletions.
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

0 comments on commit d3aa848

Please sign in to comment.