DHT22温湿度传感器的使用

使用python读取dht22温湿度传感器的值。

 import sys
 import Adafruit_DHT
 import requests
 import json
 url = 'https://www.3gcomet.com/iot/iot_receive.php'
 sensor = Adafruit_DHT.DHT22
 pin = 4
 humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
 if humidity is not None and temperature is not None:
     temp = '{:.1f}'.format(temperature)
     humi = '{:.1f}'.format(humidity)
     payload = {"ac":'iotofict',"loc":'CloudDC',"tem":temp,"hum":humi}
     response = requests.post(url=url,data=payload)
     print(response.text)
     #print('Temp={0:0.1f}*  Humidity={1:0.1f}%'.format(temperature, humidity))
 else:
     print('Failed to get reading. Try again!')
     sys.exit(1)

常用温湿度传感器比较

SensorDHT11DHT22 (AM2302)LM35DS18B20BME280BMP180
MeasuresTemperature
Humidity
Temperature
Humidity
TemperatureTemperatureTemperature
Humidity
Pressure
Temperature
Pressure
Communication
protocol
One-wireOne-wireAnalogOne-wireI2C
SPI
I2C
Supply
voltage
3 to 5.5V DC3 to 6V DC4 to 30 V DC3 to 5.5V DC1.7 to 3.6V (for the chip) 3.3 to 5V for the board1.8 to 3.6V (for the chip) 3.3 to 5V for the board
Temperature
range
0 to 50ºC-40 to 80ºC-55 to 150ºC-55 to 125ºC-40 to 85ºC0 to 65ºC
Accuracy+/- 2ºC (at 0 to 50ºC)+/- 0.5ºC (at -40 to 80ºC)+/-0.5ºC (at 25ºC)+/-0.5ºC (at -10 to 85ºC)+/-0.5ºC (at 25ºC)+/-0.5ºC (at 25ºC)
Support
(Arduino IDE)
Adafruit DHT Library

Adafruit Unified Sensor Library
Adafruit DHT Library

Adafruit Unified Sensor Library
analogRead()DallasTemperature

OneWire
Adafruit BME280 library

Adafruit Unified Sensor Library
Adafruit BME085

Adafruit Unified Sensor Library
Support
(MicroPython)
dht module (included in MicroPython firmware)dht module (included in MicroPython firmware)from machine import ADC
ADC().read
ds18b20 module (included in MicroPython firmware)BME280 Adafruit LibraryBMP180 module

Proxmox集群配置

使用Proxmox 5.4进行集群配置,支持冷迁移。没有配置共享存储,不支持热迁移。

1 环境准备

1.1网络

pve2 192.168.189.2 集群主

pve3 192.168.189.3

pve4 192.168.189.4

openwrt 192.168.189.254

1.2主机名

/etc/hosts

192.168.189.2 pve2 pve2.ict.com

192.168.189.3 pve3 pve3.ict.com

192.168.189.4 pve4 pve4.ict.com

1.3硬盘

除开安装系统的盘,另外有一个500G的SCSI硬盘,路径为 /dev/sdb

1.4重新生成密钥对

root@pve2:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub.

cat .ssh/id_rsa.pub > .ssh/authorized_keys

1.5改源

没有付费,那就去掉企业版的源,用免费的。

sed -i 's/deb/#deb/g' /etc/apt/sources.list.d/pve-enterprise.list

echo "deb http://download.proxmox.com/debian/pve stretch pve-no-subscription" >/etc/apt/sources.list.d/pve-install-repo.list

wget http://download.proxmox.com/debian/proxmox-ve-release-5.x.gpg -O /etc/apt/trusted.gpg.d/proxmox-ve-release-5.x.gpg

apt update && apt dist-upgrade

1.6安装常用工具

安装net-tools , ntpdate, vim,openvswitch-switch

apt install ntpdate net-tools vim

apt install openvswitch-switch

1.7同步时间

ntpdate-debian

1.8注意

三台主机都要操作第4~7步骤。

2 建立集群

2.1创建集群

