如何搭建流星雨监测系统,传送门:https://blog.csdn.net/delacroix_xu/article/details/119813807
此篇文章是系列第二篇,第一篇传送门:基于树莓派的流星雨监测系统(RMS)的进一步改造(1)_delacroix_xu的专栏-CSDN博客
背景
近期开始使用一个开源项目,在树莓派4B上玩耍。监测流星雨并存储下来。
https://github.com/CroatianMeteorNetwork/RMS
但该项目有个令人不爽的地方,存储下来的是.bin文件,一种自研的格式,我希望能输出gif或者mp4,方便分享到社交媒体上。
本篇新增功能
输出mp4后,增加钉钉机器人通知,后期再增加上传服务器功能
编写脚本,每日上午8:00运行,找到昨日的目录 ~/RMS_data/CapturedFiles/YESTERDAY_DIR ,执行 python -m Utils.FRbinViewer $dir -e -f mp4 --hide 尝试转换流星监测结果到 mp4视频
然后如果发现了mp4文件,则发出钉钉通知
#!/bin/sh
set -ex
xxdays=$1
DATE=`date -d "$xxdays days ago" +%Y%m%d`
DIRS=`ls ~/RMS_data/CapturedFiles/ | grep ${DATE}`
. /home/pi/py37env/bin/activate
pwd
function sendMsg ()
{
curl -sL 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{"msgtype": "text","text": {"content":"'"$1"'"}}'
}
for DIR in $DIRS;
do
python -m Utils.FRbinViewer ~/RMS_data/CapturedFiles/${DIR} -e -f mp4 --hide
NORMAL=~/RMS_data/CapturedFiles/${DIR}/output-normal.mp4
SLOW=~/RMS_data/CapturedFiles/${DIR}/output-slow.mp4
if [ -f "$NORMAL" ]; then
echo "find video file"
/bin/cp -f ~/RMS_data/CapturedFiles/${DIR}/*.fits ~/RMS_data/ArchivedFiles/${DIR}/
/bin/cp -f ~/RMS_data/CapturedFiles/${DIR}/*.mp4 ~/RMS_data/ArchivedFiles/${DIR}/
# upload video files 2 server
# TODO
MSG="发现流星, video file: http://xxxxxxxx/meteorStoreServer/get?name=${DIR}_slow.mp4"
sendMsg "$MSG"
MSG="发现流星, video file: http://xxxxxxxx/meteorStoreServer/get?name=${DIR}_normal.mp4"
sendMsg "$MSG"
curl -F "file=@$SLOW" "http://xxxxxxxx/meteorStoreServer/post?name=${DIR}_slow.mp4"
curl -F "file=@$NORMAL" "http://xxxxxxxx/meteorStoreServer/post?name=${DIR}_normal.mp4"
fi
done
添加crontab,每天早晨8点检查流星文件
0 8 * * * cd /home/pi/Desktop/RMS/RMS_new && bash detect_yestoday_fireball.sh 1 >6.txt 2>&1
注意:针对 FRbinViewer.py 的修改,见第一篇文章, 支持输出mp4视频文件
发送钉钉群的效果如下
附录
流星mp4存储服务代码
使用flask作为框架。 post接口接受文件,写入目录。 get接口获取文件,返回二进制流
#!/bin/env python3.6
# -*- coding: utf-8 -*- #
from flask import Flask
from flask import request
from flask import Response
import json
import base64
import requests
import os
import myutil
logger = myutil.getLog("log-default.log")
app = Flask(__name__)
#app.debug=True
@app.route('/meteorStoreServer/get')
def getMeteor():
logger.info("args:" + str(request.args))
filename = request.args.get("name")
if '/' in filename or '..' in filename:
return "invalid file name"
def send_file():
store_path = os.path.join("store", filename)
with open(store_path, 'rb') as targetfile:
while 1:
data = targetfile.read(1 * 1024 * 1024)
if not data:
break
yield data
response = Response(send_file(), content_type='application/octet-stream')
response.headers["Content-disposition"] = 'attachment; filename=%s' % filename
return response
def delete_old_videos():
for f in os.listdir("store"):
print(f)
@app.route('/meteorStoreServer/post', methods={'POST'})
def postMeteor():
logger.info("values:" + json.dumps(request.values))
logger.info("files: " + str(request.files))
logger.info("args:" + str(request.args))
file_name = request.args.get("name")
for n in request.files:
fobj = request.files[n]
logger.info("save file, " + file_name)
fobj.save(os.path.join("store", file_name))
return json.dumps({"code": 0})
if __name__ == '__main__':
app.run(host='0.0.0.0',port=8085)
版权声明:本文为delacroix_xu原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。