问题
用mqtt节点发送传感器数据到邮箱
解决思路
使用random节点和range节点、email节点以及mqtt节点。radom节点用来产生随机数,一般传感器采集到的数据与我们实际所需要反应出来的数据是不一样的,在这里我们就将采集的数据范围设定为0-1023,最终反应出来的的数据是电压范围0-5V,因此我在节点中添加了一个range节点将传感器的数据映射到电压范围。mqtt的配置就不多叙述了,主要就是注册一个第三方的broker,推荐使用eclipse提供的broker。另外,我们还需要设置email节点来将数据发送到指定的邮箱。
代码
[{"id":"8c9bdc3e.6df9b","type":"mqtt out","z":"5ae2379e.510668","name":"","topic":"edu.enlove.sensor","qos":"2","retain":"","broker":"","x":468.5,"y":293.29998779296875,"wires":[]},{"id":"170cd2d5.c0939d","type":"inject","z":"5ae2379e.510668","name":"sensor","topic":"","payload":"","payloadType":"num","repeat":"","crontab":"","once":false,"x":98.5,"y":387.1499938964844,"wires":[["b9dfcc5d.7651d"]]},{"id":"b9dfcc5d.7651d","type":"random","z":"5ae2379e.510668","name":"","low":"0","high":"1023","inte":"true","x":226.5,"y":310.45001220703125,"wires":[["b03f63e0.b3a11"]]},{"id":"b03f63e0.b3a11","type":"range","z":"5ae2379e.510668","minin":"0","maxin":"1023","minout":"0","maxout":"5","action":"scale","round":false,"name":"map","x":300.5,"y":379.45001220703125,"wires":[["8c9bdc3e.6df9b"]]},{"id":"5a904cb.6fabdb4","type":"mqtt in","z":"5ae2379e.510668","name":"subscriber","topic":"edu.enlove.sensor","qos":"2","broker":"","x":310.5,"y":434.1499938964844,"wires":[["cb82666a.9c7c18"]]},{"id":"cb82666a.9c7c18","type":"e-mail","z":"5ae2379e.510668","server":"smtp.gmail.com","port":"465","secure":true,"name":"","dname":"","x":483.5,"y":370.6000061035156,"wires":[]},{"id":"efb14ef8.5ef14","type":"catch","z":"5ae2379e.510668","name":"","scope":["cb82666a.9c7c18"],"x":520.5,"y":502.1500244140625,"wires":[["cb82666a.9c7c18"]]}]
(mqtt、email节点需要自己进行配置,random节点需要手动添加这个module)
图片
总结
重点在于email节点需要smtp协议,因此需要去使用邮箱的网站获取smtp服务的密码,详情可以百度。