通过网页操作, 在pve2上建立集群。

2.2加入集群

通过网页操作,加入时需复制主控机的信息到本机。

frp 安装与配置

1 Download

wget https://github.com/fatedier/frp/releases/download/v0.23.1/frp_0.23.1_linux_amd64.tar.gz

2 Install

tar xvf frp_0.23.1linux_amd64.tar.gz
mv frp_0.23.1_linux_amd64 frp
mv ./frp/frps /bin/
mv ./frp/frpc /bin/
mv frp /etc

3 Configure Server Service

vi /etc/frp/frps.ini

[common]

bind_port = 6666
vhost_http_port = 8666
dashboard_port = 8667
dashboard_user = comet
dashboard_pwd = 12345678
privilege_token = 3gcomet
allow_ports = 20001-49999
log_file = /var/log/frps.log
log_level = info
log_max_days = 7

4 Enable Server Service

vi /lib/systemd/system/frps.service

[Unit]
Description=frps
After=network.target

[Service]
TimeoutStartSec=30
ExecStart=/bin/frps -c /etc/frp/frps.ini
ExecStop=/bin/kill $MAINPID

[Install]
WantedBy=multi-user.target

systemctl enable frps
systemctl start frps

5 Configure Client Service

Repeat Step No.1 and Step No.2 to get frp in client mechine.

vi /etc/frp/frpc.ini

[common]

server_addr = f.3gcomet.com
server_port = 6666
privilege_token = 3gcomet

log_file = /var/log/frpc.log
log_level = info
log_max_days = 3

[ssh204]

type = tcp
local_ip = 127.0.0.1
local_port = 9230
remote_port = 20422

[web204]

type = http
local_port = 80
local_ip = 127.0.0.1
remote_port = 20480
custom_domains = test.3gcomet.com

6 Enable Client Service

vi /lib/systemd/system/frpc.service

[Unit]
Description=frpc
After=network.target

[Service]
TimeoutStartSec=30
ExecStart=/bin/frpc -c /etc/frp/frpc.ini
ExecStop=/bin/kill $MAINPID

[Install]
WantedBy=multi-user.target

systemctl enable frpc
systemctl start frpc

7 Configure DNS

set test.3gcomet.com to the frp server.

8 Connect

ssh -p 20422 test.3gcomet.com
w3m http://test.3gcomet.com:8666

在OMV4下使用树莓派3B+的无线网卡

1 更新系统

apt-get update

apt-get upgrade

2 安装rpi-update并更新

apt-get install rpi-update

rpi-update

3 更新固件

wget https://archive.raspberrypi.org/debian/pool/main/f/firmware-nonfree/firmware-brcm80211_20161130-3+rpt4_all.deb

dpkg -i firmware-brcm80211_20161130-3+rpt4_all.deb

4 连接wifi

nmtui connect

解决win10不能访问samba共享问题

0 问题情况

win10 访问samba共享(如linux、NAS等系统的共享文件夹)时,提示“你没有权限访问\IP\folder。请与网络管理员联系请求访问权限。”

1 安装cifs共享支持

在控制面板-程序和功能-启用或关闭 Windows 功能,安装 SMB 1.0/CIFS 文件共享支持中的 SMB 1.0/CIFS 客户端。

2 更改本地组策略

运行 gpedit.msc 打开本地组策略,找到计算机配置-管理模板-网络-Lanman 工作站中的不安全的来宾登录,启用该配置。

3 添加凭证

在控制面板-用户帐户-凭证管理器-管理 Windows 凭据,添加 Windows 凭据,输入samba服务器的网络地址、用户名、密码。

4 重启系统

重启 Windows 10,登录后访问samba服务器,可以利用刚才添加到用户访问到共享。

查看mysql数据库及表编码格式

1.查看数据库编码格式

1mysql> show variables like 'character_set_database';

 2.查看数据表的编码格式

1mysql> show create table <表名>;

 3.创建数据库时指定数据库的字符集

mysql>create database <数据库名> character set utf8;

4.创建数据表时指定数据表的编码格式

create table tb_books (     
name varchar(45) not null,
price double not null,
bookCount int not null,
author varchar(45) not null
)
default charset = utf8;

5.修改数据库的编码格式

mysql>alter database <数据库名> character set utf8;

6.修改数据表格编码格式

mysql>alter table <表名> character set utf8;

7.修改字段编码格式

mysql>alter table <表名> change <字段名> <字段名> <类型> character set utf8; 
mysql>alter table user change username username varchar(20) character set utf8 not null;

 8.添加外键

mysql>alter table tb_product add constraint fk_1 foreign key(factoryid) references tb_factory(factoryid); 
mysql>alter table <表名> add constraint <外键名> foreign key<字段名> REFERENCES <外表表名><字段名>;

9.删除外键

mysql>alter table tb_people drop foreign key fk_1; 
mysql>alter table <表名> drop foreign key <外键名>;

docker-compose命令

#1.docker-compose

Compose 是一款用于使用 Docker 定义和运行复杂应用的工具。借助 Compose,您可以在单个文件中 定义一个多容器应用,然后在一条命令中激增您的应用,该命令可以执行使此应用运行所需完成的全部操作。

也称为: docker-compose, fig

#2.命令
docker-compose build docker-compose build
docker-compose bundle Create a distributed application bundle from the Compose file.
docker-compose config Config validates and view the compose file.
docker-compose create Create creates containers for a service.
Docker Compose release notes Release notes for Docker Compose
docker-compose down docker-compose down
docker-compose events Receive real time events from containers.
docker-compose exec docker-compose exec
docker-compose help docker-compose help
docker-compose images Lists images used by the project.
docker-compose kill Forces running containers to stop.
docker-compose pause Pauses running containers for a service.
docker-compose port Prints the public port for a port binding.s
docker-compose ps Lists containers.
docker-compose pull Pulls service images.
docker-compose push Pushes service images.
docker-compose restart Restarts Docker Compose services.
docker-compose rm Removes stopped service containers.
docker-compose run Runs a one-off command on a service.
docker-compose scale Sets the number of containers to run for a service.
docker-compose start Starts existing containers for a service.
docker-compose stop Stops running containers without removing them.
docker-compose top Displays the running processes.
docker-compose unpause Unpauses paused containers for a service.
docker-compose up Builds, (re)creates, starts, and attaches to containers for a service.

docker笔记

#1.Install packages to allow apt to use a repository over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common

#2.Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

#3.Use the following command to set up the stable repository.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

#4.Update the apt package index.
sudo apt update

#5.Install the latest version of Docker CE
sudo apt install docker-ce

#6.Ensure that you have a supported version of Docker:
docker version

#7.Verify that Docker CE is installed correctly by running the hello-world image.
sudo docker run hello-world

#8.List the hello-world image that was downloaded to your machine:
docker image ls

#9.List the hello-world container (spawned by the image) which exits after displaying its message. If it were still running, you would not need the --all option:
docker container ls --all

#10.Search the Docker Hub for images
docker search <image>

#11.Start container
docker start <name>

#12.Attach container
docker attach <name>

#13.Commit image
docker commit -m="has update" -a="comet" ea4c82dcd15a comet/ubuntu:v2

#20.Other command
docker build -t friendlyhello . # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyhello # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello # Same thing, but in detached mode
docker container ls # List all running containers
docker container ls -a # List all containers, even those not running
docker container stop <hash> # Gracefully stop the specified container
docker container kill <hash> # Force shutdown of the specified container
docker container rm <hash> # Remove specified container from this machine
docker container rm $(docker container ls -a -q) # Remove all containers
docker image ls -a # List all images on this machine
docker image rm <image id> # Remove specified image from this machine
docker image rm $(docker image ls -a -q) # Remove all images from this machine
docker login # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag # Tag <image> for upload to registry
docker push username/repository:tag # Upload tagged image to registry
docker run username/repository:tag # Run image from a registry

#21.Docker command
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes

Reference from :https://docs.docker.com/get-started/