generated from nickdante8/fw-heater-on-oil
Functional esp32 temprature collection, factory reset and OTA update (web-socket)
This commit is contained in:
@@ -1,3 +1,140 @@
|
||||
# fw-BH-barrel-automation
|
||||
|
||||
Automation of barrel control for BohemaHouse winery
|
||||
|
||||
MQTT
|
||||
* User: winery_device
|
||||
* Pass: B2h3maH@use
|
||||
|
||||
AP
|
||||
* SSID: esphome-bohemahouse-xxxxxx
|
||||
* Pass: bohemahouse
|
||||
|
||||
Local IP (OTA)
|
||||
* User: bohemahouse
|
||||
* Pass: B2h3maH@use
|
||||
|
||||
---
|
||||
|
||||
## 1. Mosquitto (MQTT Broker)
|
||||
|
||||
**Installation:**
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install -y mosquitto mosquitto-clients
|
||||
```
|
||||
|
||||
**Configuration (Authentication & WebSockets):**
|
||||
Create the password file using the credentials above:
|
||||
```bash
|
||||
sudo mosquitto_passwd -c /etc/mosquitto/passwd winery_device
|
||||
```
|
||||
|
||||
Edit the Mosquitto configuration:
|
||||
```bash
|
||||
sudo nano /etc/mosquitto/conf.d/default.conf
|
||||
```
|
||||
Add the following configuration to allow standard MQTT locally and WebSockets for external Apache proxying:
|
||||
```text
|
||||
# Standard MQTT (Local)
|
||||
listener 1883
|
||||
allow_anonymous false
|
||||
password_file /etc/mosquitto/passwd
|
||||
|
||||
# WebSockets (Required for Apache reverse proxy from outside)
|
||||
listener 9001
|
||||
protocol websockets
|
||||
```
|
||||
Restart the service:
|
||||
```bash
|
||||
sudo systemctl restart mosquitto
|
||||
```
|
||||
|
||||
## 2. Node-RED
|
||||
|
||||
**Installation:**
|
||||
Use the official installation script for Linux/Raspberry Pi:
|
||||
```bash
|
||||
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-sh-script/master/node-red-pi-setup)
|
||||
```
|
||||
|
||||
**Start and Enable on Boot:**
|
||||
```bash
|
||||
sudo systemctl enable nodered.service
|
||||
sudo systemctl start nodered.service
|
||||
```
|
||||
*Access Node-RED at: `http://<SERVER_IP>:1880`*
|
||||
|
||||
## 3. InfluxDB (v2)
|
||||
|
||||
**Installation:**
|
||||
```bash
|
||||
curl -O https://dl.influxdata.com/influxdb/releases/influxdb2_2.7.5-1_$(dpkg --print-architecture).deb
|
||||
sudo dpkg -i influxdb2_2.7.5-1_*.deb
|
||||
sudo systemctl enable --now influxdb
|
||||
```
|
||||
|
||||
**Configuration:**
|
||||
* Access the dashboard at `http://<SERVER_IP>:8086`
|
||||
* Setup Organization: `BohemaHouse`
|
||||
* Setup Bucket: `barrels`
|
||||
* Generate an **All Access API Token**. In Node-RED, install `node-red-contrib-influxdb` and use this token to connect the output node.
|
||||
|
||||
## 4. Grafana
|
||||
|
||||
**Installation:**
|
||||
```bash
|
||||
sudo apt-get install -y apt-transport-https software-properties-common wget
|
||||
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
|
||||
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
|
||||
sudo apt update
|
||||
sudo apt install -y grafana
|
||||
```
|
||||
|
||||
**Change Port (Avoids conflict with Gitea on port 3000):**
|
||||
```bash
|
||||
sudo nano /etc/grafana/grafana.ini
|
||||
```
|
||||
Find the `[server]` section, uncomment the port line, and change it:
|
||||
```ini
|
||||
http_port = 3030
|
||||
```
|
||||
|
||||
**Start and Enable on Boot:**
|
||||
```bash
|
||||
sudo systemctl enable --now grafana-server
|
||||
```
|
||||
*Access Grafana at: `http://<SERVER_IP>:3030`*
|
||||
*Note: Connect to InfluxDB using the **Flux** query language.*
|
||||
|
||||
---
|
||||
|
||||
## Remote Access (Apache Reverse Proxy for Mosquitto)
|
||||
|
||||
To safely receive MQTT packages from outside the local network using your existing Apache server, you should expose Mosquitto via **MQTT over WebSockets**.
|
||||
|
||||
1. **Enable Apache WebSocket Proxy Modules:**
|
||||
```bash
|
||||
sudo a2enmod proxy
|
||||
sudo a2enmod proxy_wstunnel
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
|
||||
2. **Apache VirtualHost Configuration:**
|
||||
Add the following `ProxyPass` rules inside your existing HTTPS `<VirtualHost *:443>` block for your domain (e.g., in `/etc/apache2/sites-available/yourdomain.conf`):
|
||||
|
||||
```apache
|
||||
# Proxy MQTT WebSockets to local Mosquitto on port 9001
|
||||
ProxyPass /mqtt ws://127.0.0.1:9001/
|
||||
ProxyPassReverse /mqtt ws://127.0.0.1:9001/
|
||||
```
|
||||
|
||||
3. **Apply Changes:**
|
||||
```bash
|
||||
sudo systemctl reload apache2
|
||||
```
|
||||
|
||||
**Connecting from the Outside:**
|
||||
Your external devices (like the ESP32 or an external web dashboard) can now connect to your MQTT broker using the WebSocket protocol over TLS:
|
||||
* **URL:** `wss://yourdomain.com/mqtt`
|
||||
* **Username/Password:** Use the `winery_device` credentials.
|
||||
|
||||
Reference in New Issue
Block a user