กลับไปหน้ารวมไฟล์
issue-printer-725ad4.md

คุณรักโลกดิจิทัล แต่ยังพบว่า post-it และกระดาษเป็นเครื่องมือที่มีประสิทธิภาพมากกว่าใช่หรือไม่?

เครื่องพิมพ์ที่เชื่อมต่ออินเทอร์เน็ตนี้จะช่วยให้คุณติดตาม Issue ใดๆ ที่เปิดขึ้นใน Github repository ของคุณ รวบรวม Issue เหล่านี้ไว้บนโต๊ะทำงานของคุณ และสนุกกับการทิ้ง Issue ทั้งหมดที่คุณปิดทิ้งไปได้ด้วยตัวเอง!

ทำความเข้าใจ Github API

Github มีชุด Open API ที่ยอดเยี่ยมที่คุณสามารถนำไปใช้ในโปรเจกต์ของคุณได้

API ทั้งหมดสามารถเข้าถึงได้ที่ https://api.github.com/ และมีเอกสารประกอบอย่างดี ที่นี่.

API ทั้งหมดสามารถทดสอบได้ง่ายๆ โดยใช้เบราว์เซอร์ของคุณ ตัวอย่างเช่น หากคุณต้องการรวบรวมข้อมูลเกี่ยวกับ Github account ของคุณ เพียงพิมพ์:

https://api.github.com/users/{username}

ในกรณีที่คุณต้องการเข้าถึงข้อมูลของ Github organization คุณสามารถใช้:

https://api.github.com/orgs/arduino

หากต้องการรวบรวม repository ทั้งหมดของ organization ให้ใช้:

https://api.github.com/orgs/arduino/repos



ในบทช่วยสอนนี้ เราต้องการรับรายการ event ทั้งหมดที่เกิดขึ้นใน repository หรือ organization ที่เฉพาะเจาะจง และกรองเฉพาะ event ที่เกี่ยวข้องกับ Issue ใหม่

นี่จะเป็นจุดเริ่มต้นของเรา:

https://api.github.com/orgs/{organization}/events

REST กับ Arduino

Github API เช่นเดียวกับ Rest API อื่นๆ จำนวนมาก สามารถเข้าถึงได้โดยใช้การเชื่อมต่อ HTTPS ที่ปลอดภัยเท่านั้น  

ขอบคุณที่ MKR1000 และ WiFi Shield 101 รองรับการเชื่อมต่อ SSL และ WiFi101 Library มี Object ที่ยอดเยี่ยมชื่อ WiFiSSLClient.

คุณสามารถอัปโหลดโค้ดต่อไปนี้ไปยังบอร์ดของคุณเพื่อทดสอบฟีเจอร์นี้ได้

โค้ดนี้จะเชื่อมต่อกับเครือข่าย WiFi ของคุณ เชื่อมต่อไปยัง api.github.com และใช้ฟังก์ชัน client.print() เพื่อส่ง GET request ไปยังเซิร์ฟเวอร์

#include <SPI.h>
#include <WiFi101.h>

char ssid[] = "xxx"; // your network SSID (name)
char pass[] = "yyy"; // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS;

const char* host = "api.github.com"; //this address is given by Github itself
const int httpsPort = 443;

