Code Monkey home page Code Monkey logo

node-makerbot-rpc's Introduction

MakerBot JSON-RPC Library for Node.js

THIS LIBRARY GRADUATED TO 1.0.0!

With every new feature comes breaking changes. See here for more info.

This library acts as an abstraction layer for the JSON-RPC methods that MakerBot 3D printers use. At the moment, it supports doing the following:

  • Authentication. You can authenticate with a Thingiverse OAuth token or locally by pressing on the knob.
  • Remote control. Control a printer remotely with a Thingiverse token and the printer's ID.
  • Get realtime camera stream (experimental). Get the realtime camera stream out of the printer.
  • Get realtime printer status. You can get the real-time status of the printer (what it's doing, info about the extruder, and much more).
  • Load/unload filament. You can instruct your printer to start the filament loading/unloading process.
  • Cancel current process. You can instruct your printer to cancel the current process (unloading/loading filament, printing, assisted calibration, etc.)
  • Print a file. You can instruct your printer to print a .makerbot file remotely.

Projects using this library

Example

const MakerbotRpc = require('makerbot-rpc')
const fs = require('fs')

var printer = new MakerbotRpc({
  authMethod: "reflector",
  accessToken: "thingiverseAccessToken",
  printerId: "yourPrinterId"
})

printer.on("connected", printerInfo => {
  console.log(`Connected to ${printerInfo.machine_name}, attempting authentication`)
})

printer.on("connect-error", err => {
  console.log("error connecting!", err)
})

printer.on("auth-push-knob", () => {
  console.log("To finish authentication, press the knob on your printer.")
})

printer.on("authenticated", res => {
  console.log("Authenticated!")
  printer.startCameraStream()
})

printer.on("camera-frame", frame => {
  printer.endCameraStream()
  fs.writeFile("testimg/test.jpg", frame, () => { })
})

printer.on("state", notif => {
  console.log(printer.state)
})

node-makerbot-rpc's People

Contributors

deepsourcebot avatar tjhorner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-makerbot-rpc's Issues

Camera Feed Parsing

This isn't essential, but it would be nice to have. There are two routes that we could use to get the camera feed:

  • Via JSON-RPC, by sending the request_camera_stream method, then parsing each frame whenever the printer sends us camera_frame. This is sorta hard to implement, but totally doable.
  • Via HTTP, by sending the /camera method to the printer to receive a single frame. This is slower, obviously, but can work if we only want a snapshot every now and then. It would also involve sending another authentication HTTP call for the camera context.

Timeout Handling

If the connection to a printer times out, it just crashes. To fix this, I should add an event for when the TCP connection times out, so the user can handle it appropriately.

Send print files in chunks

Right now, literally the entire file is sent all at once when you print a file. This isn't ideal, since if you, for example, request a JSON-RPC method while it's sending, it will corrupt the file. We should split the file into chunks and send multiple put_raw requests to prevent corruption.

Additionally, it might also be a good idea to prevent requests from sending while the file is sending (could queue them up, I guess).

More efficient camera feed parsing

The way binary data (and thus camera frames) are parsed is very hacky, uses some weird methods to parse JSON that might have been in the packet, etc. It's really experimental at the moment, and it should definitely be reworked to be more efficient.

Also, it will strictly only work for JPEGs at the moment, which is not ideal.

Provide method to get single camera frame

This could be a convenience method that starts the camera stream, and once it receives a frame, it calls back the promise and ends the stream.

We could either do this OR use the /camera method the printer provides on its HTTP server, but this wouldn't work for remote printers. So I think starting then ending the stream is the best route.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.