e8845005 by Barry

Added image release tool to rebuild automatically and put the bin file

out.
1 parent c272edb4
...@@ -12,6 +12,14 @@ I like the NodeMcu devices. They have 4mb flash and work well and are fairly rob ...@@ -12,6 +12,14 @@ I like the NodeMcu devices. They have 4mb flash and work well and are fairly rob
12 12
13 ### How to Load on a New ESP8266 13 ### How to Load on a New ESP8266
14 14
15 Vagrant setup
16
17 https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/build-firmware
18
19 Setup Vagrant SCP
20
21 vagrant plugin install vagrant-scp
22
15 Use python 3.6+ 23 Use python 3.6+
16 24
17 Create a virtual environment to save your brainspace. 25 Create a virtual environment to save your brainspace.
...@@ -38,6 +46,14 @@ Install esptool and the other required pip modules which will let you install th ...@@ -38,6 +46,14 @@ Install esptool and the other required pip modules which will let you install th
38 pip install -r requirements.txt 46 pip install -r requirements.txt
39 ``` 47 ```
40 48
49 NEW
50 Custom Vagrant image:
51
52 ```
53 python release_image.py
54 ```
55
56 <!-- THIS IS REPLACED BY THE NEW RELEASE IMAGE SCRIPT
41 After the modules are installed you will need to use esptool to erase the flash. 57 After the modules are installed you will need to use esptool to erase the flash.
42 if things go wrong... https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html 58 if things go wrong... https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
43 59
...@@ -60,6 +76,7 @@ After the file has been downloaded (use wget? browser? curl? whatever makes you ...@@ -60,6 +76,7 @@ After the file has been downloaded (use wget? browser? curl? whatever makes you
60 ``` 76 ```
61 esptool --port COM1 --baud 460800 write_flash --flash_size=detect 0 esp8266-20171101-v1.9.3.bin 77 esptool --port COM1 --baud 460800 write_flash --flash_size=detect 0 esp8266-20171101-v1.9.3.bin
62 ``` 78 ```
79 -->
63 80
64 This will write the binary micropython os to the device. After this you will want to validate the write was successful. 81 This will write the binary micropython os to the device. After this you will want to validate the write was successful.
65 82
......
...@@ -12,9 +12,13 @@ import socket ...@@ -12,9 +12,13 @@ import socket
12 import select 12 import select
13 import time 13 import time
14 import sys 14 import sys
15 import struct
16 import json 15 import json
17 16
17 if 'esp' in sys.platform:
18 import ustruct
19 else:
20 import struct
21
18 from utils import get_color, get_color_list, multiple_replace 22 from utils import get_color, get_color_list, multiple_replace
19 23
20 24
...@@ -426,7 +430,7 @@ class MudServer(object): ...@@ -426,7 +430,7 @@ class MudServer(object):
426 430
427 try: 431 try:
428 # read data from the socket, using a max length of 4096 432 # read data from the socket, using a max length of 4096
429 data = cl.socket.recv(4096) 433 data = cl.socket.recv(1024)
430 434
431 # process the data, stripping out any special Telnet commands 435 # process the data, stripping out any special Telnet commands
432 message = self._process_sent_data(cl, data) 436 message = self._process_sent_data(cl, data)
...@@ -640,6 +644,9 @@ class MudServer(object): ...@@ -640,6 +644,9 @@ class MudServer(object):
640 if option_state == self._READ_NAWS: 644 if option_state == self._READ_NAWS:
641 height = 30 645 height = 30
642 width = 100 646 width = 100
647 if 'esp' in sys.platform:
648 height, width = ustruct.unpack('>hh', option_data)
649 else:
643 height, width = struct.unpack('>hh', option_data) 650 height, width = struct.unpack('>hh', option_data)
644 if height > 0: 651 if height > 0:
645 client.height = height 652 client.height = height
......
...@@ -11,15 +11,12 @@ IPADDRESS = '192.168.1.189' ...@@ -11,15 +11,12 @@ IPADDRESS = '192.168.1.189'
11 11
12 BAUDRATE = 115200 12 BAUDRATE = 115200
13 13
14 folders = ['help', 'rooms', 'inventory', 'commands', 'mobs'] 14 folders = ['help', 'rooms', 'rooms/town', 'rooms/wilderness', 'inventory', 'commands', 'mobs']
15 15
16 files = [ 16 files = [
17 "main.py",
18 "mobs.txt",
19 "spawner.txt",
20 "welcome.txt", 17 "welcome.txt",
21 "wifiweb.py", 18 "defaultplayer.json",
22 "defaultplayer.json" 19 "main.py"
23 ] 20 ]
24 21
25 def run_command(sio, command, expected='>>>'): 22 def run_command(sio, command, expected='>>>'):
...@@ -27,18 +24,21 @@ def run_command(sio, command, expected='>>>'): ...@@ -27,18 +24,21 @@ def run_command(sio, command, expected='>>>'):
27 sio.flush() # it is buffering. required to get the data out *now* 24 sio.flush() # it is buffering. required to get the data out *now*
28 res = '' 25 res = ''
29 while expected not in res: 26 while expected not in res:
27 try:
30 res = sio.readline() 28 res = sio.readline()
31 # print(res) 29 except UnicodeDecodeError:
30 return ''
32 return res 31 return res
33 32
34 with serial.Serial(PORT, BAUDRATE, timeout=1) as ser: 33 with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
35 sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser)) 34 sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
36 run_command(sio, '\x03') 35 run_command(sio, '\x03')
37 run_command(sio, 'import os') 36 run_command(sio, 'import os')
38 root = eval(run_command(sio, 'os.listdir()', expected=']')) 37 root = run_command(sio, 'os.listdir()', expected=']')
39
40 if not set(folders).issubset(root):
41 38
39 if 'EEXIST' in root:
40 print('Folders already created.')
41 else:
42 print('Creating folders.') 42 print('Creating folders.')
43 # we are missing folders so they need to be created. 43 # we are missing folders so they need to be created.
44 tmp_folders = folders 44 tmp_folders = folders
...@@ -48,18 +48,19 @@ with serial.Serial(PORT, BAUDRATE, timeout=1) as ser: ...@@ -48,18 +48,19 @@ with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
48 continue 48 continue
49 print('Creating folder: {}'.format(folder)) 49 print('Creating folder: {}'.format(folder))
50 run_command(sio, 'os.mkdir("{}")'.format(folder)) 50 run_command(sio, 'os.mkdir("{}")'.format(folder))
51 else:
52 print('Folders already created.')
53 51
54 52
55 for folder in folders: 53 for folder in folders:
56 for f in os.listdir(folder): 54 for f in os.listdir(folder):
55 if not os.path.isdir(f):
57 files.append('{}/{}'.format(folder, f)) 56 files.append('{}/{}'.format(folder, f))
58 57
59 with open('releasepw.conf', 'r', encoding='utf-8') as f: 58 with open('releasepw.conf', 'r', encoding='utf-8') as f:
60 password = f.read() 59 password = f.read()
61 60
62 for file in files: 61 for file in files:
63 os.system("python webrepl\webrepl_cli.py -p {} {} {}:/{}".format(password, file, IPADDRESS, file)) 62 # print("python webrepl\\webrepl_cli.py -p {} {} {}:/{}".format(password, file, IPADDRESS, file))
63 os.system("python webrepl\\webrepl_cli.py -p {} {} {}:/{}".format(password, file, IPADDRESS, file))
64 64
65 run_command(sio, 'import machine;machine.reset') 65 print("Rebooting via machine reset")
66 run_command(sio, 'import machine;machine.reset()')
......
1 import os
2 import io
3 import serial
4 import time
5
6 ######################################
7 # EDIT THIS TO MATCH YOUR SETTINGS
8 PORT = 'COM17'
9 VMID = '1e5fc8c'
10 ESSID = 'Volley'
11 WIFI_PASSWORD = '6198472223'
12 ######################################
13
14 BAUDRATE = 115200
15
16 baked_files = [
17 "weemud.py",
18 "mudserver.py",
19 "commandhandler.py",
20 "wifiweb.py",
21 "utils.py"
22 ]
23
24
25 def run_command(sio, command, expected='>>>'):
26 sio.write("{}\n".format(command))
27 sio.flush() # it is buffering. required to get the data out *now*
28 res = ''
29 while expected not in res:
30 try:
31 res = sio.readline()
32 except UnicodeDecodeError:
33 return ''
34 return res
35
36 # Compile vagrant image
37 for file in baked_files:
38 os.system("vagrant scp {} {}:micropython/ports/esp8266/modules/{}".format(file, VMID, file))
39 os.system('vagrant ssh {} -c "cd micropython/ports/esp8266;make"'.format(VMID))
40 try:
41 os.mkdir('image')
42 except FileExistsError:
43 pass
44 os.system('vagrant scp {}:micropython/ports/esp8266/build/firmware-combined.bin image/firmware-combined.bin'.format(VMID))
45
46 os.system('esptool --port {} erase_flash'.format(PORT))
47 os.system('esptool --port {} --baud 460800 write_flash --flash_size=detect 0 image/firmware-combined.bin'.format(PORT))
48
49 print("Sleeping 10 seconds for reboot")
50 time.sleep(10)
51
52 with open('releasepw.conf', 'r', encoding='utf-8') as f:
53 WEBREPL_PASS = f.read()
54
55 with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
56 sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
57 run_command(sio, '\x03')
58 run_command(sio, 'import os')
59 print('Setting up Webrepl')
60 run_command(sio, "f = open('webrepl_cfg.py', 'w+').write(\"PASS = '{}'\\n\")".format(WEBREPL_PASS))
61 run_command(sio, 'f = open("boot.py", "w+").write("# This file is executed on every boot (including wake-boot from deepsleep)\\n#import esp\\n#esp.osdebug(None)\\nimport gc\\nimport webrepl\\nwebrepl.start()\\ngc.collect()\\n")')
62
63 print('Setting up Wifi Network')
64 run_command(sio, 'import network')
65 run_command(sio, 'sta_if = network.WLAN(network.STA_IF)')
66 run_command(sio, 'ap_if = network.WLAN(network.AP_IF)')
67
68 run_command(sio, 'sta_if.active(True)')
69
70 print('Connecting to {}'.format(ESSID))
71 run_command(sio, "sta_if.connect('{}', '{}')".format(ESSID, WIFI_PASSWORD))
72
73 waiting_for_ip = True
74 while waiting_for_ip:
75 try:
76 ifconfig = eval(run_command(sio, "sta_if.ifconfig()", expected='('))
77
78 if ifconfig[0] != '0.0.0.0':
79 print("New IP Address: {}".format(ifconfig[0]))
80 waiting_for_ip = False
81 except SyntaxError:
82 pass
83 except NameError:
84 pass
85
86 print("Rebooting via machine reset")
87
88 run_command(sio, 'import machine;machine.reset()')
89
90 print('Starting the squishy mud release')
91 time.sleep(5)
92 # Run the rest of the mud setup
93 import release
...\ No newline at end of file ...\ No newline at end of file
1 import json 1 import json
2 import sys 2 import sys
3 import re
4 3
5 if 'esp' in sys.platform: 4 if 'esp' in sys.platform:
6 from urandom import getrandbits 5 from urandom import getrandbits
...@@ -12,7 +11,7 @@ codes = {'resetall': 0, 'bold': 1, 'underline': 4, ...@@ -12,7 +11,7 @@ codes = {'resetall': 0, 'bold': 1, 'underline': 4,
12 'blinkoff': 25, 'underlineoff': 24, 'reverseoff': 27, 11 'blinkoff': 25, 'underlineoff': 24, 'reverseoff': 27,
13 'reset': 0, 'black': 30, 'red': 31, 'green': 32, 12 'reset': 0, 'black': 30, 'red': 31, 'green': 32,
14 'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36, 13 'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36,
15 'white': 37} 14 'white': 37 }
16 15
17 16
18 def password_hash(name, password): 17 def password_hash(name, password):
...@@ -37,13 +36,10 @@ def get_color(name): ...@@ -37,13 +36,10 @@ def get_color(name):
37 return '\x1b[{}m'.format(codes.get(name, 0)) 36 return '\x1b[{}m'.format(codes.get(name, 0))
38 37
39 38
40 def multiple_replace(text, adict): 39 def multiple_replace(text, replace_words):
41 rx = re.compile('|'.join(map(re.escape, adict))) 40 for word, replacement in replace_words.items():
42 41 text = text.replace(word, get_color(replacement))
43 def one_xlat(match): 42 return text
44 return get_color(adict[match.group(0)])
45 return rx.sub(one_xlat, text)
46
47 43
48 def save_object_to_file(obj, filename): 44 def save_object_to_file(obj, filename):
49 with open(filename.lower(), 'w', encoding='utf-8') as f: 45 with open(filename.lower(), 'w', encoding='utf-8') as f:
......
This diff is collapsed. Click to expand it.