]> git.aero2k.de Git - sirius.git/commitdiff
Add a processing example
authorQuentin Dufour <quentin@dufour.tk>
Mon, 1 May 2017 15:53:54 +0000 (17:53 +0200)
committerQuentin Dufour <quentin@dufour.tk>
Mon, 1 May 2017 15:54:49 +0000 (17:54 +0200)
README.md

index 446ab0ea3e08a893ccbaf23f8ec64271afb861de..63b45f51b1e43a2da9a9036e4d2f080f00f284bc 100644 (file)
--- a/README.md
+++ b/README.md
@@ -72,7 +72,8 @@ WantedBy=multi-user.target
 
 If you want to print messages from your application, you can use the external API.
 
-For example, with curl:
+
+#### With curl
 
 ```bash
 curl \
@@ -80,6 +81,45 @@ curl \
   http://127.0.0.1:5000/ext_api/v1/printer/1/print_html?api_key=<key>
 ```
 
+#### With Processing
+
+You'll need an external library named unirest and its dependencies.
+You can download it directly from my server : [unirest-java-1.4.10.jar](https://cloud.deuxfleurs.fr/f/685c77efbd/?raw=1)
+Or, if you prefer, you can compile it from the source by following this [guide](http://blog.mashape.com/installing-unirest-java-with-the-maven-assembly-plugin/).
+
+Once you have the `unirest-java-1.4.10.jar` (or another version):
+
+  1. Create a folder named `code` inside your sketchbook folder, next to your Processing files (use File explorer on Windows, Finder on Mac OS, etc.)
+  2. Put `unirest-java-1.4.10.jar` in this folder
+
+Now restart processing and add the following in your project:
+
+```processing
+import com.mashape.unirest.http.*;
+import com.mashape.unirest.http.exceptions.UnirestException;
+
+boolean little_print(String face, String message, String endpoint, String api_key) {
+  try {
+    com.mashape.unirest.http.HttpResponse<String> request = Unirest.post(endpoint+"?api_key="+api_key)
+      .body("{\"message\": \"" + message.replace("\"", "\\\"") +"\", \"face\": \"" + face.replace("\"", "\\\"") + "\"}")
+      .asString();
+  
+    println(request.getBody());
+    return true;
+  } catch (Exception e) {
+    println(e);
+    return false;
+  }
+}
+
+```
+
+Each time you want to use your little printer to print something, you should write something like this (don't forget to put your API key and update the URL):
+
+```processing
+little_print("noface", "<h1 style=\"margin-top: 100px\"> PROOOOCESSING </h1>", "http://127.0.0.1:5000/ext_api/v1/printer/1/print_html", "xxxxxxxxx");
+```
+
 ### Environment variables
 
 The server can be configured with the following variables: