使用Bolt WiFi制作温度监测警报器

这个项目能够通过电子邮件或短信通知温度突然变化或超出定义阈值的设备。
构建项目
第 1 步:将 lm35 连接到螺栓
将 lm35 的 gnd 引脚连接到 bolt 设备的 gnd 引脚。
将 lm35 的模拟输出引脚连接到 bolt 设备的 a0(模拟输入)引脚。
连接 lm35 的 vcc 引脚连接到 bolt 设备的 5v。
第 2 步:配置 bolt iot
要为这个项目创建一个产品,首先登录到bolt cloud
单击“产品”选项卡,然后创建产品
对于这个项目
我选择 input devices 选项和 gpio 来收集数据
单击配置此产品以配置产品
单击螺栓的“a0”引脚并命名变量
现在单击代码选项卡并写下代码
第 3 步:可视化
现在为了制作预测图,我们使用 google chart 在 bolt cloud 中编写 javascript 代码
setchartlibrary(‘google-chart’);
setcharttitle(‘temperature prediction for pharmaceuticals’);
setcharttype(‘predictiongraph’);
setaxisname(‘time’,‘temperature’);
mul(0.0977);
plotchart(‘time_stamp’,‘temp’);
现在查看可视化
每 5 分钟计算一次数据,因此请等待 20-25 分钟。
注意:现在您还可以通过单击 bolt 设备名称来使用您的bolt iot android 应用程序和 ios 应用程序 f或 visualization
第 4 步:使用 z 分数分析和通知进行异常检测
对于这个项目,我使用了 oracle vm virtual box,您也可以使用 digital ocean。现在制作 conf.py ,其中包含twilio(登录并使用 api)和bolt cloud帐户的信息,例如
 ssid = you can find ssid in your twilio dashboard
auth_token = you can find  on your twilio dashboard
from_number = this is the no. generated by twilio. you can find this on your twilio dashboard
to_number = this is your number. make sure you are adding +91 in beginning
api_key = this is your bolt cloud account api key
device_id = this is the id of your bolt device
frame_size = 10
mul_factor = 6
同样对于mailgun电子邮件,制作email_conf.py
mailgun_api_key = your mailgun private api
sandbox_url = your sandbox url
sender_email = test@your sandbox url
recipient_email = your mail id
api_key = bolt api key
device_id = your device id
frame_size = 10
mul_factor = 6
制作 anomaly_detection.py,我们在其中编写 python 代码以使用 z-score 分析进行异常检测并运行它
python3异常检测.py
python代码附在本文下面
如果发生异常或温度超过阈值,则会使用twilio和mailgun发送 sms 和邮件警报。
twilio 的短信和 mailgun 的电子邮件截图
屏幕截图
anomaly_detection.py:
import conf, email_conf, json, time, math, statistics
from boltiot import sms, email, bolt
def compute_bounds(history_data, frame_size, factor):
    if len(history_data) frame_size :
        del history_data[0:len(history_data)-frame_size]
    mn = statistics.mean(history_data)
    variance = 0
    for data in history_data:
        variance += math.pow((data-mn), 2)
    zn = factor * math.sqrt(variance / frame_size)
    high_bound = history_data[frame_size-1]+zn
    low_bound = history_data[frame_size-1]-zn
    return [high_bound,low_bound]
minimum_limit = 7 #can be change
maximum_limit = 40 #can be change
mybolt = bolt(email_conf.api_key, email_conf.device_id)
mailer = email(email_conf.mailgun_api_key, email_conf.sandbox_url, email_conf.sender_email, email_conf.recipient_email)
sms = sms(conf.ssid, conf.auth_token, conf.to_number, conf.from_number)
history_data = []
while true:
    response = mybolt.analogread('a0')
    data = json.loads(response)
    if data['success'] != '1':
        print(there was an error while retriving the data.)
        print(this is the error:+data['value'])
        time.sleep(10)
        continue
    print(the sensor value is+(data['value']))
    sensor_value = 0
    try:
        sensor_value = int(data['value'])
    except exception as e:
        print(there was an error while parsing the response:, e)
        continue
    bound = compute_bounds(history_data, email_conf.frame_size, email_conf.mul_factor)
    if not bound:
        required_data_count = email_conf.frame_size-len(history_data)
        print(not enough data to compute z-score. need, required_data_count, more data points)
        history_data.append(int(data['value']))
        time.sleep(10)
        continue
    try:
        if sensor_value > maximum_limit or sensor_value bound[0]:
            print(the temperature increased suddenly.sending sms.)
            response = sms.send_sms(someone opened the chamber)
            print(this is the response, response)
        elif sensor_value < bound[1]:
            print(the temperature decreased suddenly. sending an email.)
            response = mailer.send_email(someone opened the chamber)
            print(this is the response, response)
        history_data.append(sensor_value)
    except exception as e:
        print(error, e)
    time.sleep(10)

如何将区块链应用于零售行业
顶尖电子博览会预告,特殊时期的特殊规划
BASIC语言概述及特点
魅蓝Note6发布会在即:处理器成迷,是联发科还是高通?魅蓝首款双摄手机买999?
我国电子产业现状如何,该如何持续发展?
使用Bolt WiFi制作温度监测警报器
物理学
基于一种DeFi的顶级区块链平台介绍
创想三维以客户至上为宗旨 打造全球3D打印机行业一流服务品牌
利用GPU来找寻圣诞老人的踪迹
变频自适应超声波电源发生器设计
5G技术挑战与未来走向大盘点
华为降噪耳机2代怎么样 手机直充是最值得称赞的地方
方管的材质一般是什么样的,关于测量方管边长仪器的推荐
2018年机器学习技术会通过这些方面彻底改变制造业
基于I2C总线与芯片实现高清视频监控中的云台电机驱动系统设计
从谷歌地图与Cyberverse来看AI视频技术
丹佛斯变频器正反转接线图
技术干货|基于数模混合型SoC实现的两线制高精度无源表头方案
空气微站是什么,它的作用是什么