nagata が 2024年09月20日15時48分48秒 に編集
コメント無し
本文の変更
【概要】 ラズパイ4を使用し、センサーが健康に影響が出る湿度や不快指数を検知したとき、lineでスマートフォンに警告を送るシステム。 【概要図】  【詳細】 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
i2c_bus = smbus2.SMBus(1) address = 0x76
calibration_parms = bme280.load_calibration_params(i2c_bus, address) i=0 x=0 y=0 def send(): token = 'iUlH6gX5mQGQWW8UcCPBfZZWJIG74dddQN8oGvrZKB8' api = 'https://notify-api.line.me/api/notify' headers = {'Authorization': f'Bearer {token}'} data = {"message" : message } result = requests.post(api,headers=headers,data=data) 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 humidity >= 60: x = temperature y = humidity message = "カビ、ダニが発生しやすい湿度です" send() time.sleep(2) i += 1 if hot >= 70 and hot <= 75: x = temperature y = humidity message = "不快指数は70以上75以下です" send() time.sleep(2) i += 1 if hot >= 80 and hot <= 85: x = temperature y = humidity message = "不快指数は80以上85以下です" send() time.sleep(2) i += 1 if hot >= 85 : x = temperature y = humidity message = "不快指数は85以上です" send() time.sleep(2) i += 1 print( x, y, hot) ////////////////////////////////////////////////////////////////////////////////////////////
【必要な物品】 【参考文献】