วันพุธที่ 21 มิถุนายน พ.ศ. 2560

ใบงานวันที่21 เมษายน 2560

ใบงานวันที่21 เมษายน 2560
 รหัสนักศึกษา B5711826 ชื่อ-นามสกุล นางสาวไอลดา พลพฤกษ์ 


1. จาก Week02 การทดลอง 3/3 ใหใชงาน Anto ควบคุม 8 LED





 2. จาก Week02 คําถามทดสอบความเขาใจ ให  ทดสอบ HDC1080 ดวยการ Add Lib : https://github.com/closedcube/ClosedCube_HDC1080_Arduino แลวเรียกโปรแกรมทดสอบ File  Example  ClosedCube HDC1080  hdc1080demo  ออกแบบวงจรใหมี อุปกรณเชื่อมตอ NodeMCU ดังตอไปนี้ และใหสามารถเรียกดูและควบคุมไดผาน Anto.io
 o HDC1080 Data=D2,Clock=D1
       - Temperature
       - Humidity
o LED_1 D2
o LED_2 D3
o LED_3 D4
o Sw_Input_1 D5
o Sw_Input_2 D6









3. ปรับปรุง Week03 ทดสอบอานคาจาก HDC1080 แลวสงคาอุณหภูมิและความชื้น ไปแสดงผลที่ ThingSpeak ทุกๆ 30 วินาที http://embeddedlaboratory.blogspot.com/2016/10/posting-dht11-values-to-thingspeak.html





#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <Wire.h>
#include "ClosedCube_HDC1080.h"
ClosedCube_HDC1080 hdc1080;
int StepCount = 1;
String thinkKey = "HIMSN43MQO0YURAJ";
const char* ssid = "kk";
const char* password = "12345678";
const char* host = "api.thingspeak.com";
const int httpsPort = 443;
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Use WiFiClientSecure class to create TLS connection
hdc1080.begin(0x40);
}
void loop() {
//https://api.thingspeak.com/update…
if (StepCount % 30 == 0) {
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
} else {
Serial.println("certificate doesn't match");
}
String url = "/update?api_key=" + thinkKey + "&field1=";
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + hdc1080.readTemperature() + "&field2=" + hdc1080.readHumidity() + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
String line = client.readStringUntil('\n');
if (line.toInt()>0) {
Serial.println("Push Sucess !!");
} else {
Serial.println("Fail!!!");
}
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
}
delay(1000);
Serial.print("Time: ");
Serial.println(StepCount++);
}





4. ปรับปรุงขอ 2 ใหเฝาดูและควบคุมสั่งการไดผาน ThingSpeak broker





วันศุกร์ที่ 16 มิถุนายน พ.ศ. 2560

week09 : NI labview 2014

NI labview 2014


เตรียมการณ์
1.ติดตั้งโปรแกรม LabVIEW  




2.ติดตั้ง NI-VISA ดาวน์โหลดได้ที่ http://www.ni.com/download/ni-visa-5.0.3/2251/en/ 


3.ติดตั้ง l JKI VI Package Manager (VIPM) Community Edition (Free) ดาวน์โหลดได้ที่ http://jki.net/vipm/download





