Commit 1189b2d3 authored by 方开's avatar 方开 🍔
Browse files

Merge branch 'master' into 'dev'

# Conflicts:
#   config/cmd.json
#   config/house.json
#   measure.py
parents fd98141c 8cf2a5a0
......@@ -37,65 +37,4 @@
* crc16校验: 对应文件`crc16.py` ,支持直接将`原始硬件数据`进行校验,或者将`转换后的字符串`进行校验
## 部署运行
用supervisor来启动、停止、重启和监测该程序。
### 安装(Ubuntu系统)
```bash
sudo apt install supervisor
```
### supervisor配置
* 创建配置目录
```bash
sudo mkdir -p /etc/supervisor/conf.d
```
* 通过echo_supervisord_conf 命令生成配置文件
```
echo_supervisord_conf > /etc/supervisor/supervisord.conf
```
* 编辑supervisord.conf文件,在该文件末尾将需要运行的python程序加入到任务中,具体示例如下
```conf
....
[program:ms] ; 自定义的进程名
command=/usr/bin/python3 measure.py ; 启动命令
directory = /home/cloud-machine ;程序的启动目录
autostart=true ;supervisor启动时程序也自动重启
autorestart=true ;程序异常退出后自动重启
startsecs=10 ;启动 10 秒后没有异常退出,就当作已经正常启动了
```
### 加入自启动计划
* 通过apt方式安装的supervisor开机会自动启动,通过pip等方式安装需要手动配置
* 参考链接 [supervisor配置](http://einverne.github.io/post/2017/07/use-supervisor-to-manage-process.html)
### 启动supervisor并用supervisorctl运行软件
* 运行下面命令启动配置文件里面的进程(此示例为ms,即会运行measure.py文件)
```bash
sudo supervisord -c /etc/supervisor/supervisord.conf
```
* 查看运行状态,出现running说明程序正在运行中,出现stoped说明程序终止。
```bash
supervisorctl status
```
* 开始、停止、重启命令
```bash
supervisorctl start all #开始
supervisorctl stop all #停止
supervisorctl restart all #重启
```
待补充
\ No newline at end of file
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -40,9 +40,11 @@ class GetCmds(object):
for subData in cmds:
if subId in subData:
windStatusCmd = subData[subId][0].get("status")
print(3)
return (self.host, self.port), windStatusCmd, None
else:
print(4)
for subData in cmds:
if subId in subData:
if "pointNum" in subData:
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -8,7 +8,25 @@ measurePath = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "../../log/measure.log")
# logging
# 配置logging信息
def mainlogging():
log = logging.getLogger('')
log.setLevel(logging.DEBUG)
formatter = logging.Formatter(
"%(asctime)s - %(module)s.%(funcName)s.%(lineno)d - %(levelname)s - %(message)s")
log_file_handler = TimedRotatingFileHandler(
filename=mainPath, when="D", interval=1, encoding="utf-8")
log_file_handler.setFormatter(formatter)
log_file_handler.setLevel(logging.DEBUG)
log.addHandler(log_file_handler)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(formatter)
log.addHandler(stream_handler)
return log
# 定时测量的logging
def measurelogging():
log = logging.getLogger('')
log.setLevel(logging.DEBUG)
......@@ -16,13 +34,12 @@ def measurelogging():
"%(asctime)s - %(module)s.%(funcName)s.%(lineno)d - %(levelname)s - %(message)s")
log_file_handler = TimedRotatingFileHandler(
filename=measurePath, when="D", interval=1, encoding="utf-8",backupCount=30)
filename=measurePath, when="D", interval=1, encoding="utf-8")
log_file_handler.setFormatter(formatter)
log_file_handler.setLevel(logging.DEBUG)
log.addHandler(log_file_handler)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(formatter)
stream_handler.setLevel(logging.INFO)
log.addHandler(stream_handler)
return log
File mode changed from 100644 to 100755
This diff is collapsed.
......@@ -449,7 +449,7 @@
{
"channelId": "01",
"type": "water",
"subAddr": "12",
"subAddr": "0d",
"subId": "003",
"cerealsSpecies": "稻谷"
}
......@@ -1029,9 +1029,9 @@
"houseId": "769",
"name": "34",
"subMachine": [{
"channelId": "01,02",
"channelId": "01",
"type": "temp",
"pointNum": ["32","32"],
"pointNum": ["32"],
"subAddr": "2c",
"subId": "001"
}, {
......
{
"extertemphumi": {
"ip": "10.20.1.164",
"port": 8000,
"cmd": "03011b00000001012f"
}
{
"extertemphumi": {
"ip": "10.20.1.164",
"port": 8000,
"cmd": "03011b00000001012f"
}
}
\ No newline at end of file
File mode changed from 100644 to 100755
This diff is collapsed.
......@@ -13,3 +13,4 @@ pylint==2.3.1
six==1.12.0
typed-ast==1.3.1
wrapt==1.11.1
tenacity
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment