diff --git a/README.md b/README.md index 15d2b0a..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,35 +0,0 @@ -# Multimedijski krmilnik FRI - -> *Also known as **PolžProjekt** or **KatjaKontroler*** - -## Arhitektura - -Sistem sestavljata dva kartična računalnika (trenutno Raspberry Pi 4) - *krmilnik* in *zaslon*. Na krmilniku je zagnan MQTT broker (mosquitto) in več *driverjev*, ki služijo kot mostovi med napravami v predavalnici in MQTT. Na zaslonu teče spletni brskalnik (chromium) z odprtim *frontendom* (VueJS aplikacija, servirana s krmilnika). Frontend komunicira neposredno z MQTT brokerjem preko WebSockets povezave. - -### Driverji - -- `tse_serial` - relejno polje *TSE ___*, ki krmili napajanje različnih komponent predavalnice, projekcijska platna in senčila -- `barco_telnet` - en projektor tipa *Barco G62* preko novega "Barco Telnet" protokola. Za več projektorjev je potrebnih več instanc driverja -- `projector_motors` - dvigala za projektorje preko dveh modulov *Grove I2C 4-channel SPDT relay* -- `lucke` - razsvetljava v predavalnici preko A-rosso sistema WebSCADA -- `extron_audio_matrix` - avdio matrika - **NI DOKONČAN** -- `barco_rlmw_{http,tcp}` - en projektor serije *Barco RLM W*. Obstajata dve različici (http in tcp) - -## Namestitev - -Namestitev poteka z orodjem *Ansible*, potrebna pa je tudi lokalna namestitev orodja `npm` (za izgradnjo frontenda). V mapi `ansible_deploy` sta ločeni mapi z playbooki za krmilnik in zaslon. - -Osnovni operacijski sistem za krmilnik je *RaspberryPi OS Lite* za zaslon pa *RaspberryPi OS Full*. Namestite ga lahko z orodjem *Raspberry Pi Imager* - pri tem bodite pozorni da nastavite uporabniško ime `pi` in geslo, ki je shranjeno v RC. - -Za namestitev mora imeti Raspberry Pi dostop do interneta, zato ga priključite v omrežje z DHCP. Njegov IP naslov se izpiše na HDMI izhodu, lahko ga pa najdete tudi na drug način. Ker se po prvem zagonu na vgrajeni mrežni kartici konfigurira statičen IP naslov, je priporočeno, da se za namestitev uporablja USB Ethernet adapter. - -Primer namestitve krmilnika za predavalnico P01 (ime v inventory datoteki je `p01_controller`), ki ima trenutno IP naslov `10.32.50.123` (ker se razlikuje od inventory datoteke ga je treba določiti z `-e ansible_host=`): - -```sh -cd ansible_deploy/controller -ansible-playbook playbook.yml -i inventory.yml -l p01_controller -e ansible_host=10.32.50.123 -``` - -## Posodobitev - -Posodobitev poteka enako kot namestitev. Če se izvaja v predavalnici je potrebo poskrbeti, da imajo ciljne naprave dostop do interneta. Za to ni dobrega načina, zato je priporočen enak pristop kot pri namestitvi (USB Ethernet adapter in omrežje z DHCP - lahko celo deljena povezava s prenosnika). diff --git a/ansible_deploy/barcoinv.yml b/ansible_deploy/barcoinv.yml new file mode 100644 index 0000000..7d8f910 --- /dev/null +++ b/ansible_deploy/barcoinv.yml @@ -0,0 +1,6 @@ +all: + hosts: + mmctrl-p1: + projectors: + - projector-p1-center + - projector-p1-side diff --git a/ansible_deploy/controller/malinaConfig.toml.j2 b/ansible_deploy/conf.j2 similarity index 85% rename from ansible_deploy/controller/malinaConfig.toml.j2 rename to ansible_deploy/conf.j2 index 61ab7fb..56a9b80 100644 --- a/ansible_deploy/controller/malinaConfig.toml.j2 +++ b/ansible_deploy/conf.j2 @@ -1,7 +1,7 @@ [global] room = "{{ room }}" -mqttHost = "{{ mqtt_ip }}" -mqttPort = {{ mqtt_port }} +mqttIp = "{{ mqtt_ip }}" +mqttPort = "{{ mqtt_port }}" {% if barco_G62 is defined %} {%+ for projector in barco_G62 +%} @@ -12,7 +12,7 @@ port = {{projector.port}} {% endif %} {%+ if tse_box is defined +%} -{# serial_device = "{{ tse_box.serial_device }}" #} +serial_device = "{{ tse_box.serial_device }}" {% endif %} {%+ if projector_motors is defined +%} {# change to appropriate thingy for running them #} @@ -35,4 +35,4 @@ i2c_address = {{motor.i2c_address}} url = "{{ lucke.url }}" roomId = "{{ lucke.roomId }}" bearer_token = "{{ lucke.bearer_token }}" -{% endif %} +{% endif %} \ No newline at end of file diff --git a/ansible_deploy/controller/inventory.yml b/ansible_deploy/controller/inventory.yml deleted file mode 100644 index 77b9d43..0000000 --- a/ansible_deploy/controller/inventory.yml +++ /dev/null @@ -1,82 +0,0 @@ -predavalnice_pi: - - # Skupne spremenljivke za vse krmilnike - vars: - - ansible_user: pi - - # Multimedia network - static_ip_cidr: "24" - static_ip_gateway: "192.168.192.1" - static_ip_dns_servers: - - "212.235.188.28" - - "212.235.188.29" - - # Lokalni MQTT - mqtt_ip: localhost - mqtt_port: 1883 - - # Nastavitve za vse posamezne predavalnice - hosts: - - p01_controller: - room: P01 - ansible_host: 192.168.192.42 - static_ip: 192.168.192.42 - - # Novi barco projektorji - barco_G62: - - position: main - model: barco_G62 - port: 3023 - ip: 192.168.192.12 - - position: side - model: barco_G62 - port: 3023 - ip: 192.168.192.13 - - tse_box: - - projector_motors: - - position: main - i2c_address: 0x42 - offset: 0 #for when using single 8 channel relay board - - position: side - i2c_address: 0x43 - offset: 4 - - lucke: - url: http://192.168.190.90:8091 - roomId: 1 - bearer_token: 0954afe1-4111-4f89-a123-fea08a55dc46 - - p22_controller: - room: P22 - ansible_host: 192.168.192.43 - static_ip: 192.168.192.43 - - # Novi barco projektorji - barco_G62: - - position: main - model: barco_G62 - port: 3023 - ip: 192.168.192.22 - - position: side - model: barco_G62 - port: 3023 - ip: 192.168.192.23 - - tse_box: - - projector_motors: - - position: main - i2c_address: 0x42 - offset: 0 #for when using single 8 channel relay board - - position: side - i2c_address: 0x43 - offset: 4 - - lucke: - url: http://192.168.190.90:8091 - roomId: 2 - bearer_token: b44c8cdc-d848-4b49-9deb-79023a60a62a diff --git a/ansible_deploy/controller/mm-controller.target.j2 b/ansible_deploy/controller/mm-controller.target.j2 deleted file mode 100644 index 3947d55..0000000 --- a/ansible_deploy/controller/mm-controller.target.j2 +++ /dev/null @@ -1,3 +0,0 @@ -[Unit] -Description=Krmilnik multimedijskega sistema -After=multi-user.target diff --git a/ansible_deploy/controller/playbook.yml b/ansible_deploy/controller/playbook.yml deleted file mode 100644 index 83a9080..0000000 --- a/ansible_deploy/controller/playbook.yml +++ /dev/null @@ -1,236 +0,0 @@ -- name: Test playbook - vars: - PROJECT_BASE: "{{playbook_dir}}/../../" - INSTALL_BASE: "/home/pi/pyServices" - - hosts: - - p01_controller - - p22_controller - - handlers: - - name: restart NetworkManager - ansible.builtin.service: - name: NetworkManager - state: restarted - - name: Restart mosquitto - become: true - ansible.builtin.systemd_service: - name: mosquitto.service - state: restarted - - tasks: - - # - # NETWORK CONFIGURATION - # - - - name: set eth0 static IP - become: true - community.general.nmcli: - conn_name: "Multimedia network" - ifname: eth0 - type: ethernet - ip4: "{{ static_ip }}/{{ static_ip_cidr }}" - # Sorry timi - method6: disabled - # Multimedia net doesn't have Internet access, so this iface shouldn't be used for Internet access - never_default4: true - routes4_extended: - - ip: 192.168.0.0/16 - next_hop: "{{ static_ip_gateway }}" - metric: 9999 - - ip: 10.0.0.0/8 - next_hop: "{{ static_ip_gateway }}" - metric: 9999 - # gw4: "{{ static_ip_gateway }}" - state: present - - - # - # SYSTEM DEPENDENCIES - # - - name: Install pkgs - become: true - apt: - name: - - python3-pip - - mosquitto - - nginx - state: latest - update_cache: true - - - name: Install Poetry - become: true - pip: - break_system_packages: true - name: - - poetry - # - # MOSQUITTO - # - - name: mosquitto enable - become: true - ansible.builtin.systemd_service: - name: mosquitto.service - enabled: true - - - name: Copy mosqitconfig - become: true - ansible.builtin.copy: - src: mosquitto.conf - dest: /etc/mosquitto/mosquitto.conf - owner: root - group: root - mode: '0644' - backup: yes - notify: Restart mosquitto - - # - # INSTALL CONTROLLER - # - - - name: Create installation directory - file: - path: "{{INSTALL_BASE}}" - state: directory - - - name: Install controller scripts - ansible.posix.synchronize: - src: "{{PROJECT_BASE}}/controller/" - dest: "{{INSTALL_BASE}}/" - delete: true - archive: false - recursive: true - - - name: template config.toml - ansible.builtin.template: - src: ./malinaConfig.toml.j2 - dest: "{{INSTALL_BASE}}/malinaConfig.toml" - - - name: Install python libraries - ansible.builtin.shell: - cmd: "poetry install" - chdir: "{{INSTALL_BASE}}" - - - # - # INSTALL FRONTEND - # - - - name: Build frontend (localhost) - delegate_to: localhost - ansible.builtin.shell: - cmd: "npm install --dev && npm run build" - chdir: "{{PROJECT_BASE}}/frontend" - - - name: Install frontend - become: true - ansible.posix.synchronize: - src: "{{PROJECT_BASE}}/frontend/dist/" - dest: "/var/www/html/" - delete: true - archive: false - recursive: true - - - name: Fix www root permission - become: true - ansible.builtin.file: - path: "/var/www/html" - owner: pi - group: pi - recurse: true - mode: 'u=rwX,g=rX,o=rX' - - # - # SERVICES - # - - - name: template target - become: true - ansible.builtin.template: - src: ./mm-controller.target.j2 - dest: /etc/systemd/system/mm-controller.target - - - name: Generate systemd services - become: true - block: - # Barco G62 (novi projektor) - - name: Barco G62 services - when: barco_G62 is defined - block: - - name: template service - become: true - vars: - script_file: "{{INSTALL_BASE}}/barco_telnet/barco_G62_control.py %i" - ansible.builtin.template: - src: ./controller_script.service.j2 - dest: /etc/systemd/system/barco@.service - - name: enable service - ansible.builtin.systemd_service: - name: "{{item}}" - enabled: true - state: restarted - daemon_reload: true - loop: - - barco@main.service - - barco@side.service - - # Lifti za projektorje (naši releji) - - name: template projector motors service - when: projector_motors is defined - block: - - name: template service - become: true - vars: - script_file: "{{INSTALL_BASE}}/projector_motors/projector_motors.py" - ansible.builtin.template: - src: ./controller_script.service.j2 - dest: /etc/systemd/system/projector_motors.service - - name: enable service - ansible.builtin.systemd_service: - name: projector_motors.service - enabled: true - state: restarted - daemon_reload: true - - # Power, platna, etc. (TSE relay box) - - name: template tse serial box service - when: tse_box is defined - block: - - name: template service - become: true - vars: - script_file: "{{INSTALL_BASE}}/tse_serial/tse_serial_controler.py" - ansible.builtin.template: - src: ./controller_script.service.j2 - dest: /etc/systemd/system/tse_box.service - - name: enable service - ansible.builtin.systemd_service: - name: tse_box.service - enabled: true - state: restarted - daemon_reload: true - - # a-rosso lučke kontroler - - name: template lucke service - when: lucke is defined - block: - - name: tmeplate service - become: true - vars: - script_file: "{{INSTALL_BASE}}/lucke/luckeControl.py" - ansible.builtin.template: - src: ./controller_script.service.j2 - dest: /etc/systemd/system/lucke.service - - name: enable service - ansible.builtin.systemd_service: - name: lucke.service - enabled: true - state: restarted - daemon_reload: true - - - - name: daemon reload - become: true - ansible.builtin.systemd_service: - daemon_reload: true diff --git a/ansible_deploy/display/inventory.yml b/ansible_deploy/display/inventory.yml deleted file mode 100644 index d801782..0000000 --- a/ansible_deploy/display/inventory.yml +++ /dev/null @@ -1,27 +0,0 @@ -predavalnice_pi: - # Skupne spremenljivke za vse zaslone - vars: - ansible_user: pi - - # Check here: https://github.com/leukipp/touchkio/releases - touchkio_version: "1.3.1" - # Multimedia network - static_ip_cidr: "24" - static_ip_gateway: "192.168.192.1" - static_ip_dns_servers: - - "212.235.188.28" - - "212.235.188.29" - hosts: - p01_touch_display: - predavalnica: p01 - static_ip: "192.168.192.111" - hostname: "p01_touch_display.local" - kiosk_url: "http://192.168.192.42?room=P01" - mqtt_host: "192.168.192.42" - - p22_touch_display: - predavalnica: p22 - static_ip: "192.168.192.112" - hostname: "p22_touch_display.local" - kiosk_url: "http://192.168.192.43?room=P22" - mqtt_host: "192.168.192.43" diff --git a/ansible_deploy/display/pi_stuff.yml b/ansible_deploy/display/pi_stuff.yml deleted file mode 100644 index 8130dc2..0000000 --- a/ansible_deploy/display/pi_stuff.yml +++ /dev/null @@ -1,37 +0,0 @@ - -# - name: Change splash image -# become: true -# copy: -# src: splash.png -# dest: /usr/share/plymouth/themes/pix/splash.png - -- name: Enable boot splash screen - become: true - shell: "raspi-config nonint get_boot_splash && raspi-config nonint do_boot_splash 0" - register: boot_splash - changed_when: - - boot_splash == "1" - -- name: Disable color splash - become: true - community.general.ini_file: - path: /boot/firmware/config.txt - option: disable_splash - value: 1 - no_extra_spaces: true - -- name: Remove desktop bloat - become: true - apt: - name: - - gvfs - - gnome-keyring - - cups - state: absent - -- name: Switch to wayfire - become: true - shell: "raspi-config nonint is_wayfire && raspi-config nonint do_wayland W2" - register: result - failed_when: ( result.rc not in [ 0, 1 ] ) - changed_when: ( result.rc == 1 ) diff --git a/ansible_deploy/display/playbook.yml b/ansible_deploy/display/playbook.yml deleted file mode 100644 index 3f05325..0000000 --- a/ansible_deploy/display/playbook.yml +++ /dev/null @@ -1,7 +0,0 @@ -- hosts: predavalnice_pi - # TODO: better include (import playbook) - tasks: - - include_tasks: static_ip.yml -# - include_tasks: wifi_temp.yml # TODO: remove this when we don't need wifi anymore - - include_tasks: pi_stuff.yml - - include_tasks: touch_display.yml diff --git a/ansible_deploy/display/static_ip.yml b/ansible_deploy/display/static_ip.yml deleted file mode 100644 index bea6891..0000000 --- a/ansible_deploy/display/static_ip.yml +++ /dev/null @@ -1,32 +0,0 @@ -- name: Configure static IP address (using Network Manager) - become: yes - community.general.nmcli: - conn_name: "Multimedia net" - ifname: eth0 - type: ethernet - ip4: "{{ static_ip }}/{{ static_ip_cidr }}" - # Sorry timi - method6: disabled - # Multimedia net doesn't have Internet access, so this iface shouldn't be used for Internet access - never_default4: true - routes4_extended: - - ip: 192.168.0.0/16 - next_hop: "{{ static_ip_gateway }}" - metric: 9999 - - ip: 10.0.0.0/8 - next_hop: "{{ static_ip_gateway }}" - metric: 9999 - # gw4: "{{ static_ip_gateway }}" - state: present - conn_reload: true - -- name: Wait for network to be available - become: yes - wait_for_connection: - timeout: 60 - -- name: Display new IP configuration - debug: - msg: "Static IP configured: {{ static_ip }}/{{ static_ip_cidr }}" - - diff --git a/ansible_deploy/display/touch_display.yml b/ansible_deploy/display/touch_display.yml deleted file mode 100644 index f95e62f..0000000 --- a/ansible_deploy/display/touch_display.yml +++ /dev/null @@ -1,38 +0,0 @@ -- name: Fix fonts - become: true - apt: - name: - - fonts-noto-core - state: present - -- name: Download .deb file - get_url: - url: "https://github.com/leukipp/touchkio/releases/download/v{{ touchkio_version }}/touchkio_{{ touchkio_version }}_arm64.deb" - dest: "/home/pi/touchkio_{{ touchkio_version }}_arm64.deb" - register: deb_download - -- name: Install the latest .deb package - become: yes - apt: - deb: "/home/pi/touchkio_{{ touchkio_version }}_arm64.deb" - when: deb_download is succeeded - -- name: Create systemd user service directory - file: - path: "{{ ansible_env.HOME }}/.config/systemd/user" - state: directory - -- name: Create systemd user service - template: - src: touchkio.service.j2 - dest: "{{ ansible_env.HOME }}/.config/systemd/user/touchkio.service" - -- name: Enable systemd service - ansible.builtin.systemd_service: - name: touchkio - enabled: true - state: restarted - scope: user - daemon_reload: true - - when: ansible_check_mode == false diff --git a/ansible_deploy/display/touchkio.service.j2 b/ansible_deploy/display/touchkio.service.j2 deleted file mode 100644 index 3cbd11b..0000000 --- a/ansible_deploy/display/touchkio.service.j2 +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Kiosk browser -After=graphical.target - -[Service] -ExecStart=/usr/bin/touchkio --web-url="{{ kiosk_url }}" --web-zoom=1.0 "--mqtt-url=mqtt://{{ mqtt_host }}" -#ExecStart=/usr/bin/chromium-browser --ozone-platform=x11 --noerrdialogs --disable-infobars --kiosk --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --app="{{ kiosk_url }}" -Restart=on-failure -RestartSec=5s - -[Install] -WantedBy=default.target diff --git a/ansible_deploy/display/wifi_temp.yml b/ansible_deploy/display/wifi_temp.yml deleted file mode 100644 index 4c45096..0000000 --- a/ansible_deploy/display/wifi_temp.yml +++ /dev/null @@ -1,26 +0,0 @@ -- name: Set wifi country - become: true - shell: "raspi-config nonint get_wifi_country && raspi-config nonint do_wifi_country SI; true" - register: wifi_country - changed_when: - - wifi_country != "SI" - -- name: Configure P2P wifi - become: yes - community.general.nmcli: - conn_name: "MALINCA" - ifname: wlan0 - type: wifi - ssid: "MALINCA" - wifi_sec: - key-mgmt: wpa-psk - psk: "MALINCA123" - autoconnect: true - method4: auto - state: present - -- name: Restart NetworkManager - become: yes - service: - name: NetworkManager - state: restarted diff --git a/ansible_deploy/inventory.ini b/ansible_deploy/inventory.ini new file mode 100644 index 0000000..da9d595 --- /dev/null +++ b/ansible_deploy/inventory.ini @@ -0,0 +1,4 @@ +[prHosts] +192.168.122.245 + + diff --git a/ansible_deploy/inventory.yml b/ansible_deploy/inventory.yml new file mode 100644 index 0000000..121412d --- /dev/null +++ b/ansible_deploy/inventory.yml @@ -0,0 +1,21 @@ +P01: + hosts: + 192.168.122.245: + vars: + room: P01 + mqtt_ip: localhost + mqtt_port: 1883 + + barco_G62: + - position: main + model: barco_G62 + port: 3023 + ip: localhost #for testirovanje + # ip: 192.168.192.13 + # - position : side + # model: barco_G62 + # port: 3023 + # ip: 192.168.192.14 + tse_box: + serial_device: /dev/ttyUSB0 + \ No newline at end of file diff --git a/ansible_deploy/malinca.yml b/ansible_deploy/malinca.yml new file mode 100644 index 0000000..edf453a --- /dev/null +++ b/ansible_deploy/malinca.yml @@ -0,0 +1,38 @@ +P01: + hosts: + #10.32.50.170: + 192.168.192.42 + vars: + static_ip: 192.168.192.42 + static_mask: 24 + static_routers: 192.168.192.1 + static_nameservers: 192.168.192.1 + room: P01 + mqtt_ip: localhost + mqtt_port: 1883 + + barco_G62: + - position: main + model: barco_G62 + port: 3023 + # ip: localhost #for testirovanje + ip: 192.168.192.12 + - position : side + model: barco_G62 + port: 3023 + ip: 192.168.192.13 + tse_box: + serial_device: /dev/ttyUSB0 + + projector_motors: + - position: main + i2c_address: 0x42 + offset: 0 #for when using single 8 channel relay board + - position: side + i2c_address: 0x43 + offset: 4 + + lucke: + url: http://192.168.190.90:8091/rest/fri-fkkt/lecture-halls/{roomId}/scenes/{sceneId}/activate + roomId: 0 + bearer_token: 0954afe1-4111-4f89-a123-fea08a55dc46 diff --git a/ansible_deploy/playbook.yaml b/ansible_deploy/playbook.yaml new file mode 100644 index 0000000..cb79108 --- /dev/null +++ b/ansible_deploy/playbook.yaml @@ -0,0 +1,211 @@ +- name: Test playbook + vars: + # TODO: maybe don't hardcode this? + PROJECT_BASE: "/home/kat/Documents/polzp/fri_multimedia_rework" + hosts: P01 + + # vars_files: + # - secret + + # addr: "192.168.122.245" + + handlers: + - name: restart NM + ansible.builtin.service: + name: NetworkManager + state: restarted + + tasks: + - name: Ping hosts + ansible.builtin.ping: + + + - name: set eth0 static IP + become: true + community.general.nmcli: + conn_name: "Multimedia network" + ifname: eth0 + type: ethernet + ip4: "{{ static_ip }}/{{ static_mask }}" + gw4: "{{ static_routers }}" + state: present + #notify: restart NM + + + - name: Install pkgs + become: true + apt: + name: + - python3-pip + - mosquitto + - nginx + state: latest + + - name: pip install + pip: + break_system_packages: true + name: + - poetry + + + - name: check for script directory + file: + path: "/home/pi/pyServices" + state: directory + + + - name: Copy poetry conf + #become: true + ansible.builtin.copy: + #seuser: root + src: "../{{ item }}" + dest: "/home/pi/pyServices/{{ item }}" + owner: pi + group: pi + mode: '0644' + backup: yes + loop: + - poetry.lock + - pyproject.toml + - README.md + + + - name: template config.toml + ansible.builtin.template: + src: ./conf.j2 + dest: /home/pi/pyServices/malinaConfig.toml + + - name: copy python scripts + #become: true + ansible.builtin.copy: + src: "../{{ item }}" + dest: "/home/pi/pyServices" + owner: pi + group: pi + mode: '0644' + backup: yes + loop: + - barco_telnet/barco_G62_control.py + - extron_audio_matrix/extron_audio_matrix_telnet_control.py + - extron_audio_matrix/extron_audio_matrix_telnet_interpreter.py + - projector_motors/projector_motors.py + - tse_serial/tse_serial_controler.py + - tse_serial/tse_serial_interpreter.py + - lucke/luckeControl.py + # - config.toml # bruh + + + - name: poetry installation + ansible.builtin.shell: + cmd: "poetry install" + chdir: "/home/pi/pyServices" + + - name: mosquitto service and reload + become: true + ansible.builtin.systemd_service: + name: mosquitto.service + state: restarted + daemon_reload: true + + + - name: generate systemd services + become: true + block: + - name: barco services + when: barco_G62 is defined + block: + - name: template service + vars: + script_file: "/home/pi/pyServices/barco_G62_control.py %i" + ansible.builtin.template: + src: ./service.j2 + dest: /lib/systemd/system/barco@.service + - name: enable service + ansible.builtin.systemd_service: + name: "{{item}}" + enabled: true + state: restarted + loop: + - barco@main.service + - barco@side.service + + - name: template projector motors service + when: projector_motors is defined + block: + - name: template service + vars: + script_file: "/home/pi/pyServices/projector_motors.py" + ansible.builtin.template: + src: ./service.j2 + dest: /lib/systemd/system/projector_motors.service + - name: enable service + ansible.builtin.systemd_service: + name: projector_motors.service + enabled: true + state: restarted + + - name: template tse serial box service + when: tse_box is defined + block: + - name: template service + vars: + script_file: "/home/pi/pyServices/tse_serial_controler.py" + ansible.builtin.template: + src: ./service.j2 + dest: /lib/systemd/system/tse_box.service + - name: enable service + ansible.builtin.systemd_service: + name: tse_box.service + enabled: true + state: restarted + + - name: template lucke service + when: lucke is defined + block: + - name: tmeplate service + vars: + script_file: "/home/pi/pyServices/luckeControl.py" + ansible.builtin.template: + src: ./service.j2 + dest: /lib/systemd/system/lucke.service + - name: enable service + ansible.builtin.systemd_service: + name: lucke.service + enabled: true + state: restarted + + + + - name: Copy mosqitconfig + become: true + ansible.builtin.copy: + #seuser: root + src: ../mosquitto.conf + dest: /etc/mosquitto/conf.d + owner: root + group: root + mode: '0644' + backup: yes + + + - name: Build frontend + delegate_to: localhost + command: + chdir: "{{PROJECT_BASE}}/frontend/vju_display/" + cmd: "npm run build" + + - name: copy frontend to webroot + become: true + + ansible.builtin.copy: + src: "{{PROJECT_BASE}}/frontend/vju_display/dist/" + dest: /var/www/html/ + owner: root + group: www-data + mode: '0755' + backup: yes + + - name: daemon reload + become: true + ansible.builtin.systemd_service: + daemon_reload: true diff --git a/ansible_deploy/controller/controller_script.service.j2 b/ansible_deploy/service.j2 similarity index 68% rename from ansible_deploy/controller/controller_script.service.j2 rename to ansible_deploy/service.j2 index b75861a..b232bbc 100644 --- a/ansible_deploy/controller/controller_script.service.j2 +++ b/ansible_deploy/service.j2 @@ -1,7 +1,6 @@ [Unit] Description={{ script_file }} After=multi-user.target -PartOf=mm-controller.target [Service] ExecStart=/usr/local/bin/poetry run python3 -u {{ script_file }} @@ -10,7 +9,8 @@ Restart=always User=pi Group=pi RestartSec=10 -WorkingDirectory={{ INSTALL_BASE }} +WorkingDirectory=/home/pi/pyServices [Install] -WantedBy=mm-controller.target +WantedBy=multi-user.target +DefaultInstance=main \ No newline at end of file diff --git a/ansible_deploy/testbook.yaml b/ansible_deploy/testbook.yaml new file mode 100644 index 0000000..1082599 --- /dev/null +++ b/ansible_deploy/testbook.yaml @@ -0,0 +1,38 @@ +- name: test playbook + hosts: P01 + + #vars_files: + # - secret + vars: + addr: "192.168.122.245" + os_environment: + - key: VITE_MQTT_HOST + value: polztest.local + + tasks: + - name: test things + when: barco_G62 is defined + block: + #- name: ping hosts + # ansible.builtin.ping: + + - name: template config.toml + ansible.builtin.template: + src: ./conf.j2 + dest: /home/pi/conf.toml + - name: template barco systemd service + vars: + script_file: "/home/kat/pyServices/fri-mm-maline/barco_G62_control.py %i" + ansible.builtin.template: + src: ./service.j2 + dest: /home/kat/testo/barco.service + - name: enable barcos + ansible.builtin.ping: + #itd itd itd + - name: test second + when: barco_old is defined + block: + - name: pingerino + ansible.builtin.ping: + + diff --git a/barco.service b/barco.service new file mode 100644 index 0000000..653b8b8 --- /dev/null +++ b/barco.service @@ -0,0 +1,16 @@ +[Unit] +Description=Barco projector control +After=mqtt_init.service + + +[Service] +ExecStart=/usr/bin/python3 /home/rpi/barco_telnet_control.py +User=rpi +Group=rpi +Type=simple +Restart=always + + +[Install] +WantedBy=mqtt_init.service + diff --git a/barco@.service b/barco@.service new file mode 100644 index 0000000..99f9c39 --- /dev/null +++ b/barco@.service @@ -0,0 +1,16 @@ +[Unit] +Description=Barco projector control +After=multi-user.target + +[Service] +ExecStart=/usr/bin/poetry run python3 /home/kat/pyServices/fri-mm-maline/barco_G62_control.py %i +Type=simple +Restart=always +WorkingDirectory=/home/kat/pyServices/fri-mm-maline +User=kat +Group=kat +RestartSec=10 + +[Install] +WantedBy=multi-user.target +DefaultInstance=main \ No newline at end of file diff --git a/controller/barco_rlmw_http/barco_rlwm_http.py b/barco_rlmw_http/barco_rlwm_http.py similarity index 100% rename from controller/barco_rlmw_http/barco_rlwm_http.py rename to barco_rlmw_http/barco_rlwm_http.py diff --git a/controller/barco_rlmw_http/main.py b/barco_rlmw_http/main.py similarity index 100% rename from controller/barco_rlmw_http/main.py rename to barco_rlmw_http/main.py diff --git a/controller/barco_rlmw_tcp/barco_rlmw_tcp.py b/barco_rlmw_tcp/barco_rlmw_tcp.py similarity index 100% rename from controller/barco_rlmw_tcp/barco_rlmw_tcp.py rename to barco_rlmw_tcp/barco_rlmw_tcp.py diff --git a/controller/barco_rlmw_tcp/main.py b/barco_rlmw_tcp/main.py similarity index 100% rename from controller/barco_rlmw_tcp/main.py rename to barco_rlmw_tcp/main.py diff --git a/barco_telnet/barco_G62_control.py b/barco_telnet/barco_G62_control.py new file mode 100644 index 0000000..14031c1 --- /dev/null +++ b/barco_telnet/barco_G62_control.py @@ -0,0 +1,142 @@ +import asyncio +import socket +import aiomqtt +import telnetlib3 +import toml +import sys + +#GLOBALS + +room: str +barcoPosition: str +barcoIP: str +telnetPort: int +mqttPort: int +mqttIP: str +barcoReached: bool + +cmdMap = { + 'power': 'POWR', + 'shutter': 'PMUT', + 'freeze': 'FRZE' +} +reverseCmdMap = {v: k for k, v in cmdMap.items()} + + +def parse_barco_response(raw: str): + global room, barcoPosition, barcoReached + raw = raw[1:-1] # strip square brackets + #print(raw) + if raw.startswith("ERR"): + print("Projector" + room + " " + barcoPosition + " returned" + raw) + return None # TODO parse type error - "disabled control" is special case which shouldnt normally happen + cmd, status = raw.split("!", maxsplit=2) + #print(cmd + " " + status) + cmd = reverseCmdMap[cmd] + status = '1' if status == '01' else '0' + barcoReached = True + return cmd, status + + +async def barco_telnet_command(client, writer, select: str): + global room + onSub = f"{room}/projectors/{select}/#" + #print('TEST', onSub) + onMatch = f"{room}/projectors/{select}/command/+" #TODO should be set? + await client.subscribe(onSub) + #async with client.messages as msgs: + async for mesg in client.messages: + # print(mesg.topic.value) + # print(mesg.payload.decode()) + # print('on', select) + + if mesg.topic.matches(onMatch): + # print("test") + cmd = mesg.topic.value.split("/")[-1] + #val = '1' if mesg.payload.decode() == 'ON' else '0' + val = '1' if mesg.payload.decode() == '1' else '0' # refactor to direct 0 and 1 + barcoCmd = f"[{cmdMap[cmd]}{val}]" + print("Received: [" + mesg.topic.value + "] payload: [" + mesg.payload.decode() + "]") + print("Sending command to Barco: " + barcoCmd) + writer.write(barcoCmd) + + +async def barco_telnet_read_status(client, reader, select: str): + global room + while True: + output = await reader.readuntil(b']') + raw_response: str = output.decode().strip() # strip not necessary? needed for local netcat testing though + print("Received: " + raw_response + " from Barco (" + select + ')') + parsed = parse_barco_response(raw_response) + if parsed is None: + continue #TODO alert for errors + print(f"Updating topic [{parsed[0]}] with value [{parsed[1]}]") + await client.publish(f"{room}/projectors/{select}/status/{parsed[0]}", payload=parsed[1]) + + +async def barco_telnet_query_status(writer, select: str): + while True: + for val in cmdMap.values(): + print(f"Querying Barco {select} with: [{val}?]") + writer.write(f"[{val}?]" + '\r\n') # TODO test if funny CRLF necessary (it probably gets ignored) + await asyncio.sleep(0.2) # sleep between writes necessary, otherwise it gets confused. + # simultaneous commands from control could break this? TODO fix later + await asyncio.sleep(10) # TODO find appropriate period + + +# async def shell(reader, writer): +# async with aiomqtt.Client('localhost', 1883) as client: +# task_status_query = asyncio.create_task(barco_telnet_query_status(writer)) +# task_status_reader = asyncio.create_task(barco_telnet_read_status(client, reader)) +# task_control = asyncio.create_task(barco_telnet_command(client, writer)) +# await asyncio.gather(task_status_query, task_status_reader, task_control) + + +async def main(): + global room, barcoReached + global barcoPosition, barcoIP, telnetPort, mqttIP, mqttPort + if len(sys.argv) < 2: + sys.exit("No position provided") + else: + barcoPosition = sys.argv[1] + + conf = toml.load('./malinaConfig.toml') + g62Barcos = {k: v for k,v in conf["barco_G62"].items()} + currentBarco = g62Barcos[barcoPosition] + barcoIP = currentBarco['ip'] + telnetPort = int(currentBarco["port"]) + + room = conf["global"]["room"] + mqttPort = int(conf["global"]["mqttPort"]) + mqttIP = conf["global"]["mqttIp"] + barcoReached = False + try: + barcoReader, barcoWriter = await telnetlib3.open_connection(barcoIP, telnetPort) + barcoReached = True + except Exception as e: + print("Connection failed: " + barcoIP + ": " + str(e)) + barcoReached = False + finally: + async with aiomqtt.Client(mqttIP, mqttPort) as client: + task_status_query_barco = asyncio.create_task(barco_telnet_query_status(barcoWriter, barcoPosition)) + task_status_reader_barco = asyncio.create_task(barco_telnet_read_status(client, barcoReader, barcoPosition)) + task_control_barco = asyncio.create_task(barco_telnet_command(client, barcoWriter, barcoPosition)) + + await asyncio.gather(task_status_query_barco, task_status_reader_barco, task_control_barco) + await client.publish(f"{room}/projectors/{barcoPosition}/error", payload=("UNREACHABLE" if not barcoReached else "OK")) + +### fuj to, ne tk delat + +# if __name__ == '__main__': + +# loop = asyncio.get_event_loop() +# coro = telnetlib3.open_connection(mainBarcoIP, 3023, shell=shell) +# coro = telnetlib3.open_connection(mainBarcoIP, 3023, shell=shell) +# # coro = telnetlib3.open_connection('localhost', 1234, shell=shell) +# reader, writer = loop.run_until_complete(coro) +# loop.run_until_complete(writer.protocol.waiter_closed) + +#mqttIP = sys.argv[1] +#barcoIP = sys.argv[2] + +asyncio.run(main()) \ No newline at end of file diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..e08fbdf --- /dev/null +++ b/config.toml @@ -0,0 +1,14 @@ +[globals] +room = 'P01' +mqttIp = 'localhost' +mqttPort = '1883' + + +[barco.novi.glavni] +ip = '192.168.192.12' +port = '3023' + +[barco.novi.stranski] +ip = '192.168.192.16' # or smth +port = '3023' + diff --git a/controller/barco_telnet/barco_G62_control.py b/controller/barco_telnet/barco_G62_control.py deleted file mode 100644 index b2d6976..0000000 --- a/controller/barco_telnet/barco_G62_control.py +++ /dev/null @@ -1,138 +0,0 @@ -import asyncio -from collections import defaultdict -import aiomqtt -import telnetlib3 -import toml -import sys -import os - -#GLOBALS - -room: str -barcoPosition: str -barcoReached: bool - -lastState = defaultdict(lambda: None) - -cmdMap = { - 'power': 'POWR', - 'shutter': 'PMUT', - 'freeze': 'FRZE', - #'test_pattern': 'TPRN', -} -reverseCmdMap = {v: k for k, v in cmdMap.items()} - -# There needs to be a minimum time between writes. Since we have two "threads", we use a lock and a sleep in barco_send() to enforce it -lock = asyncio.Lock() - -def parse_barco_response(raw: str): - raw = raw[1:-1] # strip square brackets - - if raw.startswith("ERR"): - print("ERROR:", raw) - return None # TODO parse type error - "disabled control" is special case which shouldnt normally happen - - cmd, status = raw.split("!", maxsplit=2) - - cmd = reverseCmdMap[cmd] - status = int(status) - - barcoReached = True - return cmd, status - - -async def barco_send(writer, value): - async with lock: - writer.write(value + '\r\n') - print("Writing", value) - await asyncio.sleep(0.2) # sleep between writes necessary, otherwise it gets confused. - -async def barco_telnet_command(client, writer, select: str): - """Receive commands from MQTT and send them to the projector""" - await client.subscribe(f"{room}/projectors/{select}/#") - - async for mesg in client.messages: - - if mesg.topic.matches(f"{room}/projectors/{select}/set/+"): - cmd = mesg.topic.value.rsplit("/", maxsplit=1)[-1] - val = mesg.payload.decode() - - if val not in ("0", "1") or cmd not in cmdMap: - print("INVALID COMMAND OR VALUE:", cmd, val) - continue - - barcoCmd = cmdMap[cmd] - # Send command to projector - await barco_send(writer, f"[{barcoCmd}{val}]") - # Immediately ask for a status - await barco_send(writer, f"[{barcoCmd}?]") - - -async def barco_telnet_read_status(client, reader, select: str): - """Read status reports (we trigger them in the polling task as well as whenver sending a command)""" - while True: - output = await reader.readuntil(b']') - raw_response: str = output.decode() - print("Received: " + raw_response + " from Barco (" + select + ')') - - try: - key, val = parse_barco_response(raw_response) - except: - print("NOT PARSED:", raw_response) - continue - - await client.publish(f"{room}/projectors/{select}/status/{key}", payload=val) - - -async def barco_telnet_query_status(writer, select: str): - """Periodically ask the projector for its status""" - while True: - # Most queries only work when turned on, so if we're not sure, only query power - if lastState[cmdMap["power"]] == "01": - queries = cmdMap.values() - else: - queries = [cmdMap["power"]] - - for val in queries: - await barco_send(writer, f"[{val}?]") - - await asyncio.sleep(2) # TODO find appropriate period - - -async def main(): - global room, barcoReached, barcoPosition - if len(sys.argv) < 2: - sys.exit("No position provided") - else: - barcoPosition = sys.argv[1] - - config_file = os.getenv('MM_CONFIG_PATH', './malinaConfig.toml') - conf = toml.load(config_file) - room = conf['global']['room'] - mqttHost = conf['global']['mqttHost'] - mqttPort = conf['global']['mqttPort'] - - g62Barcos = {k: v for k,v in conf["barco_G62"].items()} - currentBarco = g62Barcos[barcoPosition] - barcoIP = currentBarco['ip'] - telnetPort = int(currentBarco["port"]) - - barcoReached = False - try: - barcoReader, barcoWriter = await telnetlib3.open_connection(barcoIP, telnetPort) - barcoReached = True - except Exception as e: - print("Connection failed: " + barcoIP + ": " + str(e)) - barcoReached = False - else: - async with aiomqtt.Client(mqttHost, mqttPort) as client: - task_status_query_barco = asyncio.create_task(barco_telnet_query_status(barcoWriter, barcoPosition)) - task_status_reader_barco = asyncio.create_task(barco_telnet_read_status(client, barcoReader, barcoPosition)) - task_control_barco = asyncio.create_task(barco_telnet_command(client, barcoWriter, barcoPosition)) - - await asyncio.gather(task_status_query_barco, task_status_reader_barco, task_control_barco) - await client.publish(f"{room}/projectors/{barcoPosition}/error", payload=("UNREACHABLE" if not barcoReached else "OK")) - - -if __name__ == '__main__': - asyncio.run(main()) diff --git a/controller/lucke/luckeControl.py b/controller/lucke/luckeControl.py deleted file mode 100644 index 60fece0..0000000 --- a/controller/lucke/luckeControl.py +++ /dev/null @@ -1,110 +0,0 @@ -from http import HTTPStatus - -import aiomqtt -import asyncio -import toml -import aiohttp -import os - -lucke_bearer_token: str -room: str -url: str -roomId: int|str - -async def sendSceneRequest(client, scene): - endpoint = url + f"/rest/v2/fri-fkkt/lecture-halls/{roomId}/scenes/{scene}/activate" - async with aiohttp.request("GET", endpoint, headers={"Authorization": "Bearer " + lucke_bearer_token}) as resp: - if resp.status == 204: - await client.publish(f'{room}/lucke/preset/current', payload=scene, qos=1, retain=True) - else: - print(resp.status, await resp.text()) - - -async def setLight(client, lightNum, intensity: int): - endpoint = url + f"/rest/v2/fri-fkkt/lecture-halls/{roomId}/lights/{lightNum}" - async with aiohttp.request("PUT", endpoint, headers={"Authorization": "Bearer " + lucke_bearer_token}, json={ - "stateOn": intensity != 0, - "dimmValue": intensity - }) as resp: - if resp.status == 204: - await client.publish(f'{room}/lucke/brightness/{lightNum}', payload=intensity, qos=1, retain=True) - else: - print("setLight error:", resp.status, await resp.text()) - -async def saveScene(client, sceneNum): - endpoint = url + f"/rest/v2/fri-fkkt/lecture-halls/{roomId}/scenes/{sceneNum}/save" - async with aiohttp.request("GET", endpoint, headers={"Authorization": "Bearer " + lucke_bearer_token}) as resp: - if resp.status == 204: - pass - else: - print("saveScene error:", resp.status, await resp.text()) - -async def task_luckeCommand(controlClient): - await controlClient.subscribe(f"{room}/lucke/#") - - async for mesg in controlClient.messages: - mesg: aiomqtt.Message - - if mesg.topic.matches(f"{room}/lucke/preset/recall"): - sceneNum = mesg.payload.decode() - print("Received: " + str(mesg.topic) + " payload: [" + sceneNum + "]") - await sendSceneRequest(controlClient, sceneNum) - - elif mesg.topic.matches(f"{room}/lucke/preset/save"): - sceneNum = mesg.payload.decode() - print("Received: " + str(mesg.topic) + " payload: [" + sceneNum + "]") - await saveScene(controlClient, sceneNum) - - elif mesg.topic.matches(f"{room}/lucke/set/+"): - lightNum = mesg.topic.value.rsplit("/", maxsplit=1)[-1] - try: - intensity = int(mesg.payload.decode()) - assert 0 <= intensity <= 100 - except: - print("Invalid message:", mesg) - else: - await setLight(controlClient, lightNum, intensity) - - await asyncio.sleep(0.01) - -async def task_luckePoll(client): - """Polls the API and sends light brightness to the API""" - while True: - endpoint = url + f"/rest/v2/fri-fkkt/lecture-halls/{roomId}/lights/" - async with aiohttp.ClientSession() as session: - async with session.get(endpoint, headers={"Authorization": f"Bearer {lucke_bearer_token}"}) as response: - if response.status == 200: - lights = await response.json() - for light in lights: - await client.publish(f'{room}/lucke/is_dimmable/{light["id"]}', payload=light["dimmable"], qos=1, retain=True) - # TODO: find a better way to handle non-dimmable lights - if light["stateOn"]: - dimValue = light.get("dimmValue", 100) - else: - dimValue = 0 - await client.publish(f'{room}/lucke/brightness/{light["id"]}', payload=dimValue, qos=1, retain=True) - - else: - print(f"Failed to fetch lights: {response.status}", await response.text()) - await asyncio.sleep(.5) - -async def main(): - global room, lucke_bearer_token, url, roomId - - config_file = os.getenv('MM_CONFIG_PATH', './malinaConfig.toml') - conf = toml.load(config_file) - room = conf['global']['room'] - mqttHost = conf['global']['mqttHost'] - mqttPort = conf['global']['mqttPort'] - - url = conf["lucke"]['url'] - roomId = conf["lucke"]['roomId'] - lucke_bearer_token = conf["lucke"]['bearer_token'] - - async with aiomqtt.Client(mqttHost, mqttPort) as client: - task_control = asyncio.create_task(task_luckeCommand(client)) - task_control = asyncio.create_task(task_luckePoll(client)) - await asyncio.gather(task_control) - -if __name__ == '__main__': - asyncio.run(main()) diff --git a/controller/malinaConfig.toml b/controller/malinaConfig.toml deleted file mode 100644 index 014f231..0000000 --- a/controller/malinaConfig.toml +++ /dev/null @@ -1,17 +0,0 @@ -[global] -mqttHost = '192.168.192.42' -mqttPort = 1883 -room = 'P01' - -[lucke] -url = 'http://192.168.190.90' -roomId = 1 -bearer_token = '0954afe1-4111-4f89-a123-fea08a55dc46' - -[barco_G62.main] -ip = '192.168.192.12' -port = 3023 - -[barco_G62.side] -ip = '192.168.192.13' -port = 3023 diff --git a/controller/projector_motors/projector_motors.py b/controller/projector_motors/projector_motors.py deleted file mode 100644 index 4a4a48b..0000000 --- a/controller/projector_motors/projector_motors.py +++ /dev/null @@ -1,147 +0,0 @@ -MOCK = False -import aiomqtt -import asyncio -from smbus2 import SMBus -import toml -import os - -room: str -use_offset = False - -""" 0 1 2 3 """ -relayMasks = [0b0001, 0b0010, 0b0100, 0b1000] #probably ne rabim - -bus = SMBus(1) - -i2c_map = { - 'main': -1, - 'side': -1, -} - -relMapping = { - 'service_down': 0, - 'service_up': 1, - 'down': 2, - 'up': 3 -} - -currentState = { - 'main': 0b0000, - 'side': 0b0000 -} - -async def msgRelayBoard(projSelect, command, state: bool): - # Select the correct relay board - i2c_addr = i2c_map[projSelect] - - # Get the relay position for the given command - maskShift = relMapping[command] - # Set the corresponding bit - mask = (1 << maskShift) - if state: - currentState[projSelect] = currentState[projSelect] | mask - else: - currentState[projSelect] = currentState[projSelect] & ~mask - - # Write it to the I2C bus (0x10 is the register for relay states) - bus.write_byte_data(i2c_addr, 0x10, currentState[projSelect]) - print(projSelect, "{:04b}".format(currentState[projSelect])) - - -""" - SrvDwn SrvUp OpDwn OpUp -MAIN: 0x42 0001 0010 0100 1000 -SIDE: 0x43 0001 0010 0100 1000 -""" - - -#old board -""" -MAIN: SrvDwn SrvUp OpDwn OpUp - 0 1 2 3 -SIDE: 4 5 6 7 -""" -#dej like bolš to podukumentiraj or smth - -async def task_command2relays(controlClient: aiomqtt.Client): - """Read commands from MQTT and send them to the relays""" - - await controlClient.subscribe(f"{room}/projectors/+/lift/#") - - async for mesg in controlClient.messages: - msgTopicArr = mesg.topic.value.split('/') - value = mesg.payload.decode() - - if mesg.topic.matches(f'{room}/projectors/+/lift/manual/+'): - command = msgTopicArr[-1] - projSel = msgTopicArr[-4] - - if projSel not in ("main", "side") or command not in relMapping.keys() or value not in ("0", "1"): - print("Invalid manual command:", projSel, command, value) - continue - - await msgRelayBoard(projSel, command, value == '1') - - # Service move - if "service" in command: - # Manual control makes the position unknown, so we clear it - if value == "1": - status = "MOVING" - else: - status = "STOPPED" - await controlClient.publish(f'{room}/projectors/{projSel}/lift/status', payload=status, qos=1, retain=True) - # Normal move - else: - # HACK: if the press is too short it doesn't register, so we sleep for a bit - if value == "1": - await asyncio.sleep(.2) - - #print("Pushing \'off\' to other relays to prevent conflicts") - - elif mesg.topic.matches(f'{room}/projectors/+/lift/goto'): - projSel = msgTopicArr[-3] - - if projSel not in ("main", "side") or value not in ("UP", "DOWN"): - print("Invalid goto command:", projSel, value) - continue - - # Clear manual control - await msgRelayBoard(projSel, "service_down", False) - await msgRelayBoard(projSel, "service_up", False) - - if value == "UP": - other = "down" - elif value == "DOWN": - other = "up" - await msgRelayBoard(projSel, other, False) - - # Click the buttom for a bit and release it, then publish that the lift has moved - await msgRelayBoard(projSel, value.lower(), True) - await asyncio.sleep(1) - await msgRelayBoard(projSel, value.lower(), False) - - await controlClient.publish(f'{room}/projectors/{projSel}/lift/status', payload=value, qos=1, retain=True) - - await asyncio.sleep(0.01) - - - -async def main(): - global i2c_map, room - - config_file = os.getenv('MM_CONFIG_PATH', './malinaConfig.toml') - conf = toml.load(config_file) - room = conf['global']['room'] - mqttHost = conf['global']['mqttHost'] - mqttPort = conf['global']['mqttPort'] - - projMotors = conf["projector_motors"] - i2c_map['main'] = projMotors["main"]['i2c_address'] - i2c_map['side'] = projMotors["side"]['i2c_address'] - - async with aiomqtt.Client(mqttHost, mqttPort) as client: - task_control = asyncio.create_task(task_command2relays(client)) - await asyncio.gather(task_control) - -if __name__ == '__main__': - asyncio.run(main()) diff --git a/docs/Lučke.md b/docs/Lučke.md deleted file mode 100644 index 7d64ba5..0000000 --- a/docs/Lučke.md +++ /dev/null @@ -1,15 +0,0 @@ -Lučke v velikih predavalnicah -=== - -## Mapping po predavalnicah - -### P01 - - - 1 - Neonke tabla - - 2 - Neonke sredina - - 3 - Neonke vrata - - 4 - Okrogle 2 (vse razen ene stropne luči zgoraj) - - 5 - Neonke začetek - - 6 - Reflektorji 2 (ne dela) - - 7 - Okrogle 1 (ena stropna luč zgoraj) - - 8 - Stopnice diff --git a/eth0.notwork b/eth0.notwork new file mode 100644 index 0000000..7f7c756 --- /dev/null +++ b/eth0.notwork @@ -0,0 +1,8 @@ +[Match] + +Name=eth0 + +[Network] +Address=192.168.192.42 +Gateway=192.168.192.1 + diff --git a/extron_audio.service b/extron_audio.service new file mode 100644 index 0000000..fb6ae80 --- /dev/null +++ b/extron_audio.service @@ -0,0 +1,13 @@ +[Unit] +Description=Extron audio matrix control +After=multi-user.target + +[Service] +ExecStart=/usr/bin/python3 /home/rpi/extron_audio_matrix_telnet_control.py +Type=simple +Restart=always +User=kat +Group=kat + +[Install] +WantedBy=multi-user.target diff --git a/controller/extron_audio_matrix/extron_audio_matrix_telnet_control.py b/extron_audio_matrix/extron_audio_matrix_telnet_control.py similarity index 89% rename from controller/extron_audio_matrix/extron_audio_matrix_telnet_control.py rename to extron_audio_matrix/extron_audio_matrix_telnet_control.py index ae71d7e..52a8180 100644 --- a/controller/extron_audio_matrix/extron_audio_matrix_telnet_control.py +++ b/extron_audio_matrix/extron_audio_matrix_telnet_control.py @@ -47,17 +47,12 @@ async def shell(reader, writer): async with aiomqtt.Client('localhost', 1883) as client: task_status_query = asyncio.create_task(extron_audio_telnet_status(client, writer, reader)) task_control = asyncio.create_task(extron_audio_telnet_control(client, writer)) - await asyncio.gather(task_status_query, task_control) + await asyncio.gather(task_control) if __name__ == '__main__': - config_file = os.getenv('MM_CONFIG_PATH', './malinaConfig.toml') - conf = toml.load(config_file) - room = conf['global']['room'] - mqttHost = conf['global']['mqttHost'] - mqttPort = conf['global']['mqttPort'] - loop = asyncio.get_event_loop() + #coro = telnetlib3.open_connection('localhost', 1234, shell=shell) coro = telnetlib3.open_connection('192.168.192.14', 23, shell=shell) reader, writer = loop.run_until_complete(coro) loop.run_until_complete(writer.protocol.waiter_closed) diff --git a/controller/extron_audio_matrix/extron_audio_matrix_telnet_interpreter.py b/extron_audio_matrix/extron_audio_matrix_telnet_interpreter.py similarity index 100% rename from controller/extron_audio_matrix/extron_audio_matrix_telnet_interpreter.py rename to extron_audio_matrix/extron_audio_matrix_telnet_interpreter.py diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index 94a63a9..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,17 +0,0 @@ -## Project Setup - -```sh -npm install -``` - -### Compile and Hot-Reload for Development - -```sh -npm run dev -``` - -### Type-Check, Compile and Minify for Production - -```sh -npm run build -``` diff --git a/frontend/src/components/LectureModule.vue b/frontend/src/components/LectureModule.vue deleted file mode 100644 index f2c83e3..0000000 --- a/frontend/src/components/LectureModule.vue +++ /dev/null @@ -1,128 +0,0 @@ - - - - - diff --git a/frontend/src/components/Lift.vue b/frontend/src/components/Lift.vue deleted file mode 100644 index 9b3951c..0000000 --- a/frontend/src/components/Lift.vue +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - diff --git a/frontend/src/components/LightControl.vue b/frontend/src/components/LightControl.vue deleted file mode 100644 index 5de361c..0000000 --- a/frontend/src/components/LightControl.vue +++ /dev/null @@ -1,122 +0,0 @@ - - - - - diff --git a/frontend/src/components/ProjectorShutter.vue b/frontend/src/components/ProjectorShutter.vue deleted file mode 100644 index 3cbfdcb..0000000 --- a/frontend/src/components/ProjectorShutter.vue +++ /dev/null @@ -1,63 +0,0 @@ - - - - - diff --git a/frontend/src/components/tabs/Tab.vue b/frontend/src/components/tabs/Tab.vue deleted file mode 100644 index 53747d6..0000000 --- a/frontend/src/components/tabs/Tab.vue +++ /dev/null @@ -1,39 +0,0 @@ - - - - diff --git a/frontend/src/components/tabs/VerticalTabs.vue b/frontend/src/components/tabs/VerticalTabs.vue deleted file mode 100644 index 9161292..0000000 --- a/frontend/src/components/tabs/VerticalTabs.vue +++ /dev/null @@ -1,16 +0,0 @@ - - - diff --git a/frontend/.env.development b/frontend/vju_display/.env.development similarity index 100% rename from frontend/.env.development rename to frontend/vju_display/.env.development diff --git a/frontend/.gitignore b/frontend/vju_display/.gitignore similarity index 100% rename from frontend/.gitignore rename to frontend/vju_display/.gitignore diff --git a/frontend/vju_display/.vscode/extensions.json b/frontend/vju_display/.vscode/extensions.json new file mode 100644 index 0000000..a7cea0b --- /dev/null +++ b/frontend/vju_display/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["Vue.volar"] +} diff --git a/frontend/vju_display/README.md b/frontend/vju_display/README.md new file mode 100644 index 0000000..3c39275 --- /dev/null +++ b/frontend/vju_display/README.md @@ -0,0 +1,33 @@ +# vju_display + +This template should help get you started developing with Vue 3 in Vite. + +## Recommended IDE Setup + +[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur). + +## Type Support for `.vue` Imports in TS + +TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types. + +## Customize configuration + +See [Vite Configuration Reference](https://vite.dev/config/). + +## Project Setup + +```sh +npm install +``` + +### Compile and Hot-Reload for Development + +```sh +npm run dev +``` + +### Type-Check, Compile and Minify for Production + +```sh +npm run build +``` diff --git a/frontend/env.d.ts b/frontend/vju_display/env.d.ts similarity index 100% rename from frontend/env.d.ts rename to frontend/vju_display/env.d.ts diff --git a/frontend/index.html b/frontend/vju_display/index.html similarity index 90% rename from frontend/index.html rename to frontend/vju_display/index.html index 3647951..a888544 100644 --- a/frontend/index.html +++ b/frontend/vju_display/index.html @@ -4,7 +4,7 @@ - MMM krmilnik + Vite App
diff --git a/frontend/package-lock.json b/frontend/vju_display/package-lock.json similarity index 100% rename from frontend/package-lock.json rename to frontend/vju_display/package-lock.json diff --git a/frontend/package.json b/frontend/vju_display/package.json similarity index 100% rename from frontend/package.json rename to frontend/vju_display/package.json diff --git a/frontend/vju_display/public/favicon.ico b/frontend/vju_display/public/favicon.ico new file mode 100644 index 0000000..df36fcf Binary files /dev/null and b/frontend/vju_display/public/favicon.ico differ diff --git a/frontend/src/App.vue b/frontend/vju_display/src/App.vue similarity index 85% rename from frontend/src/App.vue rename to frontend/vju_display/src/App.vue index d69ac95..32334e9 100644 --- a/frontend/src/App.vue +++ b/frontend/vju_display/src/App.vue @@ -14,10 +14,19 @@ document.addEventListener('contextmenu', event => event.preventDefault()); let urlParams = new URLSearchParams(window.location.search); -const currentRoom = ref(urlParams.get('room') || 'none') + +const currentRoom = ref(urlParams.get('room') || 'none') // if no param specified + +const debugFlag = ref(urlParams.get('debug') == 'true'); + +// should also check if valid room parameter ampak se ne mudi +// TODO does this make sense al se naj naprej defaulta kr na p01? + const pageNum = ref(0) + + const mqttStat = ref($mqtt.status()) watch(mqttStat, (_, newState) => { @@ -38,7 +47,7 @@ watch(pageNum, (_, newState) => { diff --git a/frontend/vju_display/src/components/Lift.vue b/frontend/vju_display/src/components/Lift.vue new file mode 100644 index 0000000..de00b71 --- /dev/null +++ b/frontend/vju_display/src/components/Lift.vue @@ -0,0 +1,140 @@ + + + + + + + diff --git a/frontend/src/components/MasterPowerControlModule.vue b/frontend/vju_display/src/components/MasterPowerControlModule.vue similarity index 100% rename from frontend/src/components/MasterPowerControlModule.vue rename to frontend/vju_display/src/components/MasterPowerControlModule.vue diff --git a/frontend/src/components/Numpad.vue b/frontend/vju_display/src/components/Numpad.vue similarity index 92% rename from frontend/src/components/Numpad.vue rename to frontend/vju_display/src/components/Numpad.vue index d9cdad2..285d427 100644 --- a/frontend/src/components/Numpad.vue +++ b/frontend/vju_display/src/components/Numpad.vue @@ -4,7 +4,6 @@ import {ref, computed} from 'vue' const emit = defineEmits(['submitPasscode']) defineProps([]) -// TODO: unhardocde this shit const correctCode = '1337' const passcodeLength = correctCode.length const enteredCode = ref('') @@ -46,13 +45,14 @@ const submit = () => {
Access Denied - + {{ enteredCode[i] ? '•' : ' ' }}
+
@@ -77,6 +77,10 @@ const submit = () => {
+ + + +
@@ -85,17 +89,19 @@ const submit = () => { button { margin: 0.1em; flex: max-content; - padding: 1em; + padding: 1.5em; text-align: center; align-self: inherit; justify-content: space-evenly; + } .keypad { display: flex; flex-direction: column; - margin: 1.5em; + margin: 2em; align-content: space-evenly; + } .keypadRow { @@ -109,15 +115,11 @@ button { .keypadFeedback { display: inline-block; text-align: center; + //border: 2px solid darkgray; background-color: lightgray; background-clip: border-box; font-size: 2em; min-height: 2em; margin-bottom: 1em; - - border: 1px solid #000000; - border-radius: 3px; - background: #ffffff; - box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; } diff --git a/frontend/src/components/Platno.vue b/frontend/vju_display/src/components/Platno.vue similarity index 100% rename from frontend/src/components/Platno.vue rename to frontend/vju_display/src/components/Platno.vue diff --git a/frontend/src/components/ProjectorPowerModule.vue b/frontend/vju_display/src/components/ProjectorPowerModule.vue similarity index 100% rename from frontend/src/components/ProjectorPowerModule.vue rename to frontend/vju_display/src/components/ProjectorPowerModule.vue diff --git a/frontend/src/components/Projektor.vue b/frontend/vju_display/src/components/Projektor.vue similarity index 89% rename from frontend/src/components/Projektor.vue rename to frontend/vju_display/src/components/Projektor.vue index add1666..bb24a36 100644 --- a/frontend/src/components/Projektor.vue +++ b/frontend/vju_display/src/components/Projektor.vue @@ -42,8 +42,6 @@ function handleIncomingMQTT(topic: string, msg: string) { function handleProjectorStatus(typ: string, msg: string) { console.log('handling status') //console.log(projStatus) - console.debug(props.room, projStatus.power, projStatus.shutter) - if (typ == 'power') { projStatus.power = msg == '1' } else if (typ == 'shutter') { projStatus.shutter = msg == '1' } else if (typ == 'freeze') { projStatus.freeze = msg == '1' } @@ -64,7 +62,7 @@ function publishMQTTMsg(topic: string, msg: string) { -const publishPrefix = ref(props.room + '/projectors/' + props.position + '/set/') +const publishPrefix = ref(props.room + '/projectors/' + props.position + '/command/') //TODO organize better, binds, etc. @@ -82,18 +80,18 @@ const projStatus = reactive({

Power

-

Shutter

-

Freeze image

-
diff --git a/frontend/src/components/ResetButton.vue b/frontend/vju_display/src/components/ResetButton.vue similarity index 100% rename from frontend/src/components/ResetButton.vue rename to frontend/vju_display/src/components/ResetButton.vue diff --git a/frontend/src/components/icons/DownIcon.vue b/frontend/vju_display/src/components/icons/DownIcon.vue similarity index 100% rename from frontend/src/components/icons/DownIcon.vue rename to frontend/vju_display/src/components/icons/DownIcon.vue diff --git a/frontend/src/components/icons/UpIcon.vue b/frontend/vju_display/src/components/icons/UpIcon.vue similarity index 100% rename from frontend/src/components/icons/UpIcon.vue rename to frontend/vju_display/src/components/icons/UpIcon.vue diff --git a/frontend/src/components/pages/AudioPage.vue b/frontend/vju_display/src/components/pages/AudioPage.vue similarity index 100% rename from frontend/src/components/pages/AudioPage.vue rename to frontend/vju_display/src/components/pages/AudioPage.vue diff --git a/frontend/src/components/pages/LightingPage.vue b/frontend/vju_display/src/components/pages/LightingPage.vue similarity index 68% rename from frontend/src/components/pages/LightingPage.vue rename to frontend/vju_display/src/components/pages/LightingPage.vue index 1d439af..d3f9dcd 100644 --- a/frontend/src/components/pages/LightingPage.vue +++ b/frontend/vju_display/src/components/pages/LightingPage.vue @@ -5,7 +5,6 @@ import {ref, onMounted, reactive} from 'vue' import {$mqtt} from 'vue-paho-mqtt' import DownIcon from '../icons/DownIcon.vue'; import UpIcon from '../icons/UpIcon.vue'; -import LightControl from '../LightControl.vue'; const props = defineProps({ room: String, @@ -86,45 +85,6 @@ function publishMQTTMsg(topic: string, msg: string) { const publishPrefix = ref(props.room + '/') -// TODO: unhardcode -const showCustom = true; - -// TODO: un-hard-code this -const lights = [ - { - id: 1, - name: "Tabla", - dimmable: true, - }, { - id: 5, - name: "Začetek", - dimmable: true, - }, { - id: 2, - name: "Sredina", - dimmable: true, - }, { - id: 3, - name: "Vrh", - dimmable: true, - }, { - id: 4, - name: "Vhod 1", - dimmable: false, - }, { - id: 7, - name: "Vhod 2", - dimmable: false, - // }, { - // id: 6, - // name: "Reflektorji 2 (ne dela)", - // dimmable: false, - }, { - id: 8, - name: "Stopnice", - dimmable: false, - } -] @@ -132,49 +92,30 @@ const lights = [
+
+

Razsvetljava

+
-
+
-
- - -
-
-
+
-
- - -
-
- -
- -

Senčila