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
### How to Load on a New ESP8266
Vagrant setup
https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/build-firmware
Setup Vagrant SCP
vagrant plugin install vagrant-scp
Use python 3.6+
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
pip install -r requirements.txt
```
NEW
Custom Vagrant image:
```
python release_image.py
```
<!-- THIS IS REPLACED BY THE NEW RELEASE IMAGE SCRIPT
After the modules are installed you will need to use esptool to erase the flash.
if things go wrong... https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
......@@ -60,6 +76,7 @@ After the file has been downloaded (use wget? browser? curl? whatever makes you
```
esptool --port COM1 --baud 460800 write_flash --flash_size=detect 0 esp8266-20171101-v1.9.3.bin
```
-->
This will write the binary micropython os to the device. After this you will want to validate the write was successful.
......
......@@ -12,9 +12,13 @@ import socket
import select
import time
import sys
import struct
import json
if 'esp' in sys.platform:
import ustruct
else:
import struct
from utils import get_color, get_color_list, multiple_replace
......@@ -426,7 +430,7 @@ class MudServer(object):
try:
# read data from the socket, using a max length of 4096
data = cl.socket.recv(4096)
data = cl.socket.recv(1024)
# process the data, stripping out any special Telnet commands
message = self._process_sent_data(cl, data)
......@@ -640,7 +644,10 @@ class MudServer(object):
if option_state == self._READ_NAWS:
height = 30
width = 100
height, width = struct.unpack('>hh', option_data)
if 'esp' in sys.platform:
height, width = ustruct.unpack('>hh', option_data)
else:
height, width = struct.unpack('>hh', option_data)
if height > 0:
client.height = height
if width > 0:
......
......@@ -11,15 +11,12 @@ IPADDRESS = '192.168.1.189'
BAUDRATE = 115200
folders = ['help', 'rooms', 'inventory', 'commands', 'mobs']
folders = ['help', 'rooms', 'rooms/town', 'rooms/wilderness', 'inventory', 'commands', 'mobs']
files = [
"main.py",
"mobs.txt",
"spawner.txt",
"welcome.txt",
"wifiweb.py",
"defaultplayer.json"
"defaultplayer.json",
"main.py"
]
def run_command(sio, command, expected='>>>'):
......@@ -27,18 +24,21 @@ def run_command(sio, command, expected='>>>'):
sio.flush() # it is buffering. required to get the data out *now*
res = ''
while expected not in res:
res = sio.readline()
# print(res)
try:
res = sio.readline()
except UnicodeDecodeError:
return ''
return res
with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
run_command(sio, '\x03')
run_command(sio, 'import os')
root = eval(run_command(sio, 'os.listdir()', expected=']'))
if not set(folders).issubset(root):
root = run_command(sio, 'os.listdir()', expected=']')
if 'EEXIST' in root:
print('Folders already created.')
else:
print('Creating folders.')
# we are missing folders so they need to be created.
tmp_folders = folders
......@@ -48,18 +48,19 @@ with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
continue
print('Creating folder: {}'.format(folder))
run_command(sio, 'os.mkdir("{}")'.format(folder))
else:
print('Folders already created.')
for folder in folders:
for f in os.listdir(folder):
files.append('{}/{}'.format(folder, f))
if not os.path.isdir(f):
files.append('{}/{}'.format(folder, f))
with open('releasepw.conf', 'r', encoding='utf-8') as f:
password = f.read()
for file in files:
os.system("python webrepl\webrepl_cli.py -p {} {} {}:/{}".format(password, file, IPADDRESS, file))
# print("python webrepl\\webrepl_cli.py -p {} {} {}:/{}".format(password, file, IPADDRESS, file))
os.system("python webrepl\\webrepl_cli.py -p {} {} {}:/{}".format(password, file, IPADDRESS, file))
run_command(sio, 'import machine;machine.reset')
print("Rebooting via machine reset")
run_command(sio, 'import machine;machine.reset()')
......
import os
import io
import serial
import time
######################################
# EDIT THIS TO MATCH YOUR SETTINGS
PORT = 'COM17'
VMID = '1e5fc8c'
ESSID = 'Volley'
WIFI_PASSWORD = '6198472223'
######################################
BAUDRATE = 115200
baked_files = [
"weemud.py",
"mudserver.py",
"commandhandler.py",
"wifiweb.py",
"utils.py"
]
def run_command(sio, command, expected='>>>'):
sio.write("{}\n".format(command))
sio.flush() # it is buffering. required to get the data out *now*
res = ''
while expected not in res:
try:
res = sio.readline()
except UnicodeDecodeError:
return ''
return res
# Compile vagrant image
for file in baked_files:
os.system("vagrant scp {} {}:micropython/ports/esp8266/modules/{}".format(file, VMID, file))
os.system('vagrant ssh {} -c "cd micropython/ports/esp8266;make"'.format(VMID))
try:
os.mkdir('image')
except FileExistsError:
pass
os.system('vagrant scp {}:micropython/ports/esp8266/build/firmware-combined.bin image/firmware-combined.bin'.format(VMID))
os.system('esptool --port {} erase_flash'.format(PORT))
os.system('esptool --port {} --baud 460800 write_flash --flash_size=detect 0 image/firmware-combined.bin'.format(PORT))
print("Sleeping 10 seconds for reboot")
time.sleep(10)
with open('releasepw.conf', 'r', encoding='utf-8') as f:
WEBREPL_PASS = f.read()
with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
run_command(sio, '\x03')
run_command(sio, 'import os')
print('Setting up Webrepl')
run_command(sio, "f = open('webrepl_cfg.py', 'w+').write(\"PASS = '{}'\\n\")".format(WEBREPL_PASS))
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")')
print('Setting up Wifi Network')
run_command(sio, 'import network')
run_command(sio, 'sta_if = network.WLAN(network.STA_IF)')
run_command(sio, 'ap_if = network.WLAN(network.AP_IF)')
run_command(sio, 'sta_if.active(True)')
print('Connecting to {}'.format(ESSID))
run_command(sio, "sta_if.connect('{}', '{}')".format(ESSID, WIFI_PASSWORD))
waiting_for_ip = True
while waiting_for_ip:
try:
ifconfig = eval(run_command(sio, "sta_if.ifconfig()", expected='('))
if ifconfig[0] != '0.0.0.0':
print("New IP Address: {}".format(ifconfig[0]))
waiting_for_ip = False
except SyntaxError:
pass
except NameError:
pass
print("Rebooting via machine reset")
run_command(sio, 'import machine;machine.reset()')
print('Starting the squishy mud release')
time.sleep(5)
# Run the rest of the mud setup
import release
\ No newline at end of file
import json
import sys
import re
if 'esp' in sys.platform:
from urandom import getrandbits
......@@ -12,7 +11,7 @@ codes = {'resetall': 0, 'bold': 1, 'underline': 4,
'blinkoff': 25, 'underlineoff': 24, 'reverseoff': 27,
'reset': 0, 'black': 30, 'red': 31, 'green': 32,
'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36,
'white': 37}
'white': 37 }
def password_hash(name, password):
......@@ -37,13 +36,10 @@ def get_color(name):
return '\x1b[{}m'.format(codes.get(name, 0))
def multiple_replace(text, adict):
rx = re.compile('|'.join(map(re.escape, adict)))
def one_xlat(match):
return get_color(adict[match.group(0)])
return rx.sub(one_xlat, text)
def multiple_replace(text, replace_words):
for word, replacement in replace_words.items():
text = text.replace(word, get_color(replacement))
return text
def save_object_to_file(obj, filename):
with open(filename.lower(), 'w', encoding='utf-8') as f:
......
This diff is collapsed. Click to expand it.