主要是在无界面树莓派raspberry系统上部署【宝塔面板】、【frp内网穿透】、【domoticz智能家居系统】、【DSP8266】、【Arduino】、【DHT11温湿度传感器】、【手机domoticz客户端显示数据及控制】
*******************now 20201031 16:22**************************
一、树莓派写入新系统
1、这个页面是描述《树莓派各类操作系统大全》,下载32 位 Lite 版(无桌面),考虑是服务器应用。(官网下载,国内慢的很,我传到了天翼云盘https://cloud.189/t/zYFzyq3uIBv2)
https://shumeipai.nxez/raspberry-pi-os-collection
2、下载对应Raspberry Pi Imager,用来烧录下载好的系统文件(官网下载,国内慢的很,我传到了天翼云盘https://cloud.189/t/nMzMru73yMnq)
https://www.raspberrypi/downloads/
3、打开boot文件夹,新增两个文件 wpa_supplicant.conf、ssh
wpa_supplicant.conf中写入以下内容
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="你的WiFi名称"
psk="你的WiFi密码"
key_mgmt=WPA-PSK
priority=1
}
ssh中不写内容直接建立一个无后缀名的文件支持ssh连接
- 打开路由器管理 查看树莓派IP地址
- 用ssh工具连接树莓派 (xshell、putty)都可以
- 默认用户名密码(raspbian系统)
用户名:pi
密码:raspberry
(参考:https://blog.csdn/thewaiting/article/details/105975582)
【链接上了记得修改pi的默认密码sudo passwd pi】用用户pi进入系统之后,可以先修改root密码sudo passwd root,然后su root来切换成root用户
二、树莓派系统安装软件
1、修改apt-get源为国内(清华)
sudo apt-get install vim
修改软件源:(sudo vim /etc/apt/sources.list sudo vim /etc/apt/sources.list.d/raspi.list)
# 编辑 `/etc/apt/sources.list` 文件,删除原文件所有内容,用以下内容取代:
deb http://mirrors.tuna.tsinghua.edu/raspbian/raspbian/ buster main non-free contrib rpi
deb-src http://mirrors.tuna.tsinghua.edu/raspbian/raspbian/ buster main non-free contrib rpi
# 编辑 `/etc/apt/sources.list.d/raspi.list` 文件,删除原文件所有内容,用以下内容取代:
deb http://mirrors.tuna.tsinghua.edu/raspberrypi/ buster main ui
再sudo apt-get update更新下源
2、安装宝塔面板5.9(https://blog.csdn/no1xium/article/details/107694406)
wget -O install.sh http://download.bt/install/install-ubuntu.sh && bash install.sh
如果忘记了登录密码也没事我们可以cat /www/server/panel/default.pl
折腾完了想卸载也很方便rm -f /etc/init.d/bt && rm -rf /www/server/panel
3、安装穿透frp (
https://github/fatedier/frp/releases)
安装这个版本的在树莓派上(客户端):frp_X.XX.X_linux_arm.tar.gz
解压:tar -zxfv
进入目录之后编辑 sudo vim frpc.ini
[common]
server_addr = ***.网址.***
server_port = 服务器端口
[ssh]
type=tcp
local_ip=127.0.0.1
local_port=22
remote_port=远程ssh端口
[web]
type=http
local_ip=127.0.0.1
local_port=80
custom_domains=***.网址.***
[webpicam]这个是第二个网址
type=http
local_ip=127.0.0.1
local_port=***
custom_domains=***.网址.***
locations=/路径/
[domoticz]
type = http
custom_domains = ***.***.网址.***
local_ip = 192.168.*****
local_port = ****
use_compression = false
use_encryption = false
在宝塔面板中开启端口80,22,你需要的端口
设置frp开机启动(https://wwwblogs/zinan/p/10943781.html)
添加systemd配置文件:
vim /usr/lib/systemd/system/frp.service
文件内容如下:
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
StandardOutput=syslog
StandardError=inherit
[Install]
WantedBy=multi-user.target
ExecStart的内容请根据自己frp安装目录修改。
设置开机启动
systemctl daemon-reload
systemctl enable frp
启动 frp
systemctl start frp
查看frp是否启动
ps aux | grep frps
centos7 查看启动服务项
使用 systemctl list-unit-files 可以查看启动项
左边是服务名称,右边是状态,enabled是开机启动,disabled是开机不启动
可以使用 systemctl status xxx.service查看服务状态
****宝塔面板域名解析配置,如果增加其他域名的话直接就在下面再加一个Server
server
{
listen 80;
server_name ***.网址.***;
location ~ .* {
proxy_pass http://***.网址.***:端口;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
error_page 404 /404.html;
error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-72.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/***.网址.***.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log off;
}
access_log /www/wwwlogs/***.网址.***.log;
error_log /www/wwwlogs/***.网址.***.error.log;
}
4、树莓派安装Domoticz智能家居
最简单的方法安装Domoticz: sudo curl -L install.domoticz | bash
安装完成了进入http://IP:8080,设置里面修改语言为中文,还需要添加位置信息,才能够保存。【网站保护】https://www.domoticz/forum/viewtopic.php?t=14383、【本地网络】必须添加
在设置-》硬件 中 添加硬件类型DUMMY,名称随意,在然后【创建虚拟传感器】,选择【Temp & Hum】
这时候我们再回到树莓派SSH进去,修改时区
更改时区 and Expand file system
登录后输入以下命令:
sudo raspi-config
- 选择选项以扩展root文件系统
- 建议更改密码
- 更改为你当地的时区,时区设置在"Internationalization Options"中(不同版本不一定)
然后回到温度界面可以看到传感器
然后是ESP8266链接到domoticz,官网wiki:https://www.domoticz/wiki/ESP8266_WiFi_module
结合DHT11在Arduino中的代码(需要知道domoticz中虚拟设备的idx,在设置-》设备中可以看到):
#include <SimpleDHT.h>
#include <ESP8266WiFi.h>
int pinDHT11 = 2; // GPIO2 of ESP8266
const char* ssid = "*****";//手机Wi-Fi热点
const char* password = "******";//手机Wi-Fi密码
WiFiClient client;
SimpleDHT11 dht11(pinDHT11);
// domoticz
const char * domoticz_server = "***.***.网址.***"; //Domoticz port
int port = ***; //Domoticz port
int idx = 2; //IDX for this virtual sensor, found in Setup -> Devices
float humidity = 0;
float temp = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
setup_wifi();
}
void setup_wifi() {
delay(10);
WiFi.begin(ssid, password); // 我们从连接到WiFi网络开始
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.println("WiFi connected");
}
void loop() {
// put your main code here, to run repeatedly:
printInfo();
delay(60000);
温度湿度
}
void printInfo()
{
// Domoticz format /json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
温度湿度
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
return;
}
Serial.println(String(temperature)+" - "+String(humidity));
if (client.connect(domoticz_server,port)) {
client.print("GET /json.htm?type=command¶m=udevice&idx=");
client.print(idx);
client.print("&nvalue=0&svalue=");
client.print(String(temperature));
client.print(";");
client.print(String(humidity));
client.print(";0"); //Value for HUM_STAT. Can be one of: 0=Normal, 1=Comfortable, 2=Dry, 3=Wet
client.println(" HTTP/1.1");
client.print("Host: ");
client.print(domoticz_server);
client.print(":");
client.println(port);
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
client.stop();
}
}
数据接收成功后,下载domoticz的手机客户端:https://www.domoticz/forum/viewtopic.php?f=4&t=3&sid=11f057035d38b21ad6f695aa802c21ee
免费版:https://play.google/store/apps/deta ... s.domoticz
墙内下载(最新版20200619):https://www.jianguoyun/p/DUd26BYQh66pBhi0q7QD
高级版:https://play.google/store/apps/deta ... cz.premium
高级版支持 地理围栏、Android Wear 手表、桌面小工具,体验后我表示没什么用处。。。有能力的可以买,支持下作者。
客户端时候需要设置远程domoticz服务器:其实就是在frp中配置的domoticz的dashboard地址
*******************now 20201101 19:32**************************
更多推荐
树莓派3B+基于domoticz搭建智能家居服务器之记录
发布评论