MQTT - 将 PM2.5 数据上传到 LASS 系统

LASS简介

The LASS stands for “Location Aware Sensor System”. It is an open project and was started only for the interest of public welfare. Find detailed introduction here. Practically, LASS is based on MQTT protocol to collect all kinds of uploaded data, and for those who need these data can subscribe top as well. Find more LASS information at their official hackpad.

材料准备

  • AmebaD [AMB21 / AMB22 / AMB23 / BW16] x 1

  • PlanTower PMS3003 or PMS5003 x1

范例说明

这个范例里,我们会使用到Ameba网站里提到的其它应用,包括:

  • MQTT: 用来连上LASS的MQTT-Broker,其中Client为“FT1_0XXXX”, 后面四位数为Ameba的Wifi Mac后4码,outTopic则是“LASS/Test/Pm25Ameba/clientID ”后面的clientID为实际上Ameba的MQTT client ID

  • NTP: 上传的资料里需要时间的注记

  • PM2.5: 上传的资料里带有PM2.5的资讯

我们打开这个范例,它在 “File” -> “Examples” -> “AmebaMQTTClient” -> “lass_basic”

../../../../_images/image119.png

另外,LASS还需要填入GPS资讯。这个范例里没有加上GPS sensor,所以需要手动填入GPS资讯。我们可以利用google map找到GPS资讯,首先找到要放置Ameba的地方,此时google map的网址列就会出现GPS的经纬度,以图中的例子,可以看到GPS的latitude为24.7814033, longitude为120.9933676。

../../../../_images/image217.png

我们将GPS的资讯填入gps_lat与gps_lon里

../../../../_images/image313.png

接着按照UART – PlanTower PMS3003的范例接线方式将sensor接上

AMB21 / AMB22:

../../../../_images/image4-1.png

AMB23:

../../../../_images/image4-2.png

BW16:

../../../../_images/image4-3.png

BW16-TypeC:

../../../../_images/image4-4.png

接着编译程式码并上传到Ameba, 按下Reset按钮之后, Ameba就会每一分钟尝试读取PM2.5的资料, 并上传到LASS MQTT-Broker。打开Serial Monitor,可以看到上传的资讯,包括client id, topic, 目前的pm2.5数值。

../../../../_images/image511.png

我们将MQTT-Broker server位置填“gpssensor.ddns.net”,Subscribe的Topic填Serial Monitor看到的“LASS/Test/PM25/live”, 就可以接收资讯了。

里面的资讯里,时间使用UTC格式,而PM2.5的资料放在s_d0的地方,在图中可以看到s_d0=9代表PM2.5的数值是9,代表整个publish/subscribe的流程都成功运作。

../../../../_images/image66.png