From 6846a172434a3ea5c0400d0ece62e8c8a2b92b9f Mon Sep 17 00:00:00 2001 From: Remy Moll Date: Wed, 8 Nov 2023 21:41:47 +0100 Subject: [PATCH] added better wireless managment --- .gitignore | 2 +- README | 8 +++++ deploy/setup.playbook.yml | 44 ++++++++++++++++++--------- deploy/templates/eink-show.service.j2 | 3 +- image_get.py | 2 +- image_show.py | 1 + main.py | 4 ++- 7 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 README diff --git a/.gitignore b/.gitignore index 9bfb3f6..eb1fd66 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ keys.py *.pyc .image-cache/ test.png -*.j2 \ No newline at end of file +wifi_networks.yml \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..ca78f7f --- /dev/null +++ b/README @@ -0,0 +1,8 @@ +# EINK PICTURE FRAME - displays images on a multi-color eink display + +## Deployment +Run the ansible playbooks (`setup` once, `deploy` on each code update): +``` +ansible-playbook deploy/setup.playbook.yml -i +ansible-playbook deploy/deploy.playbook.yml -i +``` \ No newline at end of file diff --git a/deploy/setup.playbook.yml b/deploy/setup.playbook.yml index 21d56ec..06cff61 100644 --- a/deploy/setup.playbook.yml +++ b/deploy/setup.playbook.yml @@ -1,15 +1,21 @@ -- name: Basic setup tasks for Raspberry Pi +- name: Deployment of software + requirements hosts: all user: remy become: true tasks: - - name: Add local ssh key - ansible.posix.authorized_key: - user: "{{ ansible_user }}" - state: present - # copy file present on the controller to the remote host - key: "{{ lookup('file', '~/.ssh/default.pub') }}" + # DONE BY RPI IMAGER + # - name: Add local ssh key + # ansible.posix.authorized_key: + # user: "{{ ansible_user }}" + # state: present + # # copy file present on the controller to the remote host + # key: "{{ lookup('file', '~/.ssh/default.pub') }}" + + - name: Include network variables + ansible.builtin.include_vars: + file: wifi_networks.yml + name: wifi_external - name: apt update all packages apt: @@ -52,10 +58,20 @@ delay: 5 timeout: 300 - - name: Add wifi networks from template - template: - src: templates/wpa_supplicant.conf.j2 - dest: /etc/wpa_supplicant/wpa_supplicant.conf - owner: root - group: root - mode: 0600 + # - name: Add wifi networks from template + # template: + # src: templates/wpa_supplicant.conf.j2 + # dest: /etc/wpa_supplicant/wpa_supplicant.conf + # owner: root + # group: root + # mode: 0600 + + - name: Use raspi-config to set WIFI country + shell: | + raspi-config nonint do_wifi_country CH + + - name: Use raspi-config to set WIFI SSID and password + shell: | + raspi-config nonint do_wifi_ssid_passphrase "{{ item.ssid }}" "{{ item.password }}" + loop: "{{ wifi_external.networks }}" + diff --git a/deploy/templates/eink-show.service.j2 b/deploy/templates/eink-show.service.j2 index d7a1f5b..cb1d78a 100644 --- a/deploy/templates/eink-show.service.j2 +++ b/deploy/templates/eink-show.service.j2 @@ -3,9 +3,8 @@ Description=Show new photo onto the eink display [Service] Type=oneshot - +User={{ ansible_user }} WorkingDirectory={{ code_dest }} - ExecStart=python main.py diff --git a/image_get.py b/image_get.py index 9a6e886..f8b2400 100644 --- a/image_get.py +++ b/image_get.py @@ -28,7 +28,7 @@ class ImageGetter: bytes = self.load_cached_file() return bytes - + def get_random_image_ids(self, num=1) -> str: url = keys.immich_api_root_url + "album/" + keys.immich_album_id diff --git a/image_show.py b/image_show.py index 8eb6298..f154a3e 100644 --- a/image_show.py +++ b/image_show.py @@ -24,6 +24,7 @@ class ImageShow: if image.size != (self.epd.width, self.epd.height) and image.size != (self.epd.height, self.epd.width): raise ImageShowError("Image does not match screen size") elif image.size == (self.epd.height, self.epd.width): + print("Rotated image to match orientation") image = image.transpose(Image.ROTATE_270) self.__init__() diff --git a/main.py b/main.py index b4ef700..c16a712 100644 --- a/main.py +++ b/main.py @@ -15,4 +15,6 @@ if show_image: image = get.get_random_image() image = convert.convert(image) if show_image: - show.show_image(image) \ No newline at end of file + show.show_image(image) +else: + print("Would have shown image now.")