Working sound setup for raspis

This commit is contained in:
Martin Bauer 2020-05-10 15:25:38 +02:00
parent caf6232dfb
commit d8c9a491d1
40 changed files with 815 additions and 43 deletions

View File

@ -7,21 +7,31 @@ all:
children: children:
iot: iot:
hosts: hosts:
newrpi:
squeezelite_name: MyTestRaspberry
shairport_name: MyTestRaspberry
alsa_card_name: 0
sensor_room_name_ascii: testraum
sensor_room_name: Test Raum
heatingpi:
bedroompi: bedroompi:
squeezelite_name: BedroomPi
shairport_name: BedroomPi
alsa_card_name: Codec
sensor_room_name_ascii: schlafzimmer
sensor_room_name: Schlafzimmer
kitchenpi: kitchenpi:
squeezelite_name: KitchenPi squeezelite_name: KitchenPi
shairport_name: KitchenPi shairport_name: KitchenPi
alsa_card_name: 0 alsa_card_name: 0
sensor_room_name_ascii: kueche sensor_room_name_ascii: kueche
sensor_room_name: Küche sensor_room_name: Küche
esszimmerradio: # oben, eltern
squeezelite_name: Esszimmer
shairport_name: EsszimmerRadio
wifi_ssid: BauerWLAN
newrpi:
squeezelite_name: MyTestRaspberry
shairport_name: MyTestRaspberry
alsa_card_name: 0
sensor_room_name_ascii: testraum
sensor_room_name: Test Raum
heatingpi:
vars: vars:
ansible_user: root
ansible_python_interpreter: /usr/bin/python3 ansible_python_interpreter: /usr/bin/python3
squeezeserver: 192.168.178.80 squeezeserver: 192.168.178.80
home_assistant_url: https://ha.bauer.tech home_assistant_url: https://ha.bauer.tech

View File

@ -0,0 +1,8 @@
---
- hosts: newrpi
roles:
- pi-standard-setup
- pi-squeezelite
- pi-shairport
- pi-lirc
- pi-dhtsensor

View File

@ -0,0 +1,3 @@
---
- name: Sync alsa config
template: src=asound.conf dest=/etc/asound.conf

View File

@ -0,0 +1,3 @@
---
dht_pin: "D12"
dht_polling_sleep_time_seconds: 20

View File

@ -0,0 +1,64 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import json
import time
import multiprocessing
config = json.load(open("/etc/dht22_sensing.json"))
def send_to_home_assistant(temperature, humidity):
# print(f"Sending temperature {temperature}, humidity {humidity}")
headers = {
'x-ha-access': config['token'],
'Authorization': "Bearer {}".format(config['token'])
}
temperature_url = "{}/api/states/sensor.{}".format(
config['ha_url'], config['ha_temp_sensor_name'])
temperatur_data = {
"state": str(temperature),
"attributes": {
"device_class": "temperature",
"friendly_name": config['ha_temp_friendly_name'],
"unit_of_measurement": "°C"
}
}
requests.post(temperature_url, json=temperatur_data, headers=headers)
humidity_url = "{}/api/states/sensor.{}".format(
config['ha_url'], config['ha_humidity_sensor_name'])
humidity_data = {
"state": str(humidity),
"attributes": {
"device_class": "humidity",
"friendly_name": config['ha_humidity_friendly_name'],
"unit_of_measurement": "%"
}
}
requests.post(humidity_url, json=humidity_data, headers=headers)
def sense():
import adafruit_dht
import board
dht_device = adafruit_dht.DHT22(getattr(board, config['dht_pin']))
try:
send_to_home_assistant(dht_device.temperature, dht_device.humidity)
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
if __name__ == "__main__":
multiprocessing.set_start_method('spawn')
while True:
process = multiprocessing.Process(target=sense)
process.start()
process.join()
time.sleep(float(config['polling_sleep_time_seconds']))

View File

@ -0,0 +1,10 @@
[Unit]
Description=DHT22 Temperature Humidity Sensing
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /usr/bin/dht22_sensing
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,20 @@
---
- name: apt install libgpiod2
apt: name=libgpiod2 cache_valid_time=7200 state=present
- name: pip install adafruit-circuitpython-dht
pip:
name: adafruit-circuitpython-dht
executable: pip3
- name: Install script config
template: src=dht22_sensing.json dest=/etc/dht22_sensing.json
- name: Install script
copy: src=dht22_sensing.py dest=/usr/bin/dht22_sensing owner=root mode=u+rwx
- name: Install systemd service file
copy: src=dht22_sensing.service dest=/lib/systemd/system/
- name: Add script to autostart and start now
systemd: name=dht22_sensing state=started enabled=yes daemon_reload=yes
- name: Add to sysdweb
include_role:
name: pi-sysdweb
vars:
sysdweb_name: dht22_sensing

View File

