-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
51 lines (39 loc) · 1.16 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const axios = require('axios')
module.exports = class Client {
constructor() {
this.client = axios.create({
baseURL: 'http://10.0.0.119'
})
}
async uploadFile(name, script) {
const filename = `0:/gcodes/${name}`
const response = await this.client.put(`/machine/file/${encodeURIComponent(filename)}`, script, {
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
})
// file location is in response.headers.location
return response
}
async startFile(location) {
if (!location) {
throw new Error('location is required')
}
console.log(`running file ${location}`)
return this.sendCode(`M32 "${location}"`)
}
// macros wait for completion
async runMacro(location) {
if (!location) {
throw new Error('location is required')
}
console.log(`running macro ${location}`)
return this.sendCode(`M98 P"${location}"`)
}
async sendCode(code) {
// run script for the thing
const response = await this.client.post('/machine/code', code, {
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
})
// response.data has the text result
return response
}
}