changeset 1717:e9540ee0cf73

starting 2022 attempt at esp32cam
author drewp@bigasterisk.com
date Sun, 07 Aug 2022 02:26:11 -0700
parents 2bed2f68243c
children 82213d91471c
files espNode/cam.yaml espNode/tasks.py
diffstat 2 files changed, 121 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/espNode/cam.yaml	Sun Aug 07 02:26:11 2022 -0700
@@ -0,0 +1,49 @@
+# reusable for all ESP32-CAM programmed over ESP32-CAM-MB
+
+# mosquitto_sub  -v -t cam0/status
+
+# bang(pts/15):/my/proj/homeauto/espNode% catchsegv ./readcam.py --cam office_back_cam  --port 10021
+
+esphome:
+  name: $name
+  platform: ESP32
+  board: esp32cam
+  build_path: $build_path
+
+wifi:
+  ssid: !secret wifi_ssid
+  password: !secret wifi_password
+  domain: ''
+  manual_ip:
+    static_ip: $addr
+    gateway: 10.2.0.3
+    subnet: 255.255.0.0
+
+mqtt:
+  broker: '10.2.0.1'
+  port: 1883
+  username: ''
+  password: ''
+  
+logger:
+  baud_rate: 115200
+  level: DEBUG
+  
+ota:
+
+light:
+  - platform: monochromatic
+    name: "flash"
+    output: flash_out
+    default_transition_length: 0s
+  # - platform: binary
+  #   output: gpio_4
+  #   name: flash
+
+  
+
+output:
+  - platform: ledc
+    id: flash_out
+    pin: GPIO4
+    frequency: 19531Hz
--- a/espNode/tasks.py	Sun Aug 07 02:25:40 2022 -0700
+++ b/espNode/tasks.py	Sun Aug 07 02:26:11 2022 -0700
@@ -1,29 +1,42 @@
 from invoke import task
+from pathlib import Path
 
 port = '/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0'
 
-tag = 'esphome/esphome'
+tag = 'docker.io/esphome/esphome:2022.7.0-dev20220807'
 
-esphome = f'docker run --rm -v `pwd`:/config -v /usr/share/fonts:/usr/share/fonts -it {tag}'
-esphomeUsb = esphome.replace('--rm', f'--rm --device={port}')
-# on dash for lcd code for theater display:
-#tag = 'esphome_dev'
-#esphome = '/home/drewp/Downloads/esphome/env/bin/esphome'
+esphome = (
+    'docker run --rm ' +  #
+    '-v `pwd`:/config ' +  #
+    '-v /usr/share/fonts:/usr/share/fonts ' +  #
+    '-v /dev:/dev ' +  #
+    '-v /tmp:/tmp ' +  #
+    f'-it {tag}')
+
 
 @task
 def get_dev_esphome(ctx):
-    ctx.run(f'docker build -t esphome_dev -f docker/Dockerfile https://github.com/MasterTim17/esphome.git#dev')
+    ctx.run(
+        f'docker build -t esphome_dev -f docker/Dockerfile https://github.com/MasterTim17/esphome.git#dev'
+    )
+
 
 @task
 def pull_esphome(ctx):
     ctx.run(f"docker pull {tag}")
 
+
 @task
 def program_board_over_usb(ctx, board):
     board = board.replace('.yaml', '')
-    print('connect gnd, 3v3, rx/tx per https://randomnerdtutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/, ')
-    print('rts to reset (if possible), dtr to gpio0 per https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection#automatic-bootloader')
-    ctx.run(f"{esphomeUsb} run {board}.yaml --device={port}", pty=True, echo=True)
+    print(
+        'connect gnd, 3v3, rx/tx per https://randomnerdtutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/, '
+    )
+    print(
+        'rts to reset (if possible), dtr to gpio0 per https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection#automatic-bootloader'
+    )
+    ctx.run(f"{esphome} run {board}.yaml --device={port}", pty=True, echo=True)
+
 
 @task
 def program_board_over_wifi(ctx, board):
@@ -39,7 +52,55 @@
 @task
 def monitor_usb(ctx, board):
     board = board.replace('.yaml', '')
-    ctx.run(f"{esphomeUsb} logs {board}.yaml --device={port}", pty=True)
+    ctx.run(f"{esphome} logs {board}.yaml --device={port}", pty=True)
+
 
 # device up?
 #  nmap -Pn -p 3232,6053 10.2.0.21
+
+
+@task
+def program_cam_usb(ctx, name='0'):
+    idVendor = '1a86'
+    port = f'/dev/serial/by-id/usb-{idVendor}_USB_Serial-if00-port0'
+    ctx.run(
+        f"{esphome} "  #
+        + f"-s camname cam{name}"  #
+        + " run cam.yaml "  #
+        + f'--device={port} ',
+        pty=True,
+        echo=True)
+
+
+# -s k v seemed to have no effect
+def config_replace(in_file, out_file, repls):
+    yaml_text = open(in_file, 'rt').read()
+    for k, v in repls.items():
+        yaml_text = yaml_text.replace(k, str(v))
+    with open(out_file, 'wt') as out:
+        out.write(yaml_text)
+
+
+def prep_tmp(ctx, project):
+    tmp = Path(f'/tmp/esphome_build/{project}')
+    ctx.run(f'mkdir -p {tmp}')
+    ctx.run(f'cp secrets.yaml {tmp}')
+    return tmp
+
+
+@task
+def program_cam_ota(ctx, name='0'):
+    tmp = prep_tmp(ctx, 'cam')
+    tmpyaml = tmp / 'cam.yaml'
+    config_replace('cam.yaml', tmpyaml, {
+        '$build_path': tmp,
+        '$addr': '10.2.0.22',
+        '$name': f'cam{name}'
+    })
+    ctx.run(
+        f"{esphome} "  #
+        + f"run {tmpyaml} "  #
+        + "--device=OTA --no-logs"  #
+        ,
+        pty=True,
+        echo=True)