An open API service indexing awesome lists of open source software.

https://github.com/skarab42/smoothie-commands

A Smoothie firmware (http|serial) commands API
https://github.com/skarab42/smoothie-commands

Last synced: 6 months ago
JSON representation

A Smoothie firmware (http|serial) commands API

Awesome Lists containing this project

README

          

# smoothie-commands
A Smoothie firmware (http|serial) commands API

Sent commands to smoothie firmware hardware over HTTP or Serial connexion and get in returns some structured data.

- Work In Progress...

> **Table of contents**
>
> * [Online demo](#online-demo)
> * [Install](#install)
> * [Usages](#usages)
> * [HTTP interface](#http-interface)
> - [ES6 module](#es6-module)
> - [Browser](#browser)
> * [Serial interface](#serial-interface)
> * [Commands queue](#commands-queue)
> * [Error types](#error-types)
> * [CommandError](#commanderror)
> * [RequestError](#requesterror)
> * [Supported commands](#supported-commands)
> * [Development](#development)
> - [Install](#install)
> - [Run dev server](#run-dev-server)
> - [Run demo server](#run-demo-server)
> - [Build bundle](#build-bundle)
> - [Build demo](#build-demo)
> - [Publish demo](#publish-demo)
> - [Build all](#build-all)
> - [Lint code](#lint-code)
# Online demo
- [Http interface](http://smoothie-commands.surge.sh/)

# Install
`> yarn add smoothie-commands`

# Usages
## HTTP interface
### ES6 module
```js
import { command } from 'smoothie-commands/http'

command({
address: '192.168.1.42',
command: 'ls',
args: ['/sd']
timeout: 1000
})
.then(response => {
console.log('response:', response)
console.log('data:', response.data)
})
.catch(error => {
console.error(
`${error.name}::${error.type}:`,
error.message,
error.response
)
})
```

### Browser
index.html
```html

```

index.js
```js
smoothieCommands.command({
address: '192.168.1.42',
command: 'ls',
args: ['/sd']
timeout: 1000
})
.then(response => {
console.log('response:', response)
console.log('data:', response.data)
})
.catch(error => {
console.error(
`${error.name}::${error.type}:`,
error.message,
error.response
)
})
```

## Serial interface
- Work In Progress...

# Commands queue
By default parallel request are prohibited and you need to wait for the end of a request before sending another.
But fortunately there is the `queue()` helper to help you manage this constraint.

```js
import { queue } from 'smoothie-commands/http'

const address = '192.168.1.121'

// command list
const commands = [
{ address, command: 'version' },
{ address, command: 'get status' },
{ address, command: 'ls', args: ['/sd'] },
{ address, command: 'G0 X10 Y50' },
{ address, command: 'get status' },
{ address, command: 'get status' }
]

// queue callbacks
const callbacks = {
onStart (payload) {
console.log('start:', payload.commands.length)
},
onPause (payload) {
console.log('pause:', payload.commands.length)
},
onResume (payload) {
console.log('resume:', payload.commands.length)
},
onStop (payload) {
console.log('stop:', payload.commands.length)
},
onSend (payload) {
console.log('send:', payload.command, payload.commands.length)
},
onResponse (payload) {
console.log('response:', payload.response)
},
onError (payload) {
console.error('error:', payload.error)
},
onDone (results) {
console.log('done:', results)
}
}

// create the queue
const myQueue = queue({ commands, ...callbacks })

// append/prepend one command
myQueue.append({ address, command: 'help' })

// append/prepend multiple command (version is called first)
myQueue.prepend({ address, command: 'help' }, { address, command: 'version' })

// append/prepend command block (help is called first)
myQueue.prepend([
{ address, command: 'help' },
{ address, command: 'version' }
])

// mixed style (call => G0 X10 Y50, get status, version, help)
myQueue.prepend(
{ address, command: 'help' },
{ address, command: 'version' },
[
{ address, command: 'G0 X10 Y50' },
{ address, command: 'get status' }
]
)

// start the queue
myQueue.start()
.then(results => {
// return an array of results,
// can by a response or an Error object
console.log(results)
})
// myQueue.pause()
// myQueue.resume()
// myQueue.stop()
```

# Error types
## CommandError
```
ALREADY_SUSPENDED_ERROR
COULD_NOT_CREATE_ERROR
COULD_NOT_DELETE_ERROR
COULD_NOT_MOVE_ERROR
COULD_NOT_OPEN_ERROR
COULD_NOT_UPLOAD_ERROR
CURRENTLY_PLAYING_ERROR
FILE_NOT_FOUND_ERROR
INVALID_ARGUMENTS_ERROR
INVALID_COMMAND_ERROR
KILL_ERROR
MINIMAL_DURATION_ERROR
NOT_CURRENTLY_PLAYING_ERROR
NOT_ENOUGH_SPACE_ERROR
NOT_SUSPENDED_ERROR
NO_HEATERS_FOUND_ERROR
NO_LASER_MODULE_ERROR
UNDEFINED_ERROR
UNDEFINED_SETTING_ERROR
UNKNOWN_DEVICE_ERROR
UNKNOWN_FILE_SIZE_ERROR
UNKNOWN_RESPONSE_ERROR
UNSUPPORTED_COMMAND_ERROR
UNSUPPORTED_PARSER_ERROR
UNSUPPORTED_SUBCOMMAND_ERROR
```

## RequestError
```
NETWORK_ERROR
REQUEST_ABORTED_ERROR
REQUEST_OPEN_ERROR
REQUEST_TIMEOUT_ERROR
PARALLEL_REQUEST_ERROR
SERVER_ERROR
```

# Supported commands
```
abort - Abort currently playing file
break - Enter in MRI mode
calc_thermistor - Calculate the Steinhart Hart coefficients
cat [limit] - Output the contents of a file
cd - Change current absolute path to provided path
config-get [local|sd|cache] - Get config setting value from the specified source
config-load - Load config values from the specified source
config-set - Set value to the specified source setting
dfu - Entering boot mode
echo - Echo echo echo...
fire [duration] - Fire laser manualy
get <...options> - Get some values
get fk [-m] x[,y,z] - Do forward kinematics on the given actuator position and display the cartesian coordinates
get ik [-m] x[,y,z] - Do inverse kinematics on the given cartesian position and display the actuator coordinates
get pos - Get all the various M114 variants
get state - Get state
get status - Get status
get temp [device] - Get temperature for a device
get wcs - Get world coordinate system
help - Get some help
load - Load config values from the specified file
ls [-s] - List directory
md5sum - Get the md5 sum for a file
mem [-v] - Get memory informations
mkdir - Create new directory
mv - Move a file from source to target path
net - Get network informations
play - Play file from SD card
progress [-b] - Get SD or File playing progression
pwd - Get (print) current working directory
remount - Remount SD card
reset - Reset the board
resume - Resume the suspended print
rm - Remove a file or an empty folder
save - Saves the specified config-override file
set_temp - Set device temperature
suspend - Suspend a print in progress
switch [onf|off] - Set or get switch state for a named switch
test circle [feedrate] - Draws a circle around origin
test <...options> - Execute some tests
test jog [feedrate] - Jogs back and forth from origin
test raw - Issues raw steps to the specified axis
test square [feedrate] - Draws a square from origin
thermistors - Get predefined thermistors
upload [path] <...contents> - Saves a stream of text to the named file
version - Get firmware version
```

# Development
### Install
`> yarn install`

### Run dev server
`> yarn serv:dev`

### Run demo server
`> yarn serv:demo`

### Build bundle
`> yarn bundle:http`

`> yarn bundle:http:tiny`

### Build demo
`> yarn build:demo`

### Publish demo
`> yarn surge:demo`

### Build all
`> yarn build`

### Lint code
`> yarn lint`