# Tanzo Office Automation

## Unità relay Denkovi

	Password: admin

* [User manual](http://denkovi.com/Documents/smartDen-IP-16R/Current-Version/UserManual.pdf)
* [Node-red examples](http://denkovi.com/smartden-lan-ethernet-16-relay-module-din-rail-box#examples)

## Configurazione Mosquitto

	listener 1883
	protocol mqtt
	listener 1884
	protocol websockets

## Repository GitHub

* <https://github.com/tanzilli/toa>

## Cambio Mac address su adattatori eth/usb economici

__/etc/systemd/network/00-default.link__

	[Match]
	MACAddress=00:e0:4c:53:44:58
	
	[Link]
	MACAddress=00:e0:4c:53:44:01

* Vedi <https://upon2020.com/blog/2017/07/how-to-change-your-ethernets-mac-address-on-boot-linux/>

## Configurazione Avahi

__/etc/avahi/avahi-daemon.conf__

	publish-workstation=yes

## Power over ethernet

L'alimentazione a 24 volt arriva su:

* Fili blu connessi tra loro +24 volt
* Fili marroni connessi tra loro GND

<img src="./poe.gif">

## Unità a 16 relè Denkovi

* [User manual](http://denkovi.com/Documents/smartDen-IP-16R/Current-Version/UserManual.pdf)
* [Esempio in Node-RED](http://denkovi.com/smartden-lan-ethernet-16-relay-module-din-rail-box#examples)

# Sonoff S26

<abstract>
Sul modulo SONOFF va sostituito il firmware di default con il firmware Tasmota. Per fare questo bisogna installare
l'ambiente Platform I/O sul proprio PC, scaricare i sorgenti Tasmota, compilarli e programmare il modulo 
SONOFF tramite un convertitore USB/Seriale.
</abstract>

### Installazione Platform I/O su Mac

	sudo easy_install pip
	sudo pip install -U platformio

### Installazione dei sorgenti Tasmota su Mac

	git clone https://github.com/arendst/Sonoff-Tasmota.git

### Configurazione

Edit del file __~/Sonoff-Tasmota/platformio.ini__

	env_default = sonoff

Edit del file __~/Sonoff-Tasmota/sonoff/my_user_config.h__

	#define MODULE                 SONOFF_S2X 
	
	...

	#define STA_SSID1              ""     // [Ssid1] Wifi SSID
	#define STA_PASS1              ""        // [Password1] Wifi password

	...

	define MQTT_HOST              "192.168.1.123"   // [MqttHost]



### Compilazione e programmazione

	cd ~/Sonoff-Tasmota
	sudo platformio run --target upload --upload-port /dev/tty.usbserial

### Links

* <https://github.com/arendst/Sonoff-Tasmota/wiki/Sonoff-S26-Smart-Socket>
* <https://github.com/arendst/Sonoff-Tasmota/wiki/PlatformIO-CLI>

## Appunti sullo streaming da Raspberry Camera

* [Video Streaming with Flask](https://blog.miguelgrinberg.com/post/video-streaming-with-flask)
* [Flask Video Streaming Revisited](https://blog.miguelgrinberg.com/post/flask-video-streaming-revisited)

	sudo apt update
	apt install python-flask
	sudo apt install python-picamera
	sudo apt install git
	git clone https://github.com/miguelgrinberg/flask-video-streaming.git
	cd flask-video-streaming
	python app.py
	CAMERA=pi python app.py
	
### streaming.py

	#!/usr/bin/env python
	from flask import Flask, render_template, Response
	from camera import Camera
	
	app = Flask(__name__)
	
	@app.route('/')
	def index():
	    return render_template('index.html')
	
	def gen(camera):
	    while True:
	        frame = camera.get_frame()
	        yield (b'--frame\r\n'
	               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
	
	@app.route('/video_feed')
	def video_feed():
	    return Response(gen(Camera()),
	                    mimetype='multipart/x-mixed-replace; boundary=frame')
	
	if __name__ == '__main__':
	    app.run(host='0.0.0.0', debug=True)
    
### index.html

	<html>
	  <head>
	    <title>Video Streaming Demonstration</title>
	  </head>
	  <body>
	    <h1>Video Streaming Demonstration</h1>
	    <img src="{{ url_for('video_feed') }}">
	  </body>
	</html>

## Installazione senza controllo dell'autenticazione 

	sudo apt --allow-unauthenticated update
	
## Links

* [https://www.alt-codes.net/smiley_alt_codes.php](https://www.alt-codes.net/smiley_alt_codes.php)

## Installazione librerie mqtt per Python (Paho)

	sudo apt update
	sudo install python-serial
	sudo apt install python-pip
	sudo pip install paho-mqtt
	sudo apt install python-setuptools
	sudo easy_install PyCRC

# Appunti vari

* [Mappa dislocazione prese, scatole, ecc](./mappa_prese.pdf)
* [Diagramma corrugati FM](https://www.draw.io/?state=%7B%22ids%22:%5B%221VaahzzbWY4uVNHhcqTqlhuqnKIMwN_ra%22%5D,%22action%22:%22open%22,%22userId%22:%22108220109346728266085%22%7D#G1VaahzzbWY4uVNHhcqTqlhuqnKIMwN_ra)
* [NetList](https://docs.google.com/spreadsheets/d/1SvRIi6zXq2_tHEaJYCC-caIq92unugpr1A36egU5-ls/edit#gid=0)
 
## Prospetti

* [File list](/www/primopiano/prospetti)

## Tipologie di luci

* [Faretto slim a led da incasso 12 watt Euro 5.53 + IVA](https://www.ledkia.com/it/acquistare-superslim-downlight-led-design/441-superslim-led-rotonda-12w-cornice-nera.html)
* [Plafoniera singola lampadina Edison Euro 6.34 + IVA senza lampadina](https://www.amazon.it/dp/B0728K7V7P/ref=psdc_1904594031_t2_B01N95E9IL)
* [Plafoniera a tubo 5 attacchi per lampade Edison Euro 33.5 + IVA escluse lampadine](https://www.amazon.it/Glighone-Industrial-Sospensione-Lampadario-Plafoniera/dp/B06XCM4X7K/ref=pd_sbs_201_3?_encoding=UTF8&pd_rd_i=B06XCM4X7K&pd_rd_r=be6884ec-ac97-11e8-a1f4-150dcd1d19a7&pd_rd_w=X4w1M&pd_rd_wg=F8Atb&pf_rd_i=desktop-dp-sims&pf_rd_m=A11IL2PNWYJU7H&pf_rd_p=18ac1db8-8667-475d-a3cb-dc2e0028cb9b&pf_rd_r=R9SK8FR9ETMYY663VEMB&pf_rd_s=desktop-dp-sims&pf_rd_t=40701&psc=1&refRID=R9SK8FR9ETMYY663VEMB)
* [Lampadine Edison da 60 watt Euro 2.5 + IVA](https://www.amazon.it/dp/B078698X3Y/ref=sspa_dk_detail_3?psc=1&pd_rd_i=B078698X3Y&pf_rd_m=A11IL2PNWYJU7H&pf_rd_p=8015ca79-fcdf-4197-8424-bff4cc8e0b8d&pf_rd_r=3GMY03P0J7JZP86FZPYM&pd_rd_wg=wk1BU&pf_rd_s=desktop-dp-sims&pf_rd_t=40701&pd_rd_w=H5Ydu&pf_rd_i=desktop-dp-sims&pd_rd_r=dcff9182-ace3-11e8-8c55-2d361ed6bbcc)
* [Faretto nero da 30 watt Euro 13.8 + IVA inclusa lampada](https://www.ledkia.com/it/acquistare-monofase/3469-faretto-led-dora-per-binario-monofase-30w.html)


## Codice dei colori delle pareti

* TR 4648 Base D Verde lato interno sala QE 39 MQ
* TR 4601 Base D Arancione lato interno direzione 24 MQ 
* Bianco - Paretone 52 MQ
* Bianco bagni - 32 MQ

## Prese

* [Side per Bticino Matix - Euro 4.45](https://www.manomano.it/catalogue/prese-di-corrente-da-montare/presa-elettrica-universale-bipasso-e-schuko-10-16a-2-moduli-side-4box-per-bticino-matix-5116215)
* [Cestello Matix 503 - Euro 0.72](https://www.manomano.it/supporti-per-interruttori-e-prese/bticino-matix-supporto-tt-3-posti-895498)
* [Cestello Matix 506 - Euro 2.01](https://www.manomano.it/supporti-per-interruttori-e-prese/bticino-506lsa-matix-supporto-a-6-moduli-895501?model_id=895501)
 

## Comandi vari

	sudo netstat -antp

Controllo dei messaggi in arrivo con mosquitto_sub

	mosquitto_sub -h localhost -F '%I %j' -t toa/lights/10/set_value -v
	
<https://mosquitto.org/man/mosquitto_sub-1.html>	

Log MQTT

	mosquitto_sub -h localhost -F '%I %j' -t '$SYS/broker/log/#'

@include='bio_sergio_tanzilli'
	
