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的资讯

Open the example. “File” “Examples” “AmebaMQTTClient” “lass_basic”

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

This example requires internet connection, so make sure you fill in SSID and PASS into AP information that you wish to connect. Also, LASS requires GPS information. There is no GPS sensor included in this example, so you must manually provide GPS information. Use Google Map to find the coordinates you plan to place your Ameba. You can see in this example that the latitude is 24.7814033, and the longitude is 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

We can also use MQTTlens to verify if the data is properly uploaded. Enter “gpssensor.ddns.net” as the MQTT-Broker server and “LASS/Test/PM25/live” as the subscribe topic to receive data.

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

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