Skip to content

Developers: API to Inject GCODE into CONTROL

openbuilds-engineer edited this page May 20, 2019 · 6 revisions

Purpose

This API allows other CAM/PostProcessor/GCODE Generators to inject GCODE into OpenBuilds CONTROL in the same way that OpenBuilds CAM's "Send to OpenBuilds CONTROL" button does:

Example code (Generated using POSTMAN https://www.getpostman.com/ )

Ruby

require 'uri'
require 'net/http'

url = URI("https://mymachine.openbuilds.com:3001/upload")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["User-Agent"] = 'PostmanRuntime/7.13.0'
request["Accept"] = '*/*'
request["Cache-Control"] = 'no-cache'
request["Postman-Token"] = '9cd91cbf-4d85-4e0f-ad35-6cef45453e71,1c053219-f3ad-4d43-9f3f-46c22253f5bc'
request["Host"] = 'mymachine.openbuilds.com:3001'
request["accept-encoding"] = 'gzip, deflate'
request["content-type"] = 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
request["content-length"] = '359'
request["Connection"] = 'keep-alive'
request["cache-control"] = 'no-cache'
request.body = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"edited-gcode.gcode\"\r\nContent-Type: false\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"

response = http.request(request)
puts response.read_body

Javascript/Jquery

var form = new FormData();
form.append("file", "/C:/Users/User/Desktop/edited-gcode.gcode");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://mymachine.openbuilds.com:3001/upload",
  "method": "POST",
  "headers": {
    "User-Agent": "PostmanRuntime/7.13.0",
    "Accept": "*/*",
    "Cache-Control": "no-cache",
    "Postman-Token": "9cd91cbf-4d85-4e0f-ad35-6cef45453e71,94d83ff7-cd3d-45bb-b176-2683ed2c2d8f",
    "Host": "mymachine.openbuilds.com:3001",
    "accept-encoding": "gzip, deflate",
    "content-length": "359",
    "Connection": "keep-alive",
    "cache-control": "no-cache"
  },
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

GOLang

package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://mymachine.openbuilds.com:3001/upload"

	payload := strings.NewReader("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"edited-gcode.gcode\"\r\nContent-Type: false\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("User-Agent", "PostmanRuntime/7.13.0")
	req.Header.Add("Accept", "*/*")
	req.Header.Add("Cache-Control", "no-cache")
	req.Header.Add("Postman-Token", "9cd91cbf-4d85-4e0f-ad35-6cef45453e71,8f15f1e3-3466-4905-aa24-6e9ab465831b")
	req.Header.Add("Host", "mymachine.openbuilds.com:3001")
	req.Header.Add("accept-encoding", "gzip, deflate")
	req.Header.Add("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
	req.Header.Add("content-length", "359")
	req.Header.Add("Connection", "keep-alive")
	req.Header.Add("cache-control", "no-cache")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
Clone this wiki locally