comparison espNode/tasks.py @ 1717:e9540ee0cf73

starting 2022 attempt at esp32cam
author drewp@bigasterisk.com
date Sun, 07 Aug 2022 02:26:11 -0700
parents 2bed2f68243c
children 82213d91471c
comparison
equal deleted inserted replaced
1716:2bed2f68243c 1717:e9540ee0cf73
1 from invoke import task 1 from invoke import task
2 from pathlib import Path
2 3
3 port = '/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0' 4 port = '/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0'
4 5
5 tag = 'esphome/esphome' 6 tag = 'docker.io/esphome/esphome:2022.7.0-dev20220807'
6 7
7 esphome = f'docker run --rm -v `pwd`:/config -v /usr/share/fonts:/usr/share/fonts -it {tag}' 8 esphome = (
8 esphomeUsb = esphome.replace('--rm', f'--rm --device={port}') 9 'docker run --rm ' + #
9 # on dash for lcd code for theater display: 10 '-v `pwd`:/config ' + #
10 #tag = 'esphome_dev' 11 '-v /usr/share/fonts:/usr/share/fonts ' + #
11 #esphome = '/home/drewp/Downloads/esphome/env/bin/esphome' 12 '-v /dev:/dev ' + #
13 '-v /tmp:/tmp ' + #
14 f'-it {tag}')
15
12 16
13 @task 17 @task
14 def get_dev_esphome(ctx): 18 def get_dev_esphome(ctx):
15 ctx.run(f'docker build -t esphome_dev -f docker/Dockerfile https://github.com/MasterTim17/esphome.git#dev') 19 ctx.run(
20 f'docker build -t esphome_dev -f docker/Dockerfile https://github.com/MasterTim17/esphome.git#dev'
21 )
22
16 23
17 @task 24 @task
18 def pull_esphome(ctx): 25 def pull_esphome(ctx):
19 ctx.run(f"docker pull {tag}") 26 ctx.run(f"docker pull {tag}")
20 27
28
21 @task 29 @task
22 def program_board_over_usb(ctx, board): 30 def program_board_over_usb(ctx, board):
23 board = board.replace('.yaml', '') 31 board = board.replace('.yaml', '')
24 print('connect gnd, 3v3, rx/tx per https://randomnerdtutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/, ') 32 print(
25 print('rts to reset (if possible), dtr to gpio0 per https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection#automatic-bootloader') 33 'connect gnd, 3v3, rx/tx per https://randomnerdtutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/, '
26 ctx.run(f"{esphomeUsb} run {board}.yaml --device={port}", pty=True, echo=True) 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
27 40
28 @task 41 @task
29 def program_board_over_wifi(ctx, board): 42 def program_board_over_wifi(ctx, board):
30 global esphome 43 global esphome
31 board = board.replace('.yaml', '') 44 board = board.replace('.yaml', '')
37 50
38 51
39 @task 52 @task
40 def monitor_usb(ctx, board): 53 def monitor_usb(ctx, board):
41 board = board.replace('.yaml', '') 54 board = board.replace('.yaml', '')
42 ctx.run(f"{esphomeUsb} logs {board}.yaml --device={port}", pty=True) 55 ctx.run(f"{esphome} logs {board}.yaml --device={port}", pty=True)
56
43 57
44 # device up? 58 # device up?
45 # nmap -Pn -p 3232,6053 10.2.0.21 59 # nmap -Pn -p 3232,6053 10.2.0.21
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}')
87 ctx.run(f'cp secrets.yaml {tmp}')
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)