物联网的蓬勃发展,让热爱研发科技产品和服务的创客们,有了挥洒无尽创意的新天地。而为了因应开发者不同的需求,市售开发版琳琅满目,凡举 Arduino、Rasberry Pi 各有相应的不同功能。而在外部连网的时代,东西有多智能,对象有什么特色,才是 IoT 竞争环境下的致胜关键。

由 QNAP 推出的微型单板服务器 QBoat Sunny ,可视为小型 NAS,特别适合做为携带型的 IoT Gateway!不仅兼容于物联网通讯协议 MQTT ,还可以 Node-red 为基础下去开发应用程序。然而其与 NAS 最大不同在于容量的限制。QBoat Sunny 使用固态硬盘(SSD),虽容量无法与传统硬盘(HDD)比拟,但已足以用于边缘运算。


「不过是压低成本改用 ARM 当 base,把硬盘改成 SSD 做的 NAS」或许是很多人对 QBoat Sunny 的评价,然而 NAS 并不仅只是 PC 灌个 Windows 或 Linux 作为档案与数据库的服务器,软硬件的良好整合性,能适时提供用户需要的服务功能才是其核心价值。以下的范例操作,是为了以无线感测的方式,让使用者能用网页方式查询室内的温湿度。就来看看作为小型 NAS 的 QBoat Sunny 在「打造无线感测应用」,有多轻松省事吧!


 

基础架构

准备工具及操作方式

 


  • Media Tek Linklt  7697 开发版 + DHT11

    1. 连接 MTK 7697 开发版及DHT 11,其脚位连接方式如下:

     
    DHT11 MediaTek LinkIt 7697
    + 5V
    GND
    DO P3

    2. 透过 LWiFi 连结 Wireless AP router,并套用 DHT11 的链接库。编译完成后可用浏览器,如 : http://192.168.1.xxx/temp  查看是否能传出感测数值。
     
    GET參數 功用
    /temp 取得攝氏溫度
    /humi 取得濕度百分比值

    完整程序代码如下:
    <strong>&lt;&lt; MonitorNode.ino &gt;&gt;</strong>
    
    
     #include &lt;LWiFi.h&gt;
    
     #include "DHT.h"
    
    
    
    #define DHTPIN 3 // what digital pin we’re connected to
    
     #define WARNPIN 13
    
    
    
    // Uncomment whatever type you’re using!
    
     #define DHTTYPE DHT11 // DHT 11
    
     //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
    
     //#define DHTTYPE DHT21 // DHT 21 (AM2301)
    
     DHT dht(DHTPIN, DHTTYPE);
    
    
    
    char ssid[] = “LaisanHere”; // your network SSID (name)
    
     char pass[] = “t101419008”; // your network password
    
     int keyIndex = 0; // your network key Index number (needed only for WEP)
    
    
    
    int status = WL_IDLE_STATUS;
    
    
    
    WiFiServer server(80);
    
    
    
    void setup() {
    
     //Initialize serial and wait for port to open:
    
     Serial.begin(9600);
    
     while (!Serial) {
    
     ; // wait for serial port to connect. Needed for native USB port only
    
     }
    
    
    
    // attempt to connect to Wifi network:
    
     while (status != WL_CONNECTED) {
    
     Serial.print(“Attempting to connect to SSID: “);
    
     Serial.println(ssid);
    
     // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    
     status = WiFi.begin(ssid, pass);
    
     }
    
     server.begin();
    
     // you’re connected now, so print out the status:
    
     printWifiStatus();
    
    
    
    // Activate DHT11
    
     dht.begin();
    
    
    
    pinMode(WARNPIN, OUTPUT);
    
     digitalWrite(WARNPIN, LOW);
    
     }
    
     void loop() {
    
     // listen for incoming clients
    
     WiFiClient client = server.available();
    
     if (client) {
    
     Serial.println(“new client”);
    
    
    
    String msg;
    
     String param;
    
    
    
    // an http request ends with a blank line
    
     if (client.connected()) {
    
     while (client.available()) {
    
     char c = client.read();
    
     msg += String(c);
    
     }
    
     }
    
    
    
    Serial.print(msg);
    
    
    
    int posi = msg.indexOf(“Referer: “);
    
     if(posi &gt; 0)
    
     {
    
     String sb = msg.substring(posi);
    
     int p = sb.indexOf(“/”);
    
     param = sb.substring(p+2);
    
     p = param.indexOf(“/”);
    
     param = param.substring(p, p+5);
    
     }
    
     else
    
     {
    
     posi = msg.indexOf(“GET”);
    
     param = msg.substring(posi+4, posi+9);
    
     }
    
    
    
    Serial.println(param);
    
    
    
    // send a standard http response header
    
     client.println(“HTTP/1.1 200 OK”);
    
     client.println(“Content-Type: text/html”);
    
     client.println(“Connection: close”); // the connection will be closed after completion of the response
    
     client.println();
    
    
    
    if(param == “/warn”)
    
     {
    
     digitalWrite(WARNPIN, HIGH);
    
     client.println(“WARNING !!”);
    
     }
    
     if(param == “/cler”)
    
     {
    
     digitalWrite(WARNPIN, LOW);
    
     client.println(“CLEAR”);
    
     }
    
     if(param == “/temp”)
    
     {
    
     float t = dht.readTemperature();
    
     client.println(t);
    
     }
    
     if(param == “/humi”)
    
     {
    
     float h = dht.readHumidity();
    
     client.println(h);
    
     }
    
    
    
    // close the connection:
    
     client.stop();
    
     Serial.println(“client disonnected”);
    
     }
    
    
    
    // give the web browser time to receive the data
    
     delay(100);
    
     }
    
    
    
    void printWifiStatus() {
    
     // print the SSID of the network you’re attached to:
    
     Serial.print(“SSID: “);
    
     Serial.println(WiFi.SSID());
    
    
    
    // print your WiFi shield’s IP address:
    
     IPAddress ip = WiFi.localIP();
    
     Serial.print(“IP Address: “);
    
     Serial.println(ip);
    
    
    
    // print the received signal strength:
    
     long rssi = WiFi.RSSI();
    
     Serial.print(“signal strength (RSSI):”);
    
     Serial.print(rssi);
    
     Serial.println(” dBm”);
    
     }

  • QBoat Sunny:透过 QIoT Suite Lite 内建的Node-red,能在浏览器上设定的GUI。最后 HTTP Request 就能以 0.5、1 分钟的间隔频率,分别读取 DHT11 上的温度和湿


  •  

相關連結:

QNAP 儲存設備 NAS https://www.qnap.com/en/

QNAP 物聯網 https://qiot.qnap.com/blog/en/

 

更多QNAP IoT 應用:

 

arrow
arrow

    tttt 發表在 痞客邦 留言(0) 人氣()