<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nuttapong Klaokliang on Medium]]></title>
        <description><![CDATA[Stories by Nuttapong Klaokliang on Medium]]></description>
        <link>https://medium.com/@Knuttapong?source=rss-4f2a1c262c5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MPcNCbPaB8WjN8yijuf-5A.jpeg</url>
            <title>Stories by Nuttapong Klaokliang on Medium</title>
            <link>https://medium.com/@Knuttapong?source=rss-4f2a1c262c5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:33:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Knuttapong/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[NETPIE] การแสดงผลข้อมูลความชื้นและอุณหภูมิจากเซนเซอร์ DHT ด้วย Grafana ร่วมกับ Node-PIE และ…]]></title>
            <link>https://medium.com/@Knuttapong/https-medium-com-knuttapong-netpie-grafana-nodered-influxdb-ba7356f7b08f?source=rss-4f2a1c262c5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba7356f7b08f</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[netpie]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Nuttapong Klaokliang]]></dc:creator>
            <pubDate>Fri, 04 Aug 2017 04:07:59 GMT</pubDate>
            <atom:updated>2017-08-04T04:11:06.555Z</atom:updated>
            <content:encoded><![CDATA[<h3>[NETPIE] การแสดงผลข้อมูลความชื้นและอุณหภูมิจากเซนเซอร์ DHT ด้วย Grafana ร่วมกับ Node-PIE และ InfluxDB</h3><p>จากบทความที่แล้ว <a href="https://medium.com/@Knuttapong/netpie-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%81%E0%B8%AA%E0%B8%94%E0%B8%87%E0%B8%9C%E0%B8%A5%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%B9%E0%B8%A5%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%8A%E0%B8%B7%E0%B9%89%E0%B8%99%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%AD%E0%B8%B8%E0%B8%93%E0%B8%AB%E0%B8%A0%E0%B8%B9%E0%B8%A1%E0%B8%B4%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B9%80%E0%B8%8B%E0%B8%99%E0%B9%80%E0%B8%8B%E0%B8%AD%E0%B8%A3%E0%B9%8C-dht-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-grafana-ea21ad11277f">[NETPIE]การแสดงผลข้อมูลความชื้นและอุณหภูมิจากเซนเซอร์ DHT ด้วย Grafana</a> เราใช้ Node.js server ที่มี NETPIE module เป็นตัวกลางในการรับข้อมูลจากเซนเซอร์ DHT ผ่าน NETPIE แล้วส่งไปแสดงผลที่ Grafana</p><p>แต่ในบทความนี้เราจะแทนที่ Node.js server ด้วย Node-PIE เป็นฟีเจอร์ใหม่ล่าสุดของ NETPIE ที่มีเบื้องหลังเป็น <a href="https://nodered.org/">Node-RED</a> ซึ่งเป็น Flow-based Programming Tool (อธิบายอย่างง่ายๆคือการลากวางตาม logic และทำงานได้โดยไม่ต้องเขียนโค้ด) มาใช้รับข้อมูล จากนั้นใช้ InfluxDB เก็บข้อมูล โดย Grafana จะร้องขอข้อมูลจาก InfluxDB เพื่อไปแสดงผล</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*2M6Umc19V_RPROXsY-NAJw.png" /><figcaption>แผนผังแสดงการทำงานของระบบ (กล่องสีเข้มๆนั้นแทน plugin ครับ)</figcaption></figure><h3>สิ่งที่ต้องเตรียม :</h3><p>โปรเจคเดิมจากบทความที่แล้ว รวมถึง ESP8266 NodeMCU ที่ต่อกับเซนเซอร์ DHT11</p><h3>Install InfluxDB</h3><p>1.เข้าไปที่ <a href="https://portal.influxdata.com/downloads">https://portal.influxdata.com/downloads</a> แล้วดาวน์โหลด InfluxDB ที่ตรงกับระบบปฏิบัติการที่ใช้ ซึ่งในบทความนี้จะใช้ Windows ครับ จากนั้น unzip ไฟล์ไปไว้ที่โปรเจคเดิมของเรา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ph91vqvYX9sWszzSTg1nqA.png" /><figcaption>เลือกดาวน์โหลด InfluxDB เวอร์ชันล่าสุด</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*cV88PGIQikMn4siSzrTkuQ.png" /><figcaption>สำหรับ Windows สามารถนำลิงก์ไปวางบน browser เพื่อดาวน์โหลดได้</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*GIs5M8b2Cizo17uCTRcb4Q.png" /><figcaption>unzip ไว้ที่โฟลเดอร์โปรเจคของเรา</figcaption></figure><p>2.สร้างไฟล์ influx.bat แล้วใส่คำสั่งด้านล่างนี้ลงไป เป็นการตั้งค่าให้กับตัวแปร HOME และเรียกใช้ command line ของ Influx</p><pre>@ECHO OFF<br>SETLOCAL<br>SET HOME=%~dp0<br>&quot;%~dp0\influx.exe&quot; %*<br>ENDLOCAL</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*uk6cGC53ty0UVqX57xk6eQ.png" /><figcaption>สามารถสร้างเป็นไฟล์ .txt ก่อน โดยคลิกขวา New &gt; Text Document จากนั้นใส่คำสั่งลงไป แล้วเปลี่ยนนามสกุลไฟล์เป็น .bat</figcaption></figure><p>3.เปิดไฟล์ influxd.exe เพื่อให้ InfluxDB เริ่มทำงาน (ต้องเปิดไว้ตลอด)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*GJaonzQuPQSp65jNtmGb_Q.png" /><figcaption>InfluxDB กำลังทำงานที่ port 8086</figcaption></figure><p>4.เปิดไฟล์ influx.bat ที่ได้จากข้อ 2. จากนั้นสร้างฐานข้อมูลชื่อ netpieDHT <br>ด้วยคำสั่ง</p><pre>CREATE DATABASE netpieDHT</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*AlcPoBK5n0XXxmXMLBDCsQ.png" /><figcaption>สามารคเช็คได้ว่ามีฐานข้อมูลที่เราสร้างไปหรือไม่ด้วยคำสั่ง SHOW DATABASE</figcaption></figure><h3>Install Node-PIE</h3><p>จำเป็นจะต้องติดตั้ง <a href="https://nodejs.org/">Node.js</a> ก่อนนะครับ จากนั้นติดตั้ง Node-PIE ได้โดยใช้คำสั่ง</p><pre>npm install node-pie -g</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*oipY6vdnOpvEZX0vU_M0ww.png" /></figure><h3>Install InfluxDB Plugin for Node-PIE</h3><p>ใช้คำสั่งด้านล่างเพื่อติดตั้ง Plugin ของ InfluxDB สำหรับใช้ใน Node-PIE</p><pre>npm install -g node-red-contrib-influxdb</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*UptQAqUJ_fQumhMlgzfdEQ.png" /></figure><h3>Let’s Start</h3><p>1.เริ่มการทำงานของ Grafana และเข้าไปที่ data source</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqO9OjWa6prG7nK94d-5cA.png" /></figure><p>2.เพิ่ม data source ประเภท influx กรอก url เป็น http://localhost:8086 <br>และ Database เป็น netpieDHT ตามที่เราได้สร้างไว้ จากนั้นกด Save &amp; Test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*DYrElHU2dh-tUp5RJqJlFQ.png" /></figure><p>3.พิมพ์ node-pie ใน cmd เพื่อเริ่มการทำงานของ Node-PIE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*eQSa9ll3xjFF1kX9OEXu_g.png" /><figcaption>Node-PIE เริ่มการทำงานที่ port 8888</figcaption></figure><p>4.ไปที่ <a href="http://localhost:8888/">http://localhost:8888</a> เพื่อสร้าง flow การทำงานของ Node-PIE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aUL84VctFg61XF0p8ZCghA.png" /><figcaption>หน้าตาของ Node-PIE ที่ด้านขวาจะเป็น node สำหรับเลือกมาสร้าง flow</figcaption></figure><p>5.โดย flow ที่เราจะสร้างจะมีการทำงานคือ subscribe ข้อมูลจาก topic /dht จากนั้นแยกข้อมูลออกเป็นอุณหภูมิและความชื้นเก็บลง InfluxDB</p><p>ขั้นแรกให้ลาก node ชื่อ microgear มาวางไว้และดับเบิลคลิกเพื่อตั้งค่าดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GMzmqyz6HZSMhO75KT92Qw.png" /></figure><p>จากนั้นค้นหา function และนำมาวางลงไปในพื้นที่ของ flow โดย function node จะทำหน้าที่เป็นตัวแยกข้อมูลอุณหภูมิและความชื้นออกจากกัน เนื่องจากในโค้ด <a href="https://github.com/netpiemaker/MiniWorkshop/blob/master/code/part2-netpie/ESP8266/microgear_switch_dht/microgear_switch_dht.ino">microgear_switch_dht</a> ที่เราใช้กับ ESP8266 นั้นจะ publish ข้อมูลออกมาในลักษณะ ความชื้น,อุณหภูมิ เช่น 44,25 เราจึงต้องใช้ , เป็นตัวแบ่งข้อมูล</p><pre>dht = msg.payload;        //รับข้อมูลใส่ตัวแปร dht<br>dht = dht.split(&#39;,&#39;);     //แบ่งข้อมูลด้วย ,<br>humid = parseInt(dht[0]); //ข้อมูลที่แบ่งในตำแหน่งที่ 0 คือความชื้น<br>temp = parseInt(dht[1]);  //ข้อมูลที่แบ่งในตำแหน่งที่ 1 คืออุณหภูมิ<br>msg.payload = [{          //นำข้อมูลที่ได้บรรจุลง payload <br>  temperature: temp,<br>  humidity: humid<br>}]<br>return msg;               //ส่งออกข้อมูลอุณหภูมิและความชื้น</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7IwGf57wnsvXXPE6QdF0Q.png" /><figcaption>ค้นหาที่ช่องมุมบนซ้าย</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ImAEOtrZScddmaL9hpUyw.png" /><figcaption>ช่อง Name สามารถตั้งชื่อตามต้องการได้</figcaption></figure><p>ค้นหา influx output จากนั้นนำมาวางแล้วทำการตั้งค่าดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dB3NtdBBvCAgN2IhZsnyBA.png" /><figcaption>กดเพื่อเพิ่ม server</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_0unbiDsuTfwaVKpRDeo6g.png" /><figcaption>เพิ่ม Database ตามชื่อที่เราสร้างไว้ จากนั้นกด Add</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*1XXEhNAqXGnqXCwW-7TX9g.png" /><figcaption>ตั้งชื่อให้ Measurement เพื่อที่ Grafana จะสามารถดึงไปได้ถูก แล้วกด Done</figcaption></figure><p>เมื่อเชื่อมทุก node เข้าด้วยกันดังภาพจะได้ลำดับการทำงานว่า เมื่อมีข้อมูลจาก topic /dht เข้ามา จะถูกแยกเป็นอุณหภูมิและความชื้น จากนั้นจะส่งไปเก็บที่ influxDB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*Jxg6racE8ZYEoH4eto99wA.png" /><figcaption>ภาพของ flow ที่เชื่อมต่อเรียบร้อยแล้ว</figcaption></figure><blockquote>การสร้าง flow นอกจากเราทำงานสร้างเองแล้ว ยังสามารถ import มาจาก JSON ได้ครับ ด้านล่างคือ JSON ของ flow ที่เราได้สร้างไปข้างต้น (ใส่ key ของ microgear เพิ่มหลังจาก import ด้วยนะครับ)</blockquote><pre>[{&quot;id&quot;:&quot;20a541a8.ef6c26&quot;,&quot;type&quot;:&quot;microgear&quot;,&quot;z&quot;:&quot;f952067c.e0241&quot;,&quot;name&quot;:&quot;&quot;,&quot;appid&quot;:&quot;&quot;,&quot;key&quot;:&quot;&quot;,&quot;secret&quot;:&quot;&quot;,&quot;alias&quot;:&quot;&quot;,&quot;topics&quot;:&quot;/dht&quot;,&quot;activate&quot;:true,&quot;retain&quot;:&quot;&quot;,&quot;retainType&quot;:&quot;&quot;,&quot;x&quot;:280,&quot;y&quot;:180,&quot;wires&quot;:[[&quot;4b465afb.21e814&quot;]]},{&quot;id&quot;:&quot;4b465afb.21e814&quot;,&quot;type&quot;:&quot;function&quot;,&quot;z&quot;:&quot;f952067c.e0241&quot;,&quot;name&quot;:&quot;split dht data&quot;,&quot;func&quot;:&quot;dht = msg.payload;\ndht = dht.split(&#39;,&#39;);\n\nhumid = parseInt(dht[0]);\ntemp = parseInt(dht[1]);\n\n msg.payload = [{\n        temperature: temp,\n        humidity: humid\n }]\n \nreturn msg;&quot;,&quot;outputs&quot;:1,&quot;noerr&quot;:0,&quot;x&quot;:410,&quot;y&quot;:300,&quot;wires&quot;:[[&quot;c08a1d2b.f3f12&quot;]]},{&quot;id&quot;:&quot;c08a1d2b.f3f12&quot;,&quot;type&quot;:&quot;influxdb out&quot;,&quot;z&quot;:&quot;f952067c.e0241&quot;,&quot;influxdb&quot;:&quot;f288efc6.c659d8&quot;,&quot;name&quot;:&quot;&quot;,&quot;measurement&quot;:&quot;dht&quot;,&quot;precision&quot;:&quot;&quot;,&quot;retentionPolicy&quot;:&quot;&quot;,&quot;x&quot;:610,&quot;y&quot;:420,&quot;wires&quot;:[]},{&quot;id&quot;:&quot;f288efc6.c659d8&quot;,&quot;type&quot;:&quot;influxdb&quot;,&quot;z&quot;:&quot;&quot;,&quot;hostname&quot;:&quot;127.0.0.1&quot;,&quot;port&quot;:&quot;8086&quot;,&quot;protocol&quot;:&quot;http&quot;,&quot;database&quot;:&quot;netpieDHT&quot;,&quot;name&quot;:&quot;&quot;,&quot;usetls&quot;:false,&quot;tls&quot;:&quot;&quot;}]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJABzzLYjCVfF589tcnsbA.png" /><figcaption>ไปที่เมนูมุมบนขวา Import &gt; Clipboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvEQ8DFh6rhB5DVlpIUASQ.png" /><figcaption>วาง JSON ลงไปและกด Import เพียงเท่านี้ก็จะได้ flow หน้าตาเหมือนกับขั้นตอนก่อนหน้านี้</figcaption></figure><p>6.จากนั้นกด Deploy ที่มุมขวาบนเพื่อให้ flow ทำงาน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*5NFjBeIwLEMzfIAiUkOhPA.png" /></figure><p>7.หาก ESP8266 ของเรากำลังทำงานอยู่จะสามารถเห็นข้อมูลที่ถูกส่งเข้า InfluxDB ได้จาก console ที่เปิดจากไฟล์ influxd.exe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GsfLkMLhrt1CntcdBTEjJw.jpeg" /></figure><p>8.กลับมาที่ Grafana จากขั้นตอนที่ 2. เราสมารถรับ data source จาก influxDB ได้แล้ว และ ESP8266 ของเราก็สามารถส่งข้อมูลไปลง influxDB ได้แล้วเช่นกัน <br>เราสามารถสร้างกราฟที่มี data source เป็น influxDB ซึ่งแสดงผลทั้งอุณหภูมิและความชื้นได้แล้วครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4xGMiZaSPf8og-lO3QP-Q.png" /><figcaption>-ขั้นตอนการสร้างกราฟสามารถศึกษาได้จากบทความก่อนหน้านี้นะครับ</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba7356f7b08f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[NETPIE] การแสดงผลข้อมูลความชื้นและอุณหภูมิจากเซนเซอร์ DHT ด้วย Grafana]]></title>
            <link>https://medium.com/@Knuttapong/netpie-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%81%E0%B8%AA%E0%B8%94%E0%B8%87%E0%B8%9C%E0%B8%A5%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%B9%E0%B8%A5%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%8A%E0%B8%B7%E0%B9%89%E0%B8%99%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%AD%E0%B8%B8%E0%B8%93%E0%B8%AB%E0%B8%A0%E0%B8%B9%E0%B8%A1%E0%B8%B4%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B9%80%E0%B8%8B%E0%B8%99%E0%B9%80%E0%B8%8B%E0%B8%AD%E0%B8%A3%E0%B9%8C-dht-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-grafana-ea21ad11277f?source=rss-4f2a1c262c5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea21ad11277f</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[netpie]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Nuttapong Klaokliang]]></dc:creator>
            <pubDate>Thu, 20 Jul 2017 10:00:32 GMT</pubDate>
            <atom:updated>2017-07-21T04:55:19.470Z</atom:updated>
            <content:encoded><![CDATA[<p>จากบทความที่แล้ว <a href="https://medium.com/@Knuttapong/simple-data-visualizing-with-grafana-d617190913b2">การแสดงผลข้อมูล JSON อย่างง่ายด้วย Grafana</a> เราจะทำการเพิ่มเติมเล็กน้อยเพื่อให้รับข้อมูลจากเซนเซอร์ DHT ผ่าน NETPIE ครับ</p><h3>สิ่งที่ต้องเตรียม :</h3><ol><li>โปรเจคเดิมจากบทความที่แล้ว</li><li>สร้าง <a href="https://netpie.io/app">Application บน NETPIE</a> แล้วเตรียม key และ secret ไว้ โดย Device สำหรับบอร์ด Arduino ESP8266 NodeMCU, Session สำหรับ data source</li><li>เซนเซอร์ DHT11 ต่อกับบอร์ด Arduino ESP8266 NodeMCU ที่ upload โค้ด<a href="https://github.com/netpiemaker/MiniWorkshop/blob/master/code/part2-netpie/ESP8266/microgear_switch_dht/microgear_switch_dht.ino">การส่งข้อมูลอุณหภูมิและความชื้น</a> ไว้แล้ว (อย่าลืมใส่ Application id, Device key, secret จากข้อ 2. และตั้งชื่อ device นะครับ)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GyxrUnjAx9zz4FzUlwgzqQ.png" /><figcaption>DHT11 ที่ต่อกับบอร์ด Arduino ESP8266 NodeMCU ส่วนด้านหลังคือตัวอย่างกราฟที่เสร็จแล้วครับ</figcaption></figure><h3>Let’s Start</h3><ol><li>copy โฟลเดอร์ fake-simple-json-datasource เพิ่มขึ้นมาในโปรเจคเดิมของเรา</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*gftZebVrxlZheZviu57L0w.png" /><figcaption>ผมตั้งชื่อโฟลเดอร์ใหม่ว่า netpie-json-datasource</figcaption></figure><p>2. เข้าไปที่โฟลเดอร์ใหม่ เปิด cmd แล้วติดตั้ง microgear เพื่อให้ติดต่อกับ NETPIE ได้ ด้วยคำสั่ง</p><pre>npm install microgear</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*WigPU_9SRRom4hZuN-ACLw.png" /></figure><p>3. เพิ่ม module ในการเชื่อมต่อกับ NETPIE โดยดาวน์โหลดจาก <a href="https://github.com/Knuttapong/netpie-module-for-dht-server">netpie-module-for-dht-server</a> และอย่าลืมใส่ Application id, Session key และ secret นะครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*55pIM3oOVbpFoxlYifwCAw.png" /><figcaption>นำไฟล์ netpie.js ที่ดาวน์โหลดมาวางไว้ที่ netpie-json-datasource</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*6kNsbeOnOhXaQ8C-n1hcuA.png" /><figcaption>ใน netpie.js อย่าลืมนำ Application id, Session key และ secret มาใส่นะครับ</figcaption></figure><p>4. เปิดไฟล์ index.js แก้ไขให้ตัวแปร timeserie รับข้อมูลจาก NETPIE module ของเราแทนไฟล์ series.json</p><pre>var netpie = require(&#39;./netpie&#39;);  //เรียกใช้ netpie module<br>var timeserie = netpie.timeserie;  //รับข้อมูลจาก netpie module</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*HPhkbfZHLUw5GIgcs8torg.png" /></figure><p>5. เปลี่ยน port ให้ไม่ซ้ำกับ data source ตัวเดิม (ในกรณีที่เปิด 2 data source พร้อมกันจะได้ไม่ชนกันครับ) ตัวอย่างเช่น เปลี่ยนเป็น port 4444 ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*gE_rlClJMYAy3ZpvahXijQ.png" /></figure><p>6. สั่งให้ grafana server และ netpie-json-datasource ทำงาน ด้วยวิธีเดียวกับ<br>บทความที่แล้วครับ</p><p>7. เพิ่ม data source ใหม่ให้ url เป็นไปตามที่เราแก้ไข port ในข้อที่ 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*GUdeja57uXC56MV-HwbSYw.png" /><figcaption>ไปที่ data source</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*Vl1Af8jErE4sAnf72RWA6A.png" /><figcaption>กดเพิ่ม data source ที่มุมบนขวา</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*mleASGKW3150cckxFwFTWA.png" /><figcaption>url ตามที่ netpie-json-datasource ทำงานอยู่</figcaption></figure><p>8. เพิ่มหน้า dashboard ใหม่ และแสดงกราฟของข้อมูลอุณหภูมิและความชื้นที่ส่งมาจาก netpie-json-datasource โดยขั้นตอนจะเหมือนกับบทความที่แล้วครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*kpDAzJqv9oapZ39qkX6vow.png" /><figcaption>กดสร้าง dashboard ใหม่</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kJV_FYbjXKqJoW9it0V9yw.png" /><figcaption>หน้าตาของกราฟที่สามารถรับข้อมูลอุณหภมิและความชื้นได้สำเร็จ</figcaption></figure><p>9. เราสามารถตั้งค่าให้ Grafana แสดงช่วงของข้อมูลที่เราต้องการ และ refresh อัตโนมัติทุกกี่วินาทีได้ โดยคลิกที่มุมบนขวาของหน้าจอ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*86rxGr4upsShaJvzpTyVCA.png" /><figcaption>คลิกที่นี่เพื่อตั้งค่า</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBxut6DTRHkZcRilVofIrQ.png" /><figcaption>ตัวอย่างการตั้งค่า refresh ทุก 5 วินาที และแสดงข้อมูลถึง 5 นาทีก่อนหน้านี้</figcaption></figure><h3>สรุปส่งท้าย</h3><p>จะเห็นว่าเราสามารถแสดงผลข้อมูลอุณหภูมิและความชื้นโดยใช้ NETPIE เข้ามาช่วยได้แล้วนะครับ แต่ยังมีข้อจำกัดที่ NETPIE module ที่ผมเขียนขึ้นเองนั้นเก็บข้อมูลลงในตัวแปร timeserie ทั้งหมดโดยไม่มีการจำกัดขนาดหรือบันทึกลงฐานข้อมูล ซึ่งมีข้อเสียคือการกินพื้นใน memory มากเกินจำเป็น และหาก server ของเราเกิดดับขึ้นมาข้อมูลเหล่านี้ก็จะหายไปเลยเพราะไม่มีการบันทึกไว้ โดยในบทความหน้าจะเป็นการเชื่อมต่อกับฐานข้อมูลและอาจจะมีการใช้ <a href="https://nodered.org/">Node-RED</a> เป็น server แทนครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea21ad11277f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[การแสดงผลข้อมูล JSON อย่างง่ายด้วย Grafana]]></title>
            <link>https://medium.com/@Knuttapong/simple-data-visualizing-with-grafana-d617190913b2?source=rss-4f2a1c262c5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d617190913b2</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[netpie]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Nuttapong Klaokliang]]></dc:creator>
            <pubDate>Tue, 18 Jul 2017 07:29:51 GMT</pubDate>
            <atom:updated>2017-07-19T06:26:10.283Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับ ในบทความนี้ผมจะแนะนำการใช้ <a href="http://grafana.com/">Grafana</a> ซึ่งเป็นเครื่องมือแสดงผลข้อมูล time series ในรูปแบบต่างๆ โดยจะใช้ตัวอย่างง่ายๆเป็นข้อมูล JSON จาก Node.js server เพื่อให้เห็นภาพอย่างกว้างๆและสามารถนำไปต่อยอดโดยใช้ข้อมูลจากแหล่งอื่นๆ เช่น <a href="http://netpie.io/">NETPIE</a> ได้ครับ</p><p>สิ่งที่ต้องเตรียมติดตั้งก่อนเริ่ม :<br>1. <a href="https://nodejs.org/">Node.js</a><br>2. <a href="https://git-scm.com/download/win">git</a><br>และในบทความนี้จะทำบนระบบปฏิบัติการ Windows นะครับ</p><h3><strong>Let’s Start</strong></h3><ol><li>เข้าไปที่ <a href="https://grafana.com/">grafana.com</a> และกด Get Grafana เพื่อเข้าสู่หน้าดาวน์โหลด</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h0QhfQCThW9T6M-IgH39AA.png" /></figure><p>2. เลือก Windows และกดที่ url ในกรอบสีแดงเพื่อดาวน์โหลด</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P6ChIbYaaGDeu3uTVbPp8w.png" /></figure><p>3. สร้างโฟลเดอร์เตรียมไว้ แล้ว unzip ไฟล์ที่โหลดมาจาก Grafana ไว้ที่นั่น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*ksqfYKeyNYdVeCqzYVO2yQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*p5yLL7dJmGpamIzLQnY_Ig.png" /></figure><p>4. ในโฟลเดอร์ Grafana เข้าไปที่ bin และรันไฟล์ grafana-server.exe (ต้องเปิดไว้ตลอด)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*JUqNgO_lmV7aNxyQkrCVxQ.png" /></figure><p>5. ไปที่ <a href="http://localhost:3000/">localhost:3000</a> เพื่อดูว่า Grafana เริ่มทำงานแล้ว ซึ่งเราสามารถเปลี่ยนเป็น port อื่นที่ไม่ใช่ 3000 ได้ที่ โฟลเดอร์ conf ไฟล์ defaults.ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A6n5hZnh6FMkRPZjBqn5WA.png" /></figure><p>6. login ด้วยสิทธิ์ของ admin ด้วย user และ password คือ admin (สามารถแก้ไข user และ password ของ admin ได้ที่ conf/defaults.ini เช่นกัน)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJ7dzlT3IxJ3nZIl3tcIsg.png" /><figcaption>หน้าตาตอนเริ่มต้นของ Grafana</figcaption></figure><p>7. จากหน้าแรกของ Grafana ตามขั้นตอนเราจะต้องมีแหล่งของข้อมูล หรือ data source ก่อนนะครับ คลิกเข้าไปที่ปุ่มสีเขียว Add data source และในตัวเลือกเราจะไม่เห็น data source ที่เป็น JSON ตามเป้าหมายที่วางไว้ต้นบทความ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*o7LJfP5zAab-vkH-sLhqhQ.png" /><figcaption>ไม่มี JSON</figcaption></figure><p>8. เราจะต้องเพิ่ม data source ใหม่เข้าไปใน Grafana เริ่มแรกให้กลับไปที่หน้า Home โดยคลิกที่ Dashboard บนเมนูมุมบนซ้าย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/1*JYMn5w_DFl13ImQWAqpaOQ.png" /></figure><p>9. ในส่วนของ Installed Datasources คลิกที่ None installed. Browse Grafana.net เพื่อค้นหา data source เพิ่มเติม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xlKEDOUUpNr6z5G_06A93Q.png" /></figure><p>10. เลือก Data Source และหา SimpleJson</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-xZe4NhD_Fg8jswcCUw5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7futJGcd2aMa59MFL9Zb0Q.png" /></figure><p>11. กดที่ปุ่มสีส้ม Install plugin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-xdkAsjdjD6U6XMD4C0caQ.png" /></figure><p>12. จะเห็นว่าในกรอบสีแดงมีคำสั่งในการติดตั้งอยู่ ให้ copy ไว้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZ5JcKb-eUNK3-JviOhJpA.png" /></figure><p>13. ในโฟลเดอร์ Grafana ไปที่ bin และเปิด cmd ขึ้นมา (สามารถเปิดได้ด้วย shift+คลิกขวา &gt; Open command window here)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*jGB8JRb7pQMPSF8ULjiCHQ.png" /></figure><p>14. paste คำสั่งจากข้อ 12. ลงไปใน cmd แล้ว enter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*wbdQ0QkyLOikQ7XAJ9Txqw.png" /></figure><p>15. เมื่อติดตั้งเสร็จแล้ว จะต้อง restart grafana-server ในข้อ 4. โดยการปิดหน้าต่างนั้นแล้วรันใหม่</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*SRE409XZuUipPtrBMDRcUw.png" /></figure><p>16. กลับไปที่หน้า Home (<a href="http://localhost:3000/">localhost:3000</a>) จะเห็นว่ามี SimpleJson ขึ้นมาแล้ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-3GHNnQlQCrOMbGiE7UIg.png" /></figure><p>17. จากขั้นตอนที่ผ่านๆมา ทำให้เราสามารถรับข้อมูลที่เป็น JSON ได้แล้ว แต่เรายังไม่มีแหล่งของข้อมูลเลย ในบทความนี้จะใช้ fake-simple-json-datasource จาก github (<a href="https://github.com/bergquist/fake-simple-json-datasource">https://github.com/bergquist/fake-simple-json-datasource</a>) โดยใช้คำสั่งด้านล่างนี้ในโฟลเดอร์เริ่มต้นของเรา หรือจะเข้าไปดาวน์โหลดแบบ zip ก็ได้เช่นกันครับ</p><pre>git clone https://github.com/bergquist/fake-simple-json-datasource</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*QRr7RuLNjR0mcfLUT3_XkA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*xhQjNOChuyPZzrhvbRk1tA.png" /></figure><p>18. เข้าไปโฟลเดอร์ fake-simple-json-datasource เปิด cmd ขึ้นมาเพิมพ์คำสั่งด้านล่าง เพื่อติดตั้ง Node.js dependencies</p><pre>npm install</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*eyvH2xl7Z10FwGPk4T7aCA.png" /></figure><p>19. สั่งให้ fake-simple-json-datasource ทำงานด้วยคำสั่งด้านล่าง (ทำงานอยู่ที่ port 3333 สามารถเปลี่ยนได้ในไฟล์ index.js บรรทัด 119: app.listen(3333); โดยเปลี่ยนเลข 3333 เป็น port ที่ต้องการ)</p><pre>node index.js</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*NYC33E9sKPK8HEtDugBr3A.png" /></figure><p>20. กลับมาที่ Grafana เข้าไปที่ปุ่มสีเขียว Add data source เช่นเดียวกับข้อ 7. จะเห็นว่ามี SimpleJson ให้เลือกใน Type</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*QKqmL6CfaXiwc6JC5HJyFg.png" /></figure><p>21. กรอกข้อมูลดังนี้<br>- Name: ชื่อตามที่ต้องการเพื่อสื่อว่าคือแหล่งข้อมูลอะไร<br>- Type: SimpleJson<br>- Url: http://localhost:3333 (ตามข้อ 19.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*eeBVWv_GTYlgHfgxW2fKXQ.png" /></figure><p>22. กดปุ่ม Add หากเชื่อมต่อ data source สำเร็จจะขึ้นแถบสีเขียวที่มีข้อความว่า “Success Data source is working” ขึ้นมาด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*LkzFTJuj3i8EEAExDk6beQ.png" /></figure><p>23. กลับไปที่หน้า Home (<a href="http://localhost:3000/">http://localhost:3000</a>) กด New dashboard เพื่อสร้างหน้าสำหรับแสดงผลข้อมูล</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0fomG04peuvZFFq8IjUrMQ.png" /></figure><p>24. เราจะนำข้อมูลมาแสดงผลในรูปแบบกราฟกันนะครับ เลือกที่ปุ่ม Graph ได้เลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKHXMOcGSMQwg_ypSbhiEw.png" /></figure><p>25. คลิกที่ Panel Title แล้ว Edit เพื่อทำการตั้งค่า data source ที่จะนำมาแสดง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6nVSr5I6kVtViPOlBbFuw.png" /></figure><p>26. เลือก data source ที่เป็น JSON โดยชื่อตามที่เราตั้งค่าไว้ในข้อ 21.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tNHGiYr85ovEx4NWtwc1Bw.png" /></figure><p>27. ต่อมา เลือก metric ที่จะนำมาแสดง โดยหนึ่ง data source อาจจะมี metric หรือข้อมูลหลายชุด ให้เลือกสักตัวเพื่อนำมาแสดงครับ (หรือสามารถแสดงผลหลาย metric ในกราฟเดียวกันได้โดยกดปุ่ม Add Query ครับ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lh3eQQGziNifa4qdPBAqsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WlK2C2M5p_aCTyM-h7OnJw.png" /></figure><p>28. เราสามารถตั้งชื่อกราฟได้โดยไปที่แถบ General แล้วแก้ไข Info ที่ Title ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g-VmT5nrHB1SrSJ_6BWOMg.png" /></figure><p>29. กด save แล้วทำการตั้งชื่อ dashboard ของเรา เท่านี้เป็นอันเสร็จเรียบร้อยครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*_RrfkJV_W0FJZtxc-ObOJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1VITqAQUc-bQY7gwwvYQSg.png" /></figure><h3>สรุปส่งท้าย</h3><p>หลังจากที่ทำตามขั้นตอนจนครบแล้ว เราจะได้กราฟที่แสดงข้อมูล JSON จาก Node.js server จะสังเกตุว่าข้อมูลไม่มีการอัพเดตหรือเพิ่มขึ้นมา เนื่องจากมันเป็นการดึงข้อมูลออกมาจากไฟล์ JSON เดิมๆซ้ำๆโดยไม่มีการเปลี่ยนแปลงครับ โดยทุกครั้งที่ Grafana ร้องขอข้อมูลก็จะได้แต่ข้อมูลเดิมๆกลับมา ซึ่งในบทความต่อไปผมจะเปลี่ยนให้ Node.js server สามารถรับข้อมูลจากเซนเซอร์ DHT แล้วนำมาแสดงผลบน Grafana แบบ Real time โดยใช้ <a href="http://netpie.io/">NETPIE</a> ร่วมด้วยครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d617190913b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>