@ -0,0 +1,12 @@
{
"ha_url": "{{home_assistant_url}}",
"token": "{{home_assistant_token}}",
"dht_pin": "{{dht_pin}}",
"polling_sleep_time_seconds": "{{dht_polling_sleep_time_seconds}}",
"ha_temp_sensor_name": "{{sensor_room_name_ascii|lower}}_dht22_temperatur",
"ha_temp_friendly_name": "{{sensor_room_name}} Temperatur",
"ha_humidity_sensor_name": "{{sensor_room_name_ascii|lower}}_dht22_luftfeuchtigkeit",
"ha_humidity_friendly_name": "{{sensor_room_name}} Luftfeuchtigkeit"
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
---
dht_pin: 12
dht_polling_sleep_time_seconds: 20

View File

@ -4,20 +4,20 @@
import requests import requests
import json import json
import time import time
import board import Adafruit_DHT
import adafruit_dht
config = json.load(open("/etc/dht22_sensing.json")) config = json.load(open("/etc/dht22_sensing.json"))
dht_device = adafruit_dht.DHT22(getattr(board, config['dht_pin']))
def send_to_home_assistant(temperature, humidity): def send_to_home_assistant(temperature, humidity):
# print(f"Sending temperature {temperature}, humidity {humidity}")
headers = { headers = {
'x-ha-access': config['token'], 'x-ha-access': config['token'],
'Authorization': "Bearer {}".format(config['token']) 'Authorization': "Bearer {}".format(config['token'])
} }
temperature_url = "{}/api/states/sensor.{}".format(config['ha_url'], config['ha_temp_sensor_name']) temperature_url = "{}/api/states/sensor.{}".format(
config['ha_url'], config['ha_temp_sensor_name'])
temperatur_data = { temperatur_data = {
"state": str(temperature), "state": str(temperature),
"attributes": { "attributes": {
@ -28,7 +28,8 @@ def send_to_home_assistant(temperature, humidity):
} }
requests.post(temperature_url, json=temperatur_data, headers=headers) requests.post(temperature_url, json=temperatur_data, headers=headers)
humidity_url = "{}/api/states/sensor.{}".format(config['ha_url'], config['ha_humidity_sensor_name']) humidity_url = "{}/api/states/sensor.{}".format(
config['ha_url'], config['ha_humidity_sensor_name'])
humidity_data = { humidity_data = {
"state": str(humidity), "state": str(humidity),
"attributes": { "attributes": {
@ -40,14 +41,9 @@ def send_to_home_assistant(temperature, humidity):
requests.post(humidity_url, json=humidity_data, headers=headers) requests.post(humidity_url, json=humidity_data, headers=headers)
def sense(): if __name__ == "__main__":
try: while True:
send_to_home_assistant(dht_device.temperature, dht_device.humidity) sensor = Adafruit_DHT.DHT22
except RuntimeError as error: humidity, temperature = Adafruit_DHT.read_retry(sensor, config['dht_pin'])
# Errors happen fairly often, DHT's are hard to read, just keep going send_to_home_assistant(temperature, humidity)
print(error.args[0]) time.sleep(float(config['polling_sleep_time_seconds']))
time.sleep(config['polling_sleep_time_seconds'])
while True:
sense()

View File

@ -0,0 +1,29 @@
---
# Use the deprecated version here instead, not the new circuitpython adafruit-circuitpython-dht version
# the new version needs a lot of CPU time and doesn't work correctly on old raspi 1
# a copy of the deprecated repo is downloaded as zip (if it goes away)
- name: Uninstall libgpiod2 (circuitpython) if present
apt: name=libgpiod2 cache_valid_time=7200 state=absent
- name: pip uninstall adafruit-circuitpython-dht
pip:
name: adafruit-circuitpython-dht
executable: pip3
state: absent
- name: pip install adafruit-dht
pip:
name: adafruit-dht
executable: pip3
- name: Install script config
template: src=dht22_sensing.json dest=/etc/dht22_sensing.json
- name: Install script
copy: src=dht22_sensing.py dest=/usr/bin/dht22_sensing owner=root mode=u+rwx
- name: Install systemd service file
copy: src=dht22_sensing.service dest=/lib/systemd/system/
- name: Add script to autostart and start now
systemd: name=dht22_sensing state=restarted enabled=yes daemon_reload=yes
- name: Add to sysdweb
include_role:
name: pi-sysdweb
vars:
sysdweb_name: dht22_sensing

View File

@ -1,8 +1,8 @@
{ {
"ha_url": "https://ha.bauer.tech", "ha_url": "{{home_assistant_url}}",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxNjkxMWIzZmQ4ZWU0NDI0OTg0MjA0ZDllMDhkNGRlMCIsImlhdCI6MTU3ODE3MDU5MSwiZXhwIjoxODkzNTMwNTkxfQ.i7CdXEZy9DV9KPHAl-msK0rOfIUlPYo4zwwJ4UGhXuc", "token": "{{home_assistant_token}}",
"dht_pin": "D12", "dht_pin": "{{dht_pin}}",
"polling_sleep_time_seconds": 5, "polling_sleep_time_seconds": "{{dht_polling_sleep_time_seconds}}",
"ha_temp_sensor_name": "{{sensor_room_name_ascii|lower}}_dht22_temperatur", "ha_temp_sensor_name": "{{sensor_room_name_ascii|lower}}_dht22_temperatur",
"ha_temp_friendly_name": "{{sensor_room_name}} Temperatur", "ha_temp_friendly_name": "{{sensor_room_name}} Temperatur",

View File

@ -1,7 +1,4 @@
- name: restart sshd ---
service:
name: sshd
state: restarted
- name: reboot - name: reboot
reboot: reboot:

View File

@ -0,0 +1,3 @@
---
dependencies:
- role: pi-alsasetup

View File

@ -0,0 +1,13 @@
---
- name: Deactivate normal audio
lineinfile:
path: /boot/config.txt
regexp: "^#?dtparam=audio=on"
line: "#dtparam=audio=on"
notify: reboot
- name: Activate Hifiberry
lineinfile:
path: /boot/config.txt
regexp: "^#?dtoverlay=hifiberry-amp"
line: "dtoverlay=hifiberry-amp"
notify: reboot

32
roles/pi-knxd/README Normal file
View File

@ -0,0 +1,32 @@
Infos zum Stick
http://busware.de/tiki-index.php?page=TUL
Blog mit Tutorial:
https://www.meintechblog.de/2018/07/tul-stick-als-knx-ip-gateway-auf-dem-raspberry-pi-einrichten-mit-knxd/
Programmieren
--------------
apt-get -y install dfu-programmer
Beim Einstecken des Sticks programmiertaste auf unterseite gedrueckt halten
sudo dfu-programmer atmega32u4 erase && sudo dfu-programmer atmega32u4 flash TPUARTtransparent.hex && sudo dfu-programmer atmega32u4 reset && sudo reboot
udev-rules
----------
udevadm info -a -n /dev/ttyACM0 | grep '{idProduct}' | head -n1
udevadm info -a -n /dev/ttyACM0 | grep '{idVendor}' | head -n1
udevadm info -a -n /dev/ttyACM0 | grep '{serial}' | head -n1
# my KNX stick
SUBSYSTEM=="tty", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="204b", ATTRS{serial}=="8543934393935171A0B1", SYMLINK+="ttyKNX"
# z-wave stick
SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="ttyZWave"
# HomeMatic stick (for fhem)
SUBSYSTEM=="tty", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="204b", ATTRS{product}=="CUL868", SYMLINK+="ttyHomeMatic"

View File

@ -0,0 +1,255 @@
:1000000093C00000ACC00000AAC00000A8C000005F
:10001000A6C00000A4C00000A2C00000A0C0000054
:100020009EC000009CC0000008C40000CBC30000BC
:1000300096C0000094C0000092C0000090C0000074
:100040008EC000008CC000008AC0000088C0000084
:1000500086C0000084C0000082C0000080C0000094
:100060007EC0000081C000007AC0000078C000009F
:1000700076C0000074C0000072C0000070C00000B4
:100080006EC000006CC000006AC0000068C00000C4
:1000900066C0000064C0000062C0000060C00000D4
:1000A0005EC000005CC000005AC0000012011001D8
:1000B00002000008EB034B2001000102DC010902F1
:1000C0003E00020100C032090400000102020100EA
:1000D000052400100104240206052406000107057A
:1000E00082030800FF09040100020A00000007055E
:1000F0000402100001070583021000010403090433
:1001000018036200750073007700610072006500DB
:100110002E006400650000003003540050005500BC
:10012000410052005400000011241FBECFEFDAE05E
:10013000DEBFCDBF11E0A0E0B1E0E8EBFFE002C020
:1001400005900D92AC31B107D9F712E0ACE1B1E006
:1001500001C01D92A034B107E1F76FD02BC750CF7B
:1001600088980895889808951F920F920FB60F925D
:1001700011242F933F938F939F93CF93DF93EF930C
:10018000FF939091CE008EB38430D9F4C8EAD1E0C9
:10019000E881F98190838881998101969983888388
:1001A0002E813F818217930721F48C819D81998351
:1001B00088832FB7F8948A859B8501969B878A87C9
:1001C0002FBFFF91EF91DF91CF919F918F913F9141
:1001D0002F910F900FBE0F901F901895089580E0FB
:1001E00091E03CC680E091E012C684B7877F84BF6F
:1001F00088E10FB6F89480936000109260000FBE03
:1002000080E090E020E80FB6F8942093610080939E
:1002100061000FBE809A8898B8D287E690E09093EC
:10022000CD008093CC0086E28093CA0082E0809368
:10023000C80088E98093C9000895EF92FF920F9358
:100240001F93CF93DF93D1DFECE1F1E02FB7F89468
:1002500088E291E091838083938382839583848372
:1002600088EA91E09783868380E890E09187808791
:10027000138612862FBFE8EAF1E02FB7F89484EBDB
:1002800091E091838083938382839583848384E345
:1002900092E09783868380E890E091878087138639
:1002A00012862FBF889878940CE111E088EAE82E36
:1002B00081E0F82E8EB391B39E7F20E0843009F464
:1002C00021E0922B91BB8FB7F894209126013091B9
:1002D00027018FBF809124019091250128173907AC
:1002E00001F180E091E0E8D497FD1BC08898E80117
:1002F000E881F98180838881998101969983888337
:100300002E813F818217930721F48C819D819983EF
:1003100088832FB7F8948A859B8501969B878A8767
:100320002FBF8FB7F894C091B201D091B3018FBFA6
:10033000209721F18898E091AA01F091AB0180E02B
:1003400091E060813FD58823C9F4F70182819381D0
:10035000019693838283268137818217930721F444
:1003600084819581938382832FB7F89482859385C6
:100370000197938782872FBF2197E9F62FB7F894CB
:1003800080912601909127012FBF892BF1F0889849
:10039000E801EA81FB813191FB83EA838E819F81B1
:1003A000E817F90721F48C819D819B838A832FB7FD
:1003B000F8948A859B8501979B878A872FBF8091B8
:1003C000C80085FFFCCF3093CE0080E091E0E3D4FD
:1003D0005FD470CFDA01923049F0933061F0913000
:1003E000F9F4ECEAF0E022E130E01EC0EEEBF0E0E0
:1003F0002EE330E019C0813049F0813018F08230AE
:1004000079F408C0ECEFF0E0849107C0E0E0F1E09F
:10041000849103C0E8E1F1E08491282F30E004C02A
:10042000E0E0F0E020E030E0ED93FC93C9010895B6
:100430009C0140913E0250913F024617570718F425
:10044000F90190E044C06115710511F0AB01F8CFDE
:100450008091E8008E778093E80040E050E0F0CF94
:100460008EB3882309F444C0853009F443C08091D9
:10047000E80083FF02C081E008958091E80082FDDA
:1004800031C08091E80080FF22C08091F3009091FC
:10049000F200782F60E0292F30E0262B372B07C0A1
:1004A00081918093F100415050402F5F3F4F4115A3
:1004B000510519F02830310598F390E028303105C6
:1004C00009F491E08091E8008E778093E80041156F
:1004D000510531F6992321F605C08EB3882341F0EA
:1004E000853041F08091E80082FFF7CF80E00895E9
:1004F00082E0089583E008959C0140913E0250916E
:100500003F024617570718F4F90190E045C06115FE
:10051000710511F0AB01F8CF8091E8008E778093E0
:10052000E80040E050E0F0CF8EB3882309F446C0E5
:10053000853009F445C08091E80083FF02C081E066
:1005400008958091E80082FD33C08091E80080FF2B
:1005500023C08091F3009091F200782F60E0292F62
:1005600030E0262B372B08C084918093F100319620
:10057000415050402F5F3F4F4115510519F0283031
:10058000310590F390E02830310509F491E0809135
:10059000E8008E778093E8004115510529F69923EC
:1005A00009F0C2CF05C08EB3882341F0853041F0F9
:1005B0008091E80082FFF7CF80E0089582E00895FF
:1005C00083E008958F708093E9008091EB00816053
:1005D0008093EB001092ED006093EC004093ED00EF
:1005E0008091EE00881F8827881F08950F931F931E
:1005F000CF93DF93062FEC0110E02AC09881992356
:1006000029F16B81E981FA812C81892F8F708730E4
:1006100018F5223010F452E001C056E040E028E026
:1006200030E003C04F5F220F331F2E173F07D0F378
:100630006295660F660F607C991F9927991F692B39
:100640004295407F452BBEDF882331F01F5F259602
:100650001017A0F281E001C080E0DF91CF911F91DF
:100660000F9108958091380288238CF403C08EB3D3
:100670008823B1F08091E80082FFF9CF8091E800F3
:100680008B778093E80008958EB3882349F080919A
:10069000E80080FFF9CF8091E8008E778093E80032
:1006A00008954091E4005091E50024E68091EC002B
:1006B00080FF23C08091E80080FD1DC08EB3882399
:1006C00011F482E00895853011F483E0089580915B
:1006D000EB0085FF02C081E008958091E4009091D5
:1006E000E5008417950711F3222311F484E008959F
:1006F0002150AC01DBCF80E008958091E80082FFBB
:10070000DDCFF9CFEF92FF920F931F934ED055D0CC
:1007100008ED10E0F80180818F7780838081806808
:10072000808380818F7D808319BC1EBA1092340231
:10073000109236021092350280EEE82EF12CF7016D
:1007400080818B7F8083F80180818160808380E05D
:1007500060E042E037DFE1EEF0E080818E7F808371
:10076000E2EEF0E080818160808380818860808318
:10077000F70180818E7F8083F80180818061808392
:100780001F910F91FF90EF900895E8EDF0E08081C8
:100790008F7E8083E7EDF0E080818160808384E05C
:1007A00082BF81E080933702ADCFE8EDF0E0808139
:1007B0008E7F80831092E20008951092DA001092EA
:1007C000E10008951F920F920FB60F9211241F930C
:1007D0002F933F934F935F936F937F938F939F9349
:1007E000AF93BF93EF93FF931091E9008091EC00DA
:1007F0001092E9008091F000877F8093F000789458
:10080000E0D01092E9008091F00088608093F000C1
:100810001F701093E900FF91EF91BF91AF919F91ED
:100820008F917F916F915F914F913F912F911F9188
:100830000F900FBE0F901F9018951F920F920FB63A
:100840000F9211242F933F934F935F936F937F9356
:100850008F939F93AF93BF93EF93FF938091E100AA
:1008600082FF0AC08091E20082FF06C08091E10011
:100870008B7F8093E1000BD28091DA0080FF1BC058
:100880008091D80080FF17C08091DA008E7F80931E
:10089000DA008091D90080FF0BC080E189BD82E140
:1008A00089BD09B400FEFDCF81E08EBB59DC03C0D9
:1008B00019BC1EBA57DC8091E10080FF17C08091FF
:1008C000E20080FF13C08091E2008E7F8093E200FF
:1008D0008091E20080618093E2008091D800806284
:1008E0008093D80019BC85E08EBBD1D18091E10006
:1008F00084FF2CC08091E20084FF28C080E189BD84
:1009000082E189BD09B400FEFDCF8091D8008F7DC2
:100910008093D8008091E1008F7E8093E1008091E8
:10092000E2008F7E8093E2008091E20081608093FC
:10093000E20080913402882331F48091E30087FD46
:1009400002C081E001C084E08EBBA1D18091E100B2
:1009500083FF26C08091E20083FF22C08091E100E6
:10096000877F8093E10082E08EBB109234028091F9
:10097000E1008E7F8093E1008091E2008E7F809382
:10098000E2008091E20080618093E20080E060E01C
:1009900042E018DE8091F00088608093F00077D10B
:1009A000FF91EF91BF91AF919F918F917F916F9147
:1009B0005F914F913F912F910F900FBE0F901F901D
:1009C00018951F93DF93CF93CDB7DEB7AC970FB6D3
:1009D000F894DEBF0FBECDBFE8E3F2E08091F100F6
:1009E000819322E0E034F207C9F7F9DB8091E80057
:1009F00083FF35C18091380230913902353009F4D6
:100A000087C0363040F43130C9F1313070F03330C6
:100A100009F025C133C0383009F4F4C0393009F485
:100A200003C1363009F01BC195C0803821F08238EF
:100A300009F015C108C090913502809136028823D3
:100A400099F0926011C080913C028F708093E90010
:100A50008091EB0090E025E0969587952A95E1F747
:100A6000982F91701092E9008091E800877F809321
:100A7000E8009093F1001092F100CFC0882319F0A4
:100A8000823009F0ECC090E08F719070009721F0F7
:100A9000029709F0E4C00CC080913A02813009F05D
:100AA000DEC010923602333069F5809336022AC0D8
:100AB00080913A02882331F520913C022F7009F48D
:100AC000CEC02093E9008091EB0080FF1BC0333043
:100AD00021F48091EB00806213C08091EB00806173
:100AE0008093EB0081E090E002C0880F991F2A9567
:100AF000E2F78093EA001092EA008091EB008860B0
:100B00008093EB001092E9008091E800877F88C015
:100B1000882309F0A4C010913A021F778091E30066
:100B20008078812B8093E3008091E800877F809319
:100B3000E80098DD8091E80080FFFCCF8091E30021
:100B400080688093E300112311F482E001C083E008
:100B50008EBB85C08058823008F081C080913A02F7
:100B600090913B0223E08C3D920709F033C083E073
:100B70008C838AE28B837FB7F894DE0115966EE052
:100B800040E050E011E2E62FF0E01093570084912E
:100B900040FF03C082958F706F5F8F70282F30E009
:100BA0008A3018F0C901C79602C0C901C0968D935A
:100BB0009D934F5F5F4F4431510529F77FBF80916F
:100BC000E800877F8093E800CE0103966AE270E038
:100BD0002FDC12C060913C02AE014F5F5F4FFADB29
:100BE000BC01009709F43BC08091E800877F8093A7
:100BF000E80089819A8180DC8091E8008B7780937E
:100C0000E8002DC0803859F58091E800877F8093F7
:100C1000E800809134028093F1008091E8008E77A3
:100C20008093E8001FDD1BC08823C9F490913A022D
:100C30009230A8F48091E800877F8093E800909339
:100C4000340210DD80913402882331F48091E30076
:100C500087FD02C081E001C084E08EBBC3DA8091D1
:100C6000E80083FF0AC08091E800877F8093E80056
:100C70008091EB0080628093EB00AC960FB6F89405
:100C8000DEBF0FBECDBFCF91DF911F9108950895B4
:100C90001F938EB3882371F01091E9008091EC00CE
:100CA0001092E9008091E80083FF01C08ADE1F7086
:100CB0001093E9001F910895FC018EB3843099F5DB
:100CC00084899589A689B7890097A105B10559F14D
:100CD00086818F708093E9008091E80082FF23C0B5
:100CE0004091F3002091F200942F80E030E0822BBD
:100CF000932B892B19F46FEF7FEF04C08091F100E3
:100D0000682F70E04091F3002091F200942F80E072
:100D100030E0822B932B892B41F48091E8008B7774
:100D20008093E80002C06FEF7FEFCB010895089534
:100D3000FC018EB3843051F584899589A689B789E1
:100D40000097A105B10511F181818F708093E900B1
:100D50004091F3002091F200942F80E030E0822B4C
:100D6000932B892BA9F09091E8008091E8008E7771
:100D70008093E80095FD0CC094DC982F882349F4FB
:100D80008091E8008E778093E80003C092E001C074
:100D900090E0892F0895FC018EB3843091F484890A
:100DA0009589A689B7890097A105B10551F0818180
:100DB0008F708093E9008091E80080FF02C0CF012E
:100DC000B7CF08951F93FC01162F8EB38430E1F442
:100DD00084899589A689B7890097A105B105A1F0F5
:100DE00081818F708093E9008091E80085FD08C0C3
:100DF0008091E8008E778093E80053DC882329F403
:100E00001093F10080E001C082E01F910895CF931C
:100E1000DF93EC014096FC018BE0DF011D928A9587
:100E2000E9F782E08C83898783E08E87CE01019683
:100E300061E0DCDB882371F0CE01069661E0D6DB51
:100E4000882341F0CE010B9661E0D0DB882319F0B6
:100E500081E001C080E0DF91CF910895CF93DF93CF
:100E6000EC018091E80083FFA2C0888190E020918E
:100E70003C0230913D022817390709F098C0809153
:100E80003902813269F0823220F4803209F08FC059
:100E90003CC0823209F46AC0833209F088C079C04C
:100EA00080913802813A09F082C08091E800877F02
:100EB0008093E8008091E80080FFFCCF8C899D89B9
:100EC000AE89BF898093F100292F3A2F4B2F5527E8
:100ED0002093F1009D01442755272093F1008B2F8B
:100EE0009927AA27BB278093F100888D8093F10072
:100EF000898D8093F1008A8D8093F1008091E800C4
:100F00008E778093E800AEDB52C080913802813248
:100F100009F04DC08091E800877F8093E80004C00D
:100F20008EB3882309F443C08091E80082FFF8CF94
:100F30008091F1009091F1002091F1003091F10049
:100F40008C8B9D8B2E8B3F8B8091F100888F8091B5
:100F5000F100898F8091F1008A8F8091E8008B7772
:100F60008093E8007FDBCE0139D921C0809138021F
:100F70008132E9F48091E800877F8093E80072DB9A
:100F800080913A0290913B02998B888BCE01CFDE03
:100F90000EC080913802813251F48091E800877F41
:100FA0008093E8005FDBCE0160913A02C0DEDF9102
:080FB000CF910895F894FFCFE2
:100FB80000831000000104100000018208000001F5
:0C0FC8000000000000000000000000001D
:00000001FF

View File

@ -0,0 +1,8 @@
#!/bin/bash
apt-get -y install dfu-programmer
dfu-programmer atmega32u4 erase
dfu-programmer atmega32u4 flash TPUARTtransparent.hex
dfu-programmer atmega32u4 reset

View File

@ -0,0 +1,50 @@
---
# Lirc needs a custom build on Raspian Buster, more details here:
# https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=235256
# https://gist.github.com/billpatrianakos/cb72e984d4730043fe79cbe5fc8f7941
- name: Create lirc config dir
file: path=/etc/lirc state=directory
- name: Install config file lirc_options.conf
copy: src=lirc_options.conf dest=/etc/lirc/lirc_options.conf
- name: Install config file lircd.conf
copy: src=lircd.conf dest=/etc/lirc/lircd.conf
- name: Install remote file
copy: src=hauppauge.conf dest=/etc/lirc/hauppauge.conf
- name: create temporary directory
tempfile:
state: directory
suffix: temp
register: tempdir
- name: Copy over lirc customly compiled lirc packages
copy:
src: debs/
dest: "{{ tempdir.path }}"
when: tempdir.path is defined
- name: Install custom lirc package 1
apt:
deb: "{{ tempdir.path }}/liblirc0_0.10.1-5.2_armhf.deb"
when: tempdir.path is defined
- name: Install custom lirc package 2
apt:
deb: "{{ tempdir.path }}/liblircclient0_0.10.1-5.2_armhf.deb"
when: tempdir.path is defined
- name: Install custom lirc package 3
apt:
deb: "{{ tempdir.path }}/lirc_0.10.1-5.2_armhf.deb"
when: tempdir.path is defined
- name: Activate overlay in boot config
lineinfile:
path: /boot/config.txt
regexp: "^#?dtoverlay=gpio-ir"
line: "dtoverlay=gpio-ir,gpio_pin=17"
register: boot_overlay
- name: Restart lircd
systemd: name=lircd state=started enabled=yes daemon_reload=yes
- name: Reboot if boot overlay changed
reboot:
when: boot_overlay.changed
- name: Add to sysdweb
include_role:
name: pi-sysdweb
vars:
sysdweb_name: lircd

View File

@ -0,0 +1,3 @@
---
shairport_sync_version: "3.3.5"
shairport_name: Unnamed Raspberry with shairport

View File

@ -0,0 +1,38 @@
---
- name: Apt install dependencies
apt:
cache_valid_time: 7200
state: present
name:
- build-essential
- git
- xmltoman
- autoconf
- automake
- libtool
- libpopt-dev
- libconfig-dev
- libasound2-dev
- avahi-daemon
- libavahi-client-dev
- libssl-dev
- libsoxr-dev
- name: Build and Install Shairport sync (may take a while)
script: "build-shairport-sync.sh ${shairport_sync_version}"
args:
creates: /usr/local/bin/shairport-sync
- name: Copy config
template: src=shairport-sync.conf dest=/etc/shairport-sync.conf
- name: Modify service file to run as root
lineinfile:
path: /lib/systemd/system/shairport-sync.service
regexp: "^#?User="
line: "User=root"
- name: Restart shairport-sync
systemd: name=shairport-sync state=restarted enabled=yes daemon_reload=yes
- name: Add to sysdweb
include_role:
name: pi-sysdweb
vars:
sysdweb_name: shairport-sync

Binary file not shown.

View File

@ -0,0 +1,36 @@
[Unit]
Description=SiS PM Control for Linux
Wants=network-online.target
After=network-online.target
Wants=systemd-udev-settle.service
After=systemd-udev-settle.service
[Install]
WantedBy=multi-user.target
[Service]
CapabilityBoundingSet=
LockPersonality=true
MemoryDenyWriteExecute=true
NoNewPrivileges=true
PrivateTmp=true
PrivateUsers=true
ProtectClock=true
ProtectControlGroups=true
ProtectHome=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectSystem=strict
RemoveIPC=true
RestrictAddressFamilies=AF_INET AF_INET6
RestrictNamespaces=true
RestrictRealtime=true
SystemCallFilter=@system-service
SystemCallArchitectures=native
UMask=177
Type=forking
ExecStart=/usr/local/bin/sispmctl -p 2638 -l
SyslogIdentifier=sispmctl
Restart=always
RestartSec=5

View File

@ -0,0 +1,21 @@
---
- name: Install dependencies
apt: name=libusb-dev cache_valid_time=7200 state=present
- name: Copy sispmctl sources
unarchive:
src: sispmctl-4.7.tar.gz
dest: /tmp
creates: /usr/local/bin/sispmctl
- name: Build and install
command: cd /tmp/sispmctl*/ && ./configure && make install
creates: /usr/local/bin/sispmctl
- name: Install systemd service file
copy: src=sispmctl.service dest=/lib/systemd/system/
- name: Add script to autostart and start now
systemd: name=sispmctl state=started enabled=yes daemon_reload=yes
- name: Add to sysdweb
include_role:
name: pi-sysdweb
vars:
sysdweb_name: sispmctl

View File

@ -0,0 +1,24 @@
Repository: https://github.com/ralph-irving/squeezelite.git
Version: 779fe9035a2dfcaeeb5335497a012d5e7241a409
Custom Makefile based on Makefile.rpi:
```Makefile
OPTS = -DLINUX -DUSE_SSL -DLINKALL -I./include -I./include/opus -I./include/alac -I/usr/local/include -s -march=armv6 -mfloat-abi=hard -mfpu=vfp
LDFLAGS=-L./lib -L/usr/local/lib -s -lgomp -lasound
include Makefile
```
Required packages:
```bash
apt-get install libasound2 libasound2-dev libflac-dev libmad0-dev libfaad-dev libmpg123-dev libvorbis-dev
```
- no RPI switch (this is only when wanting to do switiching based on GPIO headers)
- manually added -lasound (don't know why it wasn't in there)
Then just build with
make -f mymakefile (on a raspi)

Binary file not shown.

View File

@ -0,0 +1,17 @@
---
- name: Uninstall system package of squeezelite
apt: name=squeezelite state=absent
- name: Remove old config file if present
file: path=/etc/default/squeezelite state=absent
- name: Copy over custom compile version of squeezelite
copy: src=squeezelite dest=/opt/squeezelite mode=700
- name: Install systemd service file
template: src=squeezelite.service dest=/lib/systemd/system/
- name: Enable sysdweb autostart
systemd: name=squeezelite state=restarted enabled=yes daemon_reload=yes
- name: Add to sysdweb
include_role:
name: pi-sysdweb
vars:
sysdweb_name: squeezelite

View File

@ -0,0 +1,10 @@
[Unit]
Description=Squeezelite
After=network.target
[Service]
ExecStart=/opt/squeezelite -n {{squeezelite_name}} -s {{squeezeserver}} -o softvol_squeezelite
Restart=on-failure
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,2 @@
---
squeezeserver: 192.168.178.80

View File

@ -0,0 +1,3 @@
---
- name: restart-squeezelite
systemd: name=squeezelite state=restarted enabled=yes daemon_reload=yes

View File

@ -0,0 +1,13 @@
---
- name: Apt install squeezelite package
apt: name=squeezelite cache_valid_time=7200 state=present
notify: restart-squeezelite
- name: Install config file
template: src=squeezelite.cfg dest=/etc/default/squeezelite
notify: restart-squeezelite
- name: Add to sysdweb
include_role:
name: pi-sysdweb
vars:
sysdweb_name: squeezelite

View File

@ -1,3 +1,3 @@
SL_NAME="{{squeezelite_name}}" SL_NAME="{{squeezelite_name}}"
SL_SOUNDCARD="softvol_squeezelite" SL_SOUNDCARD="softvol_squeezelite"
SB_SERVER_IP="192.168.178.80" SB_SERVER_IP="{{squeezeserver}}"

View File

@ -0,0 +1,10 @@
#!/bin/bash
if /sbin/ifconfig wlan0 | /bin/grep -q "inet addr:" ; then
logger "Tested Inet connection - everything ok"
echo "Tested Inet connection - everything ok"
else
logger "Network connection down! Attempting reconnection."
echo "Network connection down! Attempting reconnection."
/sbin/ifup --force wlan0
fi

View File

@ -1,3 +1,4 @@
---
- name: restart sshd - name: restart sshd
service: service:
name: sshd name: sshd

View File

@ -27,14 +27,13 @@
command: "raspi-config nonint get_hostname" command: "raspi-config nonint get_hostname"
register: pi_hostname register: pi_hostname
changed_when: False changed_when: False
- name: Change hostname to {{ new_hostname }} - name: Change hostname {{ new_hostname }}
command: "raspi-config nonint do_hostname {{ new_hostname }}" command: "raspi-config nonint do_hostname {{ new_hostname }}"
when: new_hostname | bool and pi_hostname.stdout != new_hostname when: new_hostname | bool and pi_hostname.stdout != new_hostname
register: set_hostname register: set_hostname
notify: reboot notify: reboot
- name: Get hostname - name: Get hostname
command: "raspi-config nonint get_hostname" command: "raspi-config nonint get_hostname"
when: set_hostname.changed
register: pi_hostname register: pi_hostname
changed_when: False changed_when: False
- name: set boot mode to CLI - name: set boot mode to CLI
@ -71,15 +70,25 @@
ignore_errors: yes #to avoid error when WiFi is not present ignore_errors: yes #to avoid error when WiFi is not present
- name: Change WiFi country - name: Change WiFi country
command: "raspi-config nonint do_wifi_country {{ wifi_country }}" command: "raspi-config nonint do_wifi_country {{ wifi_country }}"
when: wifi_ssid | bool
- name: Set WiFi credentials - name: Set WiFi credentials
command: "raspi-config nonint do_wifi_ssid_passphrase {{ wifi_ssid }} {{ lookup('keepass', wifi_pass_url) }}" command: "raspi-config nonint do_wifi_ssid_passphrase {{ wifi_ssid }} {{ lookup('keepass', bauer_wifi) }}"
when: wifi_ssid | bool
- name: Copy WIFI watchdog script
copy: src=wifi-watchdog.sh dest=/usr/sbin/wifi-watchdog.sh
when: wifi_ssid | bool
- name: Run WIFI watchdog script periodically
cron:
name: "WIFI Watchdog"
minute: "*/15"
job: /usr/sbin/wifi-watchdog.sh
when: wifi_ssid | bool when: wifi_ssid | bool
# Message of the day # Message of the day
- name: Set Message of the day - name: Set Message of the day
copy: src=motd/{{ pi_hostname.stdout }} dest=/etc/motd copy: src=motd/{{ pi_hostname.stdout }} dest=/etc/motd
# LED off script # LED off script
- name: Copy led off script - name: Copy led off script
copy: src=configs/raspi-leds-off.sh dest=/usr/sbin/raspi-leds-off.sh mode="u+rwx" copy: src=raspi-leds-off.sh dest=/usr/sbin/raspi-leds-off.sh mode="u+rwx"
- name: Copy led off service - name: Copy led off service
copy: src=raspi-leds-off.service dest=/lib/systemd/system/ copy: src=raspi-leds-off.service dest=/lib/systemd/system/
- name: Activate led off servic - name: Activate led off servic

41
scripts/create-raspian-image/create-raspian-image.sh Normal file → Executable file
View File

@ -4,6 +4,8 @@ set -e # exit on error
TARGET_FOLDER="./rpi_image" TARGET_FOLDER="./rpi_image"
VERSION="2020-02-13" VERSION="2020-02-13"
VERSION_DIR="2020-02-14" # :D
echo "This script downloads raspian lite, and modifies the image to enable SSH and set hostname" echo "This script downloads raspian lite, and modifies the image to enable SSH and set hostname"
@ -14,16 +16,18 @@ fi
echo -n Hostname of new pi echo -n Hostname of new pi
read -p "Hostname of new pi [newrpi]: " RPI_HOSTNAME read -p "Hostname of new pi [newrpi]: " RPI_HOSTNAME
RPI_HOSTNAME=${HOSTNAME:-newrpi} read -p "WIFI password (leave empty for non-wifi setup) [] " WIFI_PASSWORD
RPI_HOSTNAME=${RPI_HOSTNAME:-newrpi}
SCRIPT_DIR=`pwd` SCRIPT_DIR=`pwd`
mkdir -p $TARGET_FOLDER mkdir -p $TARGET_FOLDER
cd $TARGET_FOLDER cd $TARGET_FOLDER
echo "Downloading image" echo "Downloading image"
IMG_FILE_BASENAME=${VERSION}-raspbian-buster-lite.zip IMG_FILE_BASENAME=${VERSION}-raspbian-buster-lite
wget http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-${VERSION}/${IMG_FILE_BASENAME}.zip wget http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-${VERSION_DIR}/${IMG_FILE_BASENAME}.zip
wget http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-${VERSION}/${IMG_FILE_BASENAME}.zip.sha256 wget http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-${VERSION_DIR}/${IMG_FILE_BASENAME}.zip.sha256
echo "Checksum verification" echo "Checksum verification"
@ -49,17 +53,40 @@ echo $RPI_HOSTNAME > mounted_image/system/etc/hostname
touch mounted_image/boot/ssh # startup ssh touch mounted_image/boot/ssh # startup ssh
sed -i "/^#PermitRootLogin/ cPermitRootLogin prohibit-password" mounted_image/system/etc/ssh/sshd_config sed -i "/^#PermitRootLogin/ cPermitRootLogin prohibit-password" mounted_image/system/etc/ssh/sshd_config
mkdir -p mounted_image/system/root/.ssh mkdir -p mounted_image/system/root/.ssh
cat $SCRIPT_DIR/public_keys/*.pub > mounted_image/system/root/.ssh/authorized_keys cat $SCRIPT_DIR/*.pub > mounted_image/system/root/.ssh/authorized_keys
chmod 700 mounted_image/system/root/.ssh chmod 700 mounted_image/system/root/.ssh
chmod 600 mounted_image/system/root/.ssh/authorized_keys chmod 600 mounted_image/system/root/.ssh/authorized_keys
echo "Unmounting image"
if [ -z "$WIFI_PASSWORD" ]
then
echo "Skipping WIFI setup"
else
echo "Setting up initial wifi config"
/bin/cat <<EOM >mounted_image/boot/wpa_supplicant.conf
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="WLAN"
psk="${WIFI_PASSWORD}"
}
EOM
fi
echo "Unmounting image and other cleanup"
sleep 3 # to prevent "device is busy"
umount /dev/loop42p1 umount /dev/loop42p1
umount /dev/loop42p2 umount /dev/loop42p2
losetup -d /dev/loop42 losetup -d /dev/loop42
rmdir mounted_image/boot rmdir mounted_image/boot
rmdir mounted_image/system rmdir mounted_image/system
rmdir mounted_image
rm ${IMG_FILE_BASENAME}.zip.sha256
chmod a+rw ${IMG_FILE_BASENAME}.img .
echo "" echo ""
echo "" echo ""

View File

@ -0,0 +1,22 @@
Instructions from
https://www.home-assistant.io/hassio/installation/
Normally provisioned RPI4
Preparation
```
apt-get install -y software-properties-common apparmor-utils apt-transport-https avahi-daemon ca-certificates curl dbus jq network-manager socat
systemctl disable ModemManager
systemctl stop ModemManager
curl -fsSL get.docker.com | sh
```
Install
```
curl -sL "https://raw.githubusercontent.com/home-assistant/supervised-installer/master/installer.sh" | bash -s -- -m raspberrypi4
```

8
test.yml Normal file
View File

@ -0,0 +1,8 @@
---
- hosts: bedroompi, kitchenpi
roles:
- pi-standard-setup
- pi-squeezelite-custom
- pi-shairport
- pi-lirc
- pi-dhtsensor

12
test_keepass.yml Normal file
View File

@ -0,0 +1,12 @@
---
- hosts: all
vars:
ansible_ssh_pass: raspberry
remote_user: pi
tasks:
- name: test
debug:
msg: Lookup rpi pw {{ lookup('keepass', 'default_rpi_password') }}