WiFiSSLClient client;
void setup() {
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);
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(2000);
}
Serial.println("Connected to wifi");
}
void loop() {
if (client.connect(host, httpsPort)) { //Connect to github
String url = "/orgs/arduino/events?page=1&per_page=1"; // /orgs/myRepository/events
Serial.print("requesting URL: "); // " ?page=1&per_page=1 " add this to get events
Serial.println(url); // one by one avoiding the filling of SRAM memory
client.print(String("GET ") + url + " HTTP/1.1\\\\r\\
" + //send an HTTP request
"Host: " + host + "\\\\r\\
" +
"User-Agent: MKR1000\\\\r\\
\\\\r\\
");
// "Connection: close\\\\r\\
\\\\r\\
");
Serial.println("request sent");
}
delay(5000);
String line = "";
while (client.connected()) {
line = client.readStringUntil('\\
');
if (line == "\\\\r") {
Serial.println("headers received");
break;
}
}
line = client.readStringUntil('\\
');
Serial.println(line);
}



หากต้องการอ่าน response จากเซิร์ฟเวอร์ คุณสามารถใช้ฟังก์ชัน client.readStringUntil() ได้

ด้วยโค้ดนี้ เราจะอ่าน response และแยก header ออกจากเนื้อหาของข้อความ

  while (client.connected()) {
line = client.readStringUntil('\\
');
if (line == "\\\\r") {
Serial.println("headers received");
break;
}
}
line = client.readStringUntil('\\
');
Serial.println(line);
}



เมื่ออัปโหลด sketch แล้ว หากคุณเปิด Terminal คุณควรจะเห็น response จากเซิร์ฟเวอร์ถูกพิมพ์ออกมา

Arduino JSON

ดังที่คุณเห็น response จากเซิร์ฟเวอร์อยู่ในรูปแบบ JSON

แม้ว่าจะสามารถ parse response string โดยการค้นหาสับสตริงที่เฉพาะเจาะจงในข้อความได้ แต่เนื่องจาก SAMD21 ที่ติดตั้งบน ZERO และ MKR1000 มีหน่วยความจำเพียงพอ เราจะใช้ Arduino JSON library เพื่อ parse ข้อความและดึงข้อมูลที่เราต้องการออกมา

คุณสามารถดาวน์โหลด Arduino JSON library ได้ง่ายๆ จาก Library Manager.

เครื่องพิมพ์

เครื่องพิมพ์ต้องการ library เพื่อทำงาน คุณสามารถติดตั้ง Adafruit Thermal Printer Library ได้จาก Library Manager เช่นกัน

การเชื่อมต่อ

ผังการเดินสาย

เครื่องพิมพ์รุ่นต่างๆ อาจมีลักษณะแตกต่างจากเครื่องพิมพ์นี้ โดยเฉพาะอย่างยิ่งเกี่ยวกับสีของสายไฟที่ออกมาจากตัวเครื่อง  

พิจารณาว่าคุณจะต้องระบุสายไฟเพียง 3 เส้นเท่านั้น :

  • VCC: โดยปกติจะเป็นสีแดง
  • GND: โดยปกติจะเป็นสีดำ
  • RX: หากคุณซื้อสิ่งนี้จาก Arduino Store ควรจะเป็นสายสีน้ำเงิน

ในการจ่ายไฟให้กับเครื่องพิมพ์ คุณจะต้องใช้ External Power Supply เนื่องจาก External Power Supply ของ USB ไม่เพียงพอ เราแนะนำให้ใช้ Power Supply ขนาด 5V (ขั้นต่ำ 2A) เพื่อจ่ายกระแสไฟที่จำเป็น





รายละเอียดทางเทคนิคเพิ่มเติม

เครื่องพิมพ์ตั๋ว GitHub / Jira แบบกายภาพ

Issue Printer เป็นอุปกรณ์ IoT ที่ชาญฉลาด ซึ่งจะพิมพ์ "Issue" หรือ "Ticket" ของซอฟต์แวร์ใหม่ลงบนใบเสร็จทันทีที่ถูกสร้างขึ้น

  • Gi

ข้อมูล Frontmatter ดั้งเดิม

title: "Issue Printer"
description: "Print Github issues on paper and stack them on your desk. Every time you close an issue and you can literally \"bin\" it!"
author: "Arduino_Genuino"
category: "Internet of Things, BT & Wireless"
tags:
  - "github"
  - "internet of things"
  - "productivity"
views: 14537
likes: 12
price: 2450
difficulty: "Intermediate"
components:
  - "1x Arduino MKR1000"
  - "1x 3D Printer (generic)"
  - "1x Thermal Printer"
tools: []
apps:
  - "1x Arduino Web Editor"
downloadableFiles:
  - "https://github.com/CasaJasmina/Issue-Printer/blob/master/Arduino_Github_Printer/Arduino_Github_Printer.ino"
  - "https://github.com/CasaJasmina/Issue-Printer/blob/master/Arduino_Github_Printer/Arduino_Github_Printer.ino"
documentationLinks: []
passwordHash: "e4fbd7f93421b14d7128a7eb0d9e2b2c934a75ff25b5bdb63d5698b94adcf39b"
encryptedPayload: "U2FsdGVkX1/cYU815QDCcX0OOSZP1GuOuHvHd2kKfXfEmeM2fz69iRFl1USNr4GDWqC0cYuke+j4quH9wa8SnsQa2cI8HP57WiSZUWNpNvQ="
seoDescription: "Build an Issue Printer to print Github issues. A fun way to physically bin your tasks once you close an issue."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/issue-printer-725ad4_cover.jpg"
lang: "th"