การใช้งาน Anto Platform + สร้าง Thing ทำงานร่วมกับไฟ LED

IOT - Internet of things
ไอโอที (IoT) หมายถึงเครือข่ายของวัตถุ อุปกรณ์ พาหนะ สิ่งปลูกสร้าง และสิ่งของอื่นๆ ที่มีวงจรอิเล็กทรอนิกส์ ซอฟต์แวร์ เซ็นเซอร์ และการเชื่อมต่อกับเครือข่าย ฝังตัวอยู่ และทำให้วัตถุเหล่านั้นสามารถเก็บบันทึกและแลกเปลี่ยนข้อมูลได้

Moderator: mindphp, ผู้ดูแลกระดาน

Patipat
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 996
ลงทะเบียนเมื่อ: 10/06/2019 10:12 am

การใช้งาน Anto Platform + สร้าง Thing ทำงานร่วมกับไฟ LED

โพสต์ที่ยังไม่ได้อ่าน โดย Patipat »

ในการจะทำ IOT หรือ Internet of thing เราต้องทำด้วยกัน 2 อย่างคือ Soft ware และ Hard ware ซึ่ง soft ware นั้นก็จะเป็นในเรื่องการเขียนโปรแกรม ส่วน Hard ware ของ IOT ก็จะเป็นในเรื่องการต่อวงจรของตัว sensor ต่างๆ ในบทความนี้จะมาพูดในเรื่อง Soft ware ในการเขียนโปรแกรมเพื่อเชื่อมต่อกับ Hard ware ที่เป็น IOTและต้องการจะสั่งงานผ่าน Smart Phone หรือ เว็บไซต์ เราจะต้องมีโปรแกรมที่สามารถทำตัวเชื่อมต่อกันได้ วันนี้ได้ยกตัวอย่างโปรแกรม Anto Plaform IOT
เป็นโปรแกรมที่สามารถสั่ง Hard ware ผ่านเว็บไซต์ได้โดยไม่ต้องเขียนโค้ดสร้างฟังก์ชันให้ยุ่งยาก ในตัว Plat form ตัวนี้มีฟังก์ชันหลายอย่าง เพียงเราแค่ อ้างรหัส ting ให้ถูกต้อง

เริ่มแรก ให้คลิกที่ เว็บ Anto เพื่อ Get start > https://www.anto.io แล้วกด Start a project ตามภาพด้านล่าง
Selection_999(033).png
ต่อมาให้กด เพื่อจะสร้างโปรเจค
Selection_999(032).png
Selection_999(032).png (10.57 KiB) Viewed 2772 times
ต่อมากด
Selection_999(034).png
สิ่งของที่ต้องเตรียม ในการทำตัวทดลองนี้
Software ที่ต้องการ
Arduino IDE v1.8 ขึ้นไป
ดาวน์โหลดได้ที่ Arduino IDE

การติดตั้งให้ arduino IDE รู้จัก board NodeMCU
เข้าเมนู File > Preferences จากนั้นใส่ข้อความว่า
http://arduino.esp8266.com/stable/package_esp8266com_index.json
ลงไปในช่อง Additional Board Manager URLs แล้วกดตกลง
การติดตั้งบอร์ด
เข้าเมนู Tools > Boards Manager พิมพ์ในช่องค้นหาว่า esp8266
กดเลือก Install รอการติดตั้ง (ใช้เวลาสักครู่)
ติดตั้ง Library Anto
เข้าเมนู Sketch > Include Library > Manage Library พิทพ์ในช่องค้นหาว่า anto-esp8266
กดเลือก Install รอการติดตั้ง


สร้าง Things Channel key ให้เข้ามาที่ เว็บไซต์หลัก https://www.anto.io แล้วกด Control panal ตามภาพด้านล่าง
Selection_999(035).png
จะเข้ามาสู่หน้านี้
Selection_999(036).png
กด Create new project
Selection_999(037).png
แล้วก็ใส่ ชื่อโปรเจค > คำอธิบาย > Hardware ที่ใช้ แล้วกด Add
Selection_999(039).png
Selection_999(039).png (13.4 KiB) Viewed 2772 times
ต่อมาให้กด รูปแว่นขยาย แล้วก็ สร้าง Chanal เพื่อเก็บค่า
1.
Selection_999(040).png
Selection_999(040).png (6.38 KiB) Viewed 2772 times
2.
Selection_999(041).png
Selection_999(041).png (12.86 KiB) Viewed 2772 times
เราจะได้มา สองสวิชในการใช้งาน
Selection_999(042).png
Selection_999(042).png (11.78 KiB) Viewed 2772 times
สร้างคีย์ในการอ่านค่า
1.
Selection_999(043).png
Selection_999(043).png (12.73 KiB) Viewed 2772 times
2.
Selection_999(044).png
Selection_999(044).png (26.87 KiB) Viewed 2772 times
แล้วก็เขียนโปรแกรม
ในส่วนของโค๊ดก็จะมี

โค้ด: เลือกทั้งหมด

#include <AntoIO.h>

const char *ssid = "your access point SSID";
const char *pass = "access point password";
const char *user = "your username";
const char *token = "your token";
const char *thing = "your thing";

// initialize AntoIO instance
AntoIO anto(user, token, thing);

//ใน void setup()
Serial.begin(115200);
delay(10);

Serial.println();
Serial.println();
Serial.print("Anto library version: ");
Serial.println(anto.getVersion());

Serial.print("\nTrying to connect ");
Serial.print(ssid);
Serial.println("...");

int value = 0;

anto.begin(ssid, pass, messageReceived);

anto.sub("LED1");
anto.sub("LED2");


pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);


ใน void loop()
void loop() {
  anto.mqtt.loop();
}

Serial.print("Recieved: ");
Serial.print(thing);
Serial.print("/");
Serial.print(channel);
Serial.print("-> ");
Serial.println(payload);

if(channel.equals("LED1")){
    value = payload.toInt();
    if(value == 1){
        digitalWrite(D1,HIGH);
    }
    else{
        digitalWrite(D1,LOW);
    }    
}
else if(channel.equals("LED2")){
    value = payload.toInt();
    if(value == 1){
        digitalWrite(D2,HIGH);
    }
    else{
        digitalWrite(D2,LOW);
    }
}
}
อ้างอิง :
https://antoiot.gitbooks.io/th-document/content/chapter1/hardware-and-program.html

อ้างอิง : https://www.anto.io/


อ้างอิง : https://www.praphas.com/forum/index.php?topic=347.0
Kor ma di kub. :)
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: Bing [Bot] และบุคลทั่วไป 61