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

You love the digital world, but you still find post-it and paper more effective tools?

This Internet-connected printer will help you keep track of any issue that get opened on your Github repository. Pile up the issues on your desk and enjoy yourself physically trashing all the issues you close!

Understanding a Github API

Github offers a beautiful set of open APIs you can use in your projects.

All the APIs are accessible at https://api.github.com/ and are well documented here.

All the APIs can be tested simply using you browser; for instance if you want to collect informations regarding your Github account just type:

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

In case you want to access information of a Github organization you can use:

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

To collect all the repositories of an organization instead just use:

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



In this tutorial we want to get the list of all the events happening in a specific repository or organization, and filter the ones regarding a new issue.

This will be our starting point:

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

REST with Arduino

Github APIs, like many other Rest APIs, are accessible using a secure HTTPS connection only.  

Thank god the MKR1000 and the WiFi Shield 101 support SSL connection and the WiFi101 Library includes a nice object called WiFiSSLClient. 

You can upload the following code on to your board to test this feature. 

It will connect to your WiFi network, connect to api.github.com and use the client.print() Function to perform a GET request to the server.

#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);
}



To read the response from the server you can use the client.readStringUntil() function. 

With this code we are going to read the response and split the headers from the content of the message.

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



Once uploaded the sketch, if you open the Terminal, you should see the response from the server getting printed. 

Arduino JSON

As you can see, the response from the server is in JSON format.

Although it is possible to parse the response string looking for specific substrings in the message, since the SAMD21 mounted on ZERO and MKR1000 has enough memory, we are going to use the Arduino JSON library, to parse the message and extract the information we need.

You can easily download the Arduino JSON library from the Library Manager.

The printer 

The printer needs a library to work. You can install the Adafruit Thermal Printer Library from the Library Manager as well. 

Connections

Wiring layout

Different models of this printer might look different from this one. Especially regarding the colours of the wires coming out of it. 

Consider that you just have to identify 3 wires :

  • VCC: usually red 
  • GND: usually black
  • RX: if you bought this on the Arduino Store this should be the blue wire. 

In order to power the printer you will need an external power supplier, the USB power supplier is not enough. We suggest using a 5V (min. 2A) power supplier to provide the required current.





EXPANDED TECHNICAL DETAILS

Physical GitHub / Jira Ticket Terminal

The Issue Printer is a clever IoT device that automatically prints new software "Issues" or "Tickets" onto a physical receipt as soon as they are created.

  • GitHub Webhook JSON Parsing: The Arduino (WiFi enabled) acts as a specialized web listener. When a new issue is opened on a GitHub repository, the cloud sends a JSON packet to the Arduino's address.
  • ESC/POS Thermal Print Kernel: The Arduino established a serial link with a Mini Thermal Receipt Printer. The firmware parses the ticket title and description and formats them using ESC/POS commands for a clean physical printout.

Interaction

  • Cloud Editor validated: The complex JSON-parsing and specialized printer timing sequences were refined in the Arduino Web Editor for 100% reliability.

ข้อมูล 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: "en"