nagata が 2024年10月24日12時55分44秒 に編集
コメント無し
本文の変更
【概要】 ラズパイ4を使用し、センサーが検知した湿度と温度の値を使って不快指数を計算する。不快指数が警告する値であったとき、LINE Notifyでスマートフォンに警告を送るシステム。 【概要図】  【詳細】 bme280を使い、湿度と温度を検知する。検知した値をif文を使って判定する。不快指数を値を使って計算((0.81×気温+0.01×相対湿度(0.99×気温-14.3)+46.3)した後、判定する。判定した結果、警告する値であったとき、LINE Notifyを使い、スマートフォンに警告のメッセージと画像を送る。  [プログラム] ``` import RPi.GPIO as GPIO import smbus2 import bme280 import sys import requests import time import os i2c_bus = smbus2.SMBus(1) address = 0x76 calibration_parms = bme280.load_calibration_params(i2c_bus, address) i=0 x=0 y=0 def send_1(): token = '' api = 'https://notify-api.line.me/api/notify' headers = {'Authorization': f'Bearer {token}'} data = {"message" : message } files = {'imageFile':open('face_angry_man3.png','rb')} result = requests.post(api,headers=headers,data=data,files=files) def send_2(): token = '' api = 'https://notify-api.line.me/api/notify' headers = {'Authorization': f'Bearer {token}'} data = {"message" : message } files = {'imageFile':open('face_angry_man4.png','rb')} result = requests.post(api,headers=headers,data=data,files=files) while True: if i >= 1 : time.sleep(60) i = 0 print("stop") bme_data = bme280.sample(i2c_bus,address,calibration_parms) temperature = bme_data.temperature humidity = bme_data.humidity print("%d" % temperature) print("%d" % humidity) hot = 0.81*temperature+0.01*humidity*(0.99*temperature-14.3)+46.3 if hot >= 70 and hot <= 75: x = temperature y = humidity message = "不快指数は70以上75以下です" time.sleep(2) send_1() i += 1 if hot >= 80 and hot <= 85: x = temperature y = humidity message = "不快指数は80以上85以下です" time.sleep(2) send_2() i += 1 if hot >= 85 : x = temperature y = humidity message = "不快指数は85以上です" time.sleep(2) send_2() i += 1 print( x, y, hot) ``` 【プログラムの実行結果】
 
 
【必要な物品】 • Raspberry Pi 4 • BME280 【参考文献】 • 不快指数の不快の基準とは https://www.sugita-ace.co.jp/column/2015/entry1059.html • 人のための湿度 健康 https://ps-group.co.jp/concept/healthcare-humidity • 【仕事の自動化】PythonでLINEを操作。メッセージや画像を自分へ送信 しよう!【初心者の方もわかりやすいように解説】 https://kino-code.com/pythonline/ • 不快指数の計算式とは?早見表もご紹介 https://kenchiku-setsubi.biz/fukaishisu/ • 意外と知らない快適な湿度の話 https://panasonic.jp/kashitsu/contents/humidity.html • 湿度・気圧センサーBME280 の使い方 https://s-design-tokyo.com/use-bme280/ ・怒る男性のイラスト(5段階) https://www.irasutoya.com/2017/02/5.html