596
|
1 from invoke import task
|
1717
|
2 from pathlib import Path
|
596
|
3
|
1701
|
4 port = '/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0'
|
|
5
|
1717
|
6 tag = 'docker.io/esphome/esphome:2022.7.0-dev20220807'
|
1701
|
7
|
1717
|
8 esphome = (
|
|
9 'docker run --rm ' + #
|
|
10 '-v `pwd`:/config ' + #
|
|
11 '-v /usr/share/fonts:/usr/share/fonts ' + #
|
|
12 '-v /dev:/dev ' + #
|
|
13 '-v /tmp:/tmp ' + #
|
|
14 f'-it {tag}')
|
|
15
|
800
|
16
|
|
17 @task
|
|
18 def get_dev_esphome(ctx):
|
1717
|
19 ctx.run(
|
|
20 f'docker build -t esphome_dev -f docker/Dockerfile https://github.com/MasterTim17/esphome.git#dev'
|
|
21 )
|
|
22
|
686
|
23
|
|
24 @task
|
|
25 def pull_esphome(ctx):
|
|
26 ctx.run(f"docker pull {tag}")
|
|
27
|
1717
|
28
|
596
|
29 @task
|
|
30 def program_board_over_usb(ctx, board):
|
800
|
31 board = board.replace('.yaml', '')
|
1717
|
32 print(
|
|
33 'connect gnd, 3v3, rx/tx per https://randomnerdtutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/, '
|
|
34 )
|
|
35 print(
|
|
36 'rts to reset (if possible), dtr to gpio0 per https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection#automatic-bootloader'
|
|
37 )
|
|
38 ctx.run(f"{esphome} run {board}.yaml --device={port}", pty=True, echo=True)
|
|
39
|
596
|
40
|
|
41 @task
|
|
42 def program_board_over_wifi(ctx, board):
|
1716
|
43 global esphome
|
800
|
44 board = board.replace('.yaml', '')
|
1716
|
45 if board == 'theater_lcd':
|
|
46 tag = 'esphome_dev'
|
|
47 esphome = 'esphome-local/env/bin/esphome'
|
|
48
|
800
|
49 ctx.run(f"{esphome} {board}.yaml run", pty=True)
|
596
|
50
|
1716
|
51
|
596
|
52 @task
|
|
53 def monitor_usb(ctx, board):
|
800
|
54 board = board.replace('.yaml', '')
|
1717
|
55 ctx.run(f"{esphome} logs {board}.yaml --device={port}", pty=True)
|
|
56
|
686
|
57
|
|
58 # device up?
|
|
59 # nmap -Pn -p 3232,6053 10.2.0.21
|
1717
|
60
|
|
61
|
|
62 @task
|
|
63 def program_cam_usb(ctx, name='0'):
|
|
64 idVendor = '1a86'
|
|
65 port = f'/dev/serial/by-id/usb-{idVendor}_USB_Serial-if00-port0'
|
|
66 ctx.run(
|
|
67 f"{esphome} " #
|
|
68 + f"-s camname cam{name}" #
|
|
69 + " run cam.yaml " #
|
|
70 + f'--device={port} ',
|
|
71 pty=True,
|
|
72 echo=True)
|
|
73
|
|
74
|
|
75 # -s k v seemed to have no effect
|
|
76 def config_replace(in_file, out_file, repls):
|
|
77 yaml_text = open(in_file, 'rt').read()
|
|
78 for k, v in repls.items():
|
|
79 yaml_text = yaml_text.replace(k, str(v))
|
|
80 with open(out_file, 'wt') as out:
|
|
81 out.write(yaml_text)
|
|
82
|
|
83
|
|
84 def prep_tmp(ctx, project):
|
|
85 tmp = Path(f'/tmp/esphome_build/{project}')
|
|
86 ctx.run(f'mkdir -p {tmp}')
|
1718
|
87 ctx.run(f'rsync -a component secrets.yaml {tmp}')
|
1717
|
88 return tmp
|
|
89
|
|
90
|
|
91 @task
|
|
92 def program_cam_ota(ctx, name='0'):
|
|
93 tmp = prep_tmp(ctx, 'cam')
|
|
94 tmpyaml = tmp / 'cam.yaml'
|
|
95 config_replace('cam.yaml', tmpyaml, {
|
|
96 '$build_path': tmp,
|
|
97 '$addr': '10.2.0.22',
|
|
98 '$name': f'cam{name}'
|
|
99 })
|
|
100 ctx.run(
|
|
101 f"{esphome} " #
|
|
102 + f"run {tmpyaml} " #
|
|
103 + "--device=OTA --no-logs" #
|
|
104 ,
|
|
105 pty=True,
|
|
106 echo=True)
|