4. ติดตั้ง LabVIEW Interface for Arduino ทำตามวิธีด้านล่างได้เลย (ต้องติดตั้ง JKI VI Package Manager ก่อนนะคะ




ค้นหา "Arduino"


คลิกติดตั้ง
 
คลิก I Agree (Don,t Prompt me Again)

คลิก I Accept

จะมี Windows Security Alert คลิก Allow access


หากมีข้อความ VIPM-Batch Process Error ขึ้นมาให้ แก้ไขดังนี้


เข้าโปรแกรม Labview เข้าเมนู Tools>>Options.



เลือก VI Server คลิก Add ในช่อง Machine name/address ใส่ 127.0.0.0 แล้วคลิก OK แล้วลองติดตั้งใหม่
  
5.ติดตั้ง โปรแกรม Arduino (แนะนำให้ติดตั้ง เวอร์ชั่น 1.0.5) 
ดาวน์โหลดได้ที่ http://arduino.googlecode.com/files/arduino-1.0.5-r2-windows.exe




7.โหลด LabVIEW Interface for Arduino Firmware ลงใน Arduino Borad โดยไปโหลดใน 
C:\Program Files\National Instruments\LabVIEW 2013\vi.lib\LabVIEW Interface for Arduino\Firmware\LIFA_Base



คลิก Sketch >> Add File..


เลือก C:\Program Files\National Instruments\LabVIEW 2013\vi.lib\LabVIEW Interface for Arduino\Firmware\ LabVIEWInterface 


หลังจาก Add File Sketch ก็สามารถโหลดลง Arduino ได้เลย

 ทดสอบโปรแกรมตัวอย่าง “Knight Rider KITT LEDs.Vi”


o   ให้แน่ใจว่าโหลด VIFA_Base.pdeไปยัง Arduino Board แล้ว
o   เลือก COM Port ให้ถูกต้องก่อนสั่ง RUN
o   เมื่อโปรแกรมทำงาน จะอ่านค่าจากขา A0 เพื่อควบคุมความเร็วในการ ติด-ดับ ของ LED จำนวน 12 ตัว ที่ต่อกับ ขา 2- ขา 13


ทดสอบโปรแกรมอย่างง่าย “Hello LIFA.Vi”





o   ให้แน่ใจว่าโหลด VIFA_Base.pdeไปยัง Arduino Board แล้ว
o   เลือก COM Port ให้ถูกต้องก่อนสั่ง RUN
o   เมื่อโปรแกรมทำงาน จะอ่านค่าจาก Switch ส่งไปยังขา 13 และอ่านค่า ขา 12 มาแสดงผล



แบบฝึกหัด NI Labview 2014

แบบฝึกหัด NI Labview 2014
1.Mission 1/3 Blink LED





2.Stop clock





ตัวอย่างเพิ่มเติมในคาบ









วันเสาร์ที่ 10 มิถุนายน พ.ศ. 2560

week 08 : IOT platfrom

523372 Embedded Systems
เรื่อง IoT platform : IBM Watson
รหัสนักศึกษา B5711826 ชื่อ นางสาว ไอลดา พลพฤกษ์
                                                 

IoT platform: IBM Watson

source:ibminternetofthingsfi.tumblr.com

        We can never expect the Big Blue to miss on the opportunity to making a mark in the internet of things segment. IBM Watson is an IoT platform which is pretty much taken among developers already. Backed by IBM’s hybrid cloud PaaS (platform as a service) development platform, the Bluemix, Watson IoT enables developers to easily deploy IoT applications.
Users of IBM Watson get:
·         Device Management
·         Secure Communications
·         Real Time Data Exchange
·         Data Storage
·         Recently added data sensor and weather data service
Demo Video

Ø ข้อดี ข้อจำกัดของ IoT platform : Watson IoT
        แพลตฟอร์ม Watson IoT ได้รับการออกแบบเพื่อลดความซับซ้อนในการพัฒนา IoT ด้านความรู้ความเข้าใจเพื่อให้คุณสามารถใช้ประโยชน์อินเทอร์เน็ตได้อย่างเต็มที่ การสมัครใช้งาน IoT platform

Ø การสมัครใช้งาน IoT platform : IBM Watson IoT Platfrom

ขั้นตอนการสมัคร IBM Watson IoT Platform

 

1. เข้าไปที่ลิงค์ https://www.ibm.com/internet-of-things/


1.1เข้าไปที่   แล้วคลิกเลือก My IBM           

 
1.2 คลิกเลือก


1.3 กรอกข้อมูลดังรูปด่านล่าง

        1.4.หลังจากนั้น คลิกที่


1.5 หลังจากนั้น ระบบจะส่งรหัสไปที่เมลเราที่เราได้กรอกไว้
1.6. เข้าไปที่เมลเพื่อเอารหัส


1.7. นำรหัสที่ได้ในเมลมากรอกดังรูป


1.8. หลังจากกรอกรหัสยืนยันเสร็จแล้ว คลิกเลือก  




            
            เสร็จสิ้นการสมัคร

Ø เรียกใช้ ESP8266 / Arduino เป็นอุปกรณ์ที่ได้รับการจัดการ IBM Watson IoT Platform

ส่วนผสม ESP8266 เป็นขั้นเป็นตอน

1.     1. Intermediate

          การเป็นอุปกรณ์ที่ได้รับการจัดการในแพลตฟอร์ม IBM Watson IoT ช่วยเพิ่มประสิทธิภาพในการจัดการอุปกรณ์จากระยะไกลและทำสิ่งต่างๆเช่นการอัปเดตระยะไกลบูตเครื่องใหม่และดำเนินการวินิจฉัย สูตรนี้จะแสดงวิธีเริ่มต้นใช้งานการกำหนดค่า ESP8266 / Arduino เป็นอุปกรณ์ที่มีการจัดการ

2.      2.ก่อนอื่นคุณต้องมี ESP8266

          มีหลายประเภทให้เลือกทั้งหมดควรจะทำงานที่นี่ฉันใช้กระดานสไตล์ NodeMCU ซึ่งง่ายต่อการใช้ต้นแบบเนื่องจากมีการสนับสนุน USB สำหรับเขียนโปรแกรมและเปิดเครื่อง ESP8266



3.      3.จากนั้นติดตั้ง Arduino IDE

          ขอรับ Arduino IDE ที่นี่ การใช้ IDE เวอร์ชัน 1.6.5 หรือที่ใหม่กว่าทำให้ง่ายต่อการเพิ่มการสนับสนุน ESP8266 ไปยัง IDE ด้วย Arduino IDE ติดตั้งใช้ฟังก์ชั่น Board Manager เพื่อเพิ่มการสนับสนุนสำหรับ ESP8266 ดูที่นี่สำหรับวิธีการทำเช่นนั้น https://github.com/esp8266/Arduino#installing-with-boards-manager

4.      4.พิ่มไลบรารี MQTT PubSubClient

          IBM Watson IoT Platform ใช้โปรโตคอล MQTT เพื่อเพิ่มไลบรารี MQTT PubSubClient ลงใน Arduino IDE นี้จะต้องเป็นรุ่นล่าสุดของห้องสมุดที่จะทำงานกับ ESP8266 ผมใช้รุ่น 2.3 จากที่นี่
(คุณสามารถนำเข้า zip library ไปยัง Arduino IDE จากตัวเลือกเมนู IDE Sketch -> รวม Library -> Add .ZIP Library)



5.    5.  เพิ่มห้องสมุด ArduinoJson

          IBM Watson IoT Platform ใช้ข้อความที่จัดรูปแบบ JSON เพื่อให้รหัส Arduino ง่ายกว่าการใช้ไลบรารีการแยกวิเคราะห์ Json ฉันใช้ ArduinoJson แล้วจึงเพิ่ม Arduino IDE ลงไป ฉันใช้เวอร์ชัน 5.0.7 แต่เวอร์ชันล่าสุดของไลบรารีควรใช้งานได้ ค้นหาได้ที่นี่: https://github.com/bblanchon/ArduinoJson/releases/tag/v5.0.7
(คุณสามารถนำเข้า zip library ไปยัง Arduino IDE จากตัวเลือกเมนู IDE Sketch -> รวม Library -> Add .ZIP Library)

6.    6.  ลงทะเบียนเพื่อ Bluemix และแพลตฟอร์ม IBM Iats Watson

          ถัดไปคุณต้องลงชื่อสมัครเข้าใช้ IBM Watson IoT Platform และสร้าง "องค์กร" และ "อุปกรณ์" รายละเอียดนี้ได้อธิบายไว้ที่เว็บไซต์ IBM และเกี่ยวข้องกับการลงชื่อสมัครใช้ Bluemix และ Internet of Things Platform และใน Bluemix Catalog เพิ่ม Internet of Things Service การทำเช่นนี้จะสร้าง Organization ของคุณจากนั้นในแดชบอร์ด IoT คุณสามารถเพิ่มอุปกรณ์ได้ มีหลายทางเลือกในการตั้งค่าเกือบทั้งหมดสามารถเว้นว่างได้คุณเพียงต้องการอุปกรณ์ประเภทหนึ่งฉันใช้ "ESP8266" และ ID อุปกรณ์ฉันใช้ "Test1"
เมื่อสร้างอุปกรณ์แล้วคุณจะเห็นหน้าข้อมูลประจำตัวผู้ใช้อุปกรณ์และคุณต้องบันทึกรายละเอียดเหล่านั้นซึ่งใช้เพื่อปรับแต่งร่าง Arduino ของคุณในขั้นตอนถัดไป


7.      The Arduino Sketch

Copy the following sketch to the Arduino IDE:
/**

 IBM IoT Foundation managed Device



 Author: Ant Elder

 License: Apache License v2

*/

#include <ESP8266WiFi.h>

#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient/releases/tag/v2.3

#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson/releases/tag/v5.0.7



//-------- Customise these values -----------

const char* ssid = "<yourWiFiSSID>";

const char* password = "<yourWiFiPassword>";



#define ORG "<yourOrg>"

#define DEVICE_TYPE "yourDeviceType"

#define DEVICE_ID "yourDevice"

#define TOKEN "yourDeviceToken"

//-------- Customise the above values --------



char server[] = ORG ".messaging.internetofthings.ibmcloud.com";

char authMethod[] = "use-token-auth";

char token[] = TOKEN;

char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID;



const char publishTopic[] = "iot-2/evt/status/fmt/json";

const char responseTopic[] = "iotdm-1/response";

const char manageTopic[] = "iotdevice-1/mgmt/manage";

const char updateTopic[] = "iotdm-1/device/update";

const char rebootTopic[] = "iotdm-1/mgmt/initiate/device/reboot";



void callback(char* topic, byte* payload, unsigned int payloadLength);



WiFiClient wifiClient;

PubSubClient client(server, 1883, callback, wifiClient);



int publishInterval = 30000; // 30 seconds

long lastPublishMillis;



void setup() {

 Serial.begin(115200); Serial.println();



 wifiConnect();

 mqttConnect();

 initManagedDevice();

}



void loop() {

 if (millis() - lastPublishMillis > publishInterval) {

   publishData();

   lastPublishMillis = millis();

 }



 if (!client.loop()) {

   mqttConnect();

   initManagedDevice();

 }

}



void wifiConnect() {

 Serial.print("Connecting to "); Serial.print(ssid);

 WiFi.begin(ssid, password);

 while (WiFi.status() != WL_CONNECTED) {

   delay(500);

   Serial.print(".");

 }

 Serial.print("nWiFi connected, IP address: "); Serial.println(WiFi.localIP());

}



void mqttConnect() {

 if (!!!client.connected()) {

   Serial.print("Reconnecting MQTT client to "); Serial.println(server);

   while (!!!client.connect(clientId, authMethod, token)) {

     Serial.print(".");

     delay(500);

   }

   Serial.println();

 }

}



void initManagedDevice() {

 if (client.subscribe("iotdm-1/response")) {

   Serial.println("subscribe to responses OK");

 } else {

   Serial.println("subscribe to responses FAILED");

 }



 if (client.subscribe(rebootTopic)) {

   Serial.println("subscribe to reboot OK");

 } else {

   Serial.println("subscribe to reboot FAILED");

 }



 if (client.subscribe("iotdm-1/device/update")) {

   Serial.println("subscribe to update OK");

 } else {

   Serial.println("subscribe to update FAILED");

 }



 StaticJsonBuffer<300> jsonBuffer;

 JsonObject& root = jsonBuffer.createObject();

 JsonObject& d = root.createNestedObject("d");

 JsonObject& metadata = d.createNestedObject("metadata");

 metadata["publishInterval"] = publishInterval;

 JsonObject& supports = d.createNestedObject("supports");

 supports["deviceActions"] = true;



 char buff[300];

 root.printTo(buff, sizeof(buff));

 Serial.println("publishing device metadata:"); Serial.println(buff);

 if (client.publish(manageTopic, buff)) {

   Serial.println("device Publish ok");

 } else {

   Serial.print("device Publish failed:");

 }

}



void publishData() {

 String payload = "{\"d\":{\"counter\":";

 payload += millis() / 1000;

 payload += "}}";



 Serial.print("Sending payload: "); Serial.println(payload);



 if (client.publish(publishTopic, (char*) payload.c_str())) {

   Serial.println("Publish OK");

 } else {

   Serial.println("Publish FAILED");

 }

}



void callback(char* topic, byte* payload, unsigned int payloadLength) {

 Serial.print("callback invoked for topic: "); Serial.println(topic);



 if (strcmp (responseTopic, topic) == 0) {

   return; // just print of response for now

 }



 if (strcmp (rebootTopic, topic) == 0) {

   Serial.println("Rebooting...");

   ESP.restart();

 }

 if (strcmp (updateTopic, topic) == 0) {

   handleUpdate(payload);

 }

}



void handleUpdate(byte* payload) {

 StaticJsonBuffer<300> jsonBuffer;

 JsonObject& root = jsonBuffer.parseObject((char*)payload);

 if (!root.success()) {

   Serial.println("handleUpdate: payload parse FAILED");

   return;

 }

 Serial.println("handleUpdate payload:"); root.prettyPrintTo(Serial); Serial.println();



 JsonObject& d = root["d"];

 JsonArray& fields = d["fields"];

 for (JsonArray::iterator it = fields.begin(); it != fields.end(); ++it) {

   JsonObject& field = *it;

   const char* fieldName = field["field"];

   if (strcmp (fieldName, "metadata") == 0) {

     JsonObject& fieldValue = field["value"];

     if (fieldValue.containsKey("publishInterval")) {

       publishInterval = fieldValue["publishInterval"];

       Serial.print("publishInterval:"); Serial.println(publishInterval);

     }

   }

 }

}

Customise the lines after “//——– Customise these values ———–” with your WiFi network SSID and password and with the IoT Device Credentials from the previous step.

กำหนดเส้นหลังจาก "// --- ปรับแต่งค่าเหล่านี้ ----" ด้วย SSID และรหัสผ่านเครือข่าย Wi-Fi และ IoT Device Credentials จากขั้นตอนก่อนหน้า


8. อัปโหลดและเรียกใช้ sketch

          อัพโหลดสเก็ตช์ไปที่ ESP8266 แล้วเปิด Serial Monitor และคุณจะเห็นมันลงทะเบียนเป็นอุปกรณ์ที่มีการเก็บรวบรวมและเริ่มเผยแพร่ข้อมูลทุกๆ 30 วินาที

9.ดูข้อมูลที่เผยแพร่ใน IBM Dashboard แพลตฟอร์ม IoT ของ IBM Watson

คุณสามารถดูกิจกรรมและข้อมูลที่เผยแพร่จากอุปกรณ์ของคุณบนแผงควบคุม IoT โดยไปที่อุปกรณ์ของคุณและคลิกที่อุปกรณ์:

10. กำหนดค่าอุปกรณ์ใหม่จากแผงควบคุมแพลตฟอร์ม IBM Watson IoT Platform Dashboard

          คุณสามารถเปิดการกำหนดค่าอุปกรณ์จากแผงควบคุม IoT โดยการเรียกดูอุปกรณ์และคลิกที่อุปกรณ์หรือไปที่ URL นี้: https: // <yourORG> .internetofthings.ibmcloud.com / dashboard / # / devices / browse / drilldown / <yourDeviceType> / <yourDeviceId>
เลื่อนลงไปที่ส่วนข้อมูลเมตาและคุณจะเห็นข้อมูลเมตา JSON ที่ส่งจาก Arduino:

          พิมพ์ค่า publishInterval เพื่อเปลี่ยนเป็น 10000 และคลิกที่ปุ่ม Confirm Changes และคุณจะเห็น Arduino Serial Monitor ในคำขออัพเดตและ Arduino จะเริ่มเผยแพร่ข้อมูลทุกๆ 10 วินาที:
          กลับไปที่ IoT และเลื่อนไปทางขวาล่างสุดของมุมมองอุปกรณ์ไปยังส่วน Action และควรจะแสดงปุ่ม Reboot,


คลิกที่ Reboot และคุณจะเห็นใน Arduino Serial Monitor การเริ่มต้นใหม่ ESP8266:


1. แค่นั้นแหละ!

          หวังเป็นอย่างยิ่งว่าคุณจะได้รับคำแนะนำเบื้องต้นเกี่ยวกับการใช้ ESP8266 / Arduino เป็นอุปกรณ์ที่ได้รับการจัดการของ IBM Watson IoT Platform
คุณสามารถดูข้อมูลเพิ่มเติมเกี่ยวกับ API การจัดการอุปกรณ์ในเอกสาร IBM Watson IoT Platform ได้ที่: https://docs.internetofthings.ibmcloud.com/#/device-management-operations#device-management-operations