diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..3929cc9 Binary files /dev/null and b/.DS_Store differ diff --git a/sample/get_cpu_temp.sh b/sample/get_cpu_temp.sh index e944603..2e977bb 100755 --- a/sample/get_cpu_temp.sh +++ b/sample/get_cpu_temp.sh @@ -3,6 +3,10 @@ while true do # /usr/bin/powermetrics -b 1 -n 1 -s tasks --show-process-energy --show-process-io | sed -l "s/^/$(date +%Y-%m-%dT%H:%M:%S" "%Z) /" >> ./data/process_energy_io.dat - /usr/bin/powermetrics -b 1 -n 1 -s smc | grep "CPU Thermal level" | sed -l "s/^/$(date +%Y-%m-%dT%H:%M:%S" "%Z) /" >> ./data/cpu_thermal.dat + #/usr/bin/powermetrics -b 1 -n 1 -s smc + power + | grep "CPU Thermal level" + | sed -l "s/^/$(date +%Y-%m-%dT%H:%M:%S" "%Z) /" + >> ./data/cpu_thermal.dat sleep 10 done diff --git a/work/.DS_Store b/work/.DS_Store new file mode 100644 index 0000000..aa34ad0 Binary files /dev/null and b/work/.DS_Store differ diff --git a/work/2023/.DS_Store b/work/2023/.DS_Store new file mode 100644 index 0000000..4e13a4b Binary files /dev/null and b/work/2023/.DS_Store differ diff --git a/work/2023/ne211028/.DS_Store b/work/2023/ne211028/.DS_Store new file mode 100644 index 0000000..8fe750c Binary files /dev/null and b/work/2023/ne211028/.DS_Store differ diff --git "a/work/2023/ne211028/docs/ne211028_IT\343\202\271\343\202\255\343\203\253\345\256\237\347\277\2222\346\234\200\347\265\202\346\210\220\346\236\234\347\211\251\343\203\227\343\203\254\343\202\274\343\203\263\350\263\207\346\226\231.pdf" "b/work/2023/ne211028/docs/ne211028_IT\343\202\271\343\202\255\343\203\253\345\256\237\347\277\2222\346\234\200\347\265\202\346\210\220\346\236\234\347\211\251\343\203\227\343\203\254\343\202\274\343\203\263\350\263\207\346\226\231.pdf" new file mode 100644 index 0000000..5007ac5 Binary files /dev/null and "b/work/2023/ne211028/docs/ne211028_IT\343\202\271\343\202\255\343\203\253\345\256\237\347\277\2222\346\234\200\347\265\202\346\210\220\346\236\234\347\211\251\343\203\227\343\203\254\343\202\274\343\203\263\350\263\207\346\226\231.pdf" differ diff --git a/work/2023/ne211028/src/.DS_Store b/work/2023/ne211028/src/.DS_Store new file mode 100644 index 0000000..988790e Binary files /dev/null and b/work/2023/ne211028/src/.DS_Store differ diff --git a/work/2023/ne211028/src/cpu_temp.dat b/work/2023/ne211028/src/cpu_temp.dat new file mode 100644 index 0000000..d8ecbb6 --- /dev/null +++ b/work/2023/ne211028/src/cpu_temp.dat @@ -0,0 +1,3 @@ +2023-09-06T12:16:31 JST, temp=45.1'C +2023-09-06T12:16:34 JST, temp=44.5'C +2023-09-06T12:16:37 JST, temp=45.1'C diff --git a/work/2023/ne211028/src/get_cpu_temp.sh b/work/2023/ne211028/src/get_cpu_temp.sh new file mode 100755 index 0000000..b74f5c9 --- /dev/null +++ b/work/2023/ne211028/src/get_cpu_temp.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +while true +do +# /usr/bin/powermetrics -b 1 -n 1 -s tasks --show-process-energy --show-process-io | sed -l "s/^/$(date +%Y-%m-%dT%H:%M:%S" "%Z) /" >> ./data/process_energy_io.dat +# /usr/bin/powermetrics -b 1 -n 1 -s smc | grep "CPU Thermal level" | sed -l "s/^/$(date +%Y-%m-%dT%H:%M:%S" "%Z) /" >> ./data/cpu_thermal.dat + + # Raspberry PiのCPU温度の取得と保存 + vcgencmd measure_temp | sed "s/^/$(date +%Y-%m-%dT%H:%M:%S" "%Z), /" >> cpu_temp.dat + + sleep 3 +done diff --git a/work/2023/ne211028/src/get_volume.py b/work/2023/ne211028/src/get_volume.py new file mode 100644 index 0000000..58730e1 --- /dev/null +++ b/work/2023/ne211028/src/get_volume.py @@ -0,0 +1,41 @@ +from pydub import AudioSegment +import math +import time + +def write_message(sound): + if sound >= 60: + print("基準値以上の音声を感知しました") + +def get_audio_volume_transitions(m4a_file, interval=1): + try: + # M4Aファイルを読み込みます + audio = AudioSegment.from_file(m4a_file, format="m4a") + + # サンプリング間隔(秒)を指定します + sample_interval = interval * 1000 # ミリ秒単位に変換 + + for t in range(0, len(audio), sample_interval): + # 指定した時間刻みでの音声データを切り出します + segment = audio[t:t + sample_interval] + + # 音量を取得します + rms = segment.rms + # 音量をデシベル単位に変換します + volume_db = 20 * math.log10(rms) + + # 音量と時間(秒)を出力します + print(f"時間: {t / 1000:.2f}秒, 音量(デシベル単位): {volume_db:.2f} dB") + #音量が基準を超えているか判定 + write_message(volume_db) + + # 次のサンプリングまで待機します + time.sleep(interval) + + except KeyboardInterrupt: + # Ctrl+Cが押された場合、プログラムを終了します + pass + +if __name__ == "__main__": + m4a_file = "sensorlog_20230908.m4a" # 分析したいM4Aファイルへのパスを指定してください + interval = 1 # サンプリング間隔(秒)を設定します + get_audio_volume_transitions(m4a_file, interval) diff --git a/work/2023/ne211028/src/sensorlog_20230906_160346.m4a b/work/2023/ne211028/src/sensorlog_20230906_160346.m4a new file mode 100644 index 0000000..73c4965 Binary files /dev/null and b/work/2023/ne211028/src/sensorlog_20230906_160346.m4a differ diff --git a/work/2023/ne211028/src/sensorlog_20230908.m4a b/work/2023/ne211028/src/sensorlog_20230908.m4a new file mode 100644 index 0000000..52012f7 Binary files /dev/null and b/work/2023/ne211028/src/sensorlog_20230908.m4a differ diff --git a/work/2023/ne211028/src/update_channel.py b/work/2023/ne211028/src/update_channel.py new file mode 100644 index 0000000..0eb2b51 --- /dev/null +++ b/work/2023/ne211028/src/update_channel.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys +import requests #httpリクエストを行うためのモジュール +import re #正規表現を使うためのモジュールをインポート +import time + +api_key = 'V4S9V18KFNIR8QDI' # 作成したチャンネルのAPIキー +channle_id = '2261964' # 作成したチャンネルのID +data_file = "cpu_temp.dat" + +_ts_base_url = "https://api.thingspeak.com" +ts_update_url = _ts_base_url + "/update" +# GET https://api.thingspeak.com/update?api_key=MSUJ80Z21B6XIS7G&field1=0 + +# HTTPでのデータ登録のための設定 +headers = {'X-THINGSPEAKAPIKEY': api_key} + + +#------ +# powermetricsで取得したCPU die tempartureの値を取得して、配列を返す +# 引数:データが入ったファイルのパス +# return : cpu_temp リスト(配列) +# 2021-09-07T23:59:36 JST CPU die temperature: 69.77 C +#------ +def getCpuTempFromFile(filename): + + _cpu_temps = [] + + # ファイルの存在を確認 + is_file = os.path.exists(filename) + if not is_file: + print("正しいファイル名を指定してください。") + sys.exit(1) + + # ファイルを開いてデータを取得 + with open(filename) as f: + _lines = f.readlines() + for _line in _lines: # 配列を1行ずつ取り出す + _data = _line.split() # ファイルの1行を空白で区切って配列にする + print(_data) # 1行の中身を確認 + # ここで、1行のデータのどの部分をどう使うか考えて処理する + res = re.match(r'temp=([0-9.]*)\'C', _data[2]) #正規表現を使って温度を取得 + if res: + print(res.group(1)) #マッチしたパターンのうち、()の部分を取り出し + _cpu_temps.append(res.group(1)) # 取得したパターンを結果用の配列に追記する + + return _cpu_temps + +#------ +# 指定したデータをThingSpeakに登録 +# 引数:req_url, headers, post_data +#------ +def post2ThingSpeak(req_url, headers, post_data): + while True: + response = requests.post(req_url, headers=headers, data=post_data) + if response.text != '0': + break + # time.sleep(1) + + +# メイン処理 +cpu_temps = [] + +print(data_file + " のデータをThingSpeakに登録します。") +# CPU温度の情報をファイルから取得 +cpu_temps = getCpuTempFromFile(data_file) + +print("CPU温度のデータが " + str(len(cpu_temps)) + " 件あります。") +# データの中身をすべて表示 +print(cpu_temps) + +# 最新のデータ(一番最後)をThingSpeakに登録 +# 登録するデータを設定 + +for i in range(len(cpu_temps)): + post_data = {'field1': cpu_temps[i]} + post2ThingSpeak(ts_update_url, headers, post_data) + print("CPU温度:" + str(cpu_temps[i]) + " を登録しました。") +sys.exit(0) diff --git a/work/2023/ne211028/src/volume_to_Thingspeak.py b/work/2023/ne211028/src/volume_to_Thingspeak.py new file mode 100644 index 0000000..22ae90b --- /dev/null +++ b/work/2023/ne211028/src/volume_to_Thingspeak.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys +import requests #httpリクエストを行うためのモジュール +import re #正規表現を使うためのモジュールをインポート +import time + +api_key = '' # 作成したチャンネルのAPIキー +channle_id = '' # 作成したチャンネルのID +data_file = "" + +_ts_base_url = "https://api.thingspeak.com" +ts_update_url = _ts_base_url + "/update" +# GET https://api.thingspeak.com/update?api_key=MSUJ80Z21B6XIS7G&field1=0 + +# HTTPでのデータ登録のための設定 +headers = {'X-THINGSPEAKAPIKEY': api_key} + + +#------ +# powermetricsで取得したCPU die tempartureの値を取得して、配列を返す +# 引数:データが入ったファイルのパス +# return : cpu_temp リスト(配列) +# 2021-09-07T23:59:36 JST CPU die temperature: 69.77 C +#------ +def getCpuTempFromFile(filename): + + _cpu_temps = [] + + # ファイルの存在を確認 + is_file = os.path.exists(filename) + if not is_file: + print("正しいファイル名を指定してください。") + sys.exit(1) + + # ファイルを開いてデータを取得 + with open(filename) as f: + _lines = f.readlines() + for _line in _lines: # 配列を1行ずつ取り出す + _data = _line.split() # ファイルの1行を空白で区切って配列にする + print(_data) # 1行の中身を確認 + # ここで、1行のデータのどの部分をどう使うか考えて処理する + res = re.match(r'temp=([0-9.]*)\'C', _data[2]) #正規表現を使って温度を取得 + if res: + print(res.group(1)) #マッチしたパターンのうち、()の部分を取り出し + _cpu_temps.append(res.group(1)) # 取得したパターンを結果用の配列に追記する + + return _cpu_temps + +#------ +# 指定したデータをThingSpeakに登録 +# 引数:req_url, headers, post_data +#------ +def post2ThingSpeak(req_url, headers, post_data): + while True: + response = requests.post(req_url, headers=headers, data=post_data) + if response.text != '0': + break + # time.sleep(1) + + +# メイン処理 +cpu_temps = [] + +print(data_file + " のデータをThingSpeakに登録します。") +# CPU温度の情報をファイルから取得 +cpu_temps = getCpuTempFromFile(data_file) + +print("CPU温度のデータが " + str(len(cpu_temps)) + " 件あります。") +# データの中身をすべて表示 +print(cpu_temps) + +# 最新のデータ(一番最後)をThingSpeakに登録 +# 登録するデータを設定 + +for i in range(len(cpu_temps)): + post_data = {'field1': cpu_temps[i]} + post2ThingSpeak(ts_update_url, headers, post_data) + print("CPU温度:" + str(cpu_temps[i]) + " を登録しました。") +sys.exit(0)