如何用python实现从传感器发送数据和消息到短信和微信等

Python034

如何用python实现从传感器发送数据和消息到短信和微信等,第1张

该回答不涉及传感器选购以及如何使用Python调用,建议根据自己的机子自行淘宝或者参考别的问题(虽然现在没有)

简述:

* 语言:python 2.7.11

* 第三方库:itchat

* 需要设备:采集湿度的设备(机房的电脑?),传感器,一个139邮箱(如果需要短信提示的话)

流程:

* 确定机子以及传感器

* 通过说明书(或者店主...)学会了通过Python获取传感器数据

* 编写判断语句,在命令行输出警告

* 将微信提示或邮箱提示替换警告的方式

微信个人号通知:

import itchat

itchat.auto_login()

itchat.send('Temperature warning')

这个插件的文档在这里:itchat

邮箱通知:

我写了一个简单的Demo: EasierLife/Plugins/MailNotification at master · littlecodersh/EasierLife · GitHub

from MailNotification import MailNotification

with MailNotification() as mail:

mail.send_notification('Temperature warning')

短信通知:

你可以选择使用各种短信平台,但最简单的方式是注册一个139邮箱,然后通过上面邮箱通知的方法发送邮件,你会收到相应的短信提示。

阅信短信验证码平台最近会从新梳理基于不同语言的短信接口调用代码示例,是为了迎合市面上现在流行的各个语言代码实现,也是为了能够更好的服务满足客户的不同层次的需求。

下面的代码是基于python的短信接口调用代码示例模板。

#coding=utf-8

import urllib

import urllib2

import time

import hashlib

def md5(str):

import hashlib

m = hashlib.md5()

m.update(str)

returnm.hexdigest()

url = 'http://IP/端口号'

timenew=time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))

pwd = md5('**********'+timenew)

values ={'name':'syncs','pwd':pwd,'content':'【阅信短信平台】验证码888888,千万不能告诉别人哦。','phone':'手机号','subid':'','mttime':timenew}

data = urllib.urlencode(values)

req = urllib2.Request(url, data)

response = urllib2.urlopen(req)

the_page = response.read()

print the_page