doodle3d / doodle3d-api Goto Github PK
View Code? Open in Web Editor NEWDoodle3D API for communication with the Doodle3D WiFi-Box
Doodle3D API for communication with the Doodle3D WiFi-Box
When sending large gcode files we have to take into account a couple of things
In order to keep under the 4mb size limit there are 2 options; reject files that exceed the size limit. Send part of the file up to 4mb and wait until buffer is cleared before sending te rest. The downside of this is that the browser must stay active during the print.
Currently the connect (find boxes) logic is only implemented in the example. Shouldn't this be included in the API?
See: https://github.com/Doodle3D/doodle3d-connect/blob/master/js/api/ConnectAPI.js
In the old doodle3d-client Printer class we updated a message to display the send percentage, which is nice feedback. Would be great if this new api could just emit an event with this info so users can use this information in a way they like.
To prevent crashing of the small webserver on the WiFi-Box it might be interesting to look into a throttle mechanism for all rest calls. This could queue requests that come in to quickly after a prev request.
Finding a way to give priority to some calls would also be important, to prioritize print calls for example.
Currently a user has to specify the parameters in a data object, but this partly defeats the purpose of this library, in that it's easier to see what can be done with the API.
Especially with ES6's default arguments this could work really nice.
for (var i = 0; i < boxes.length; i ++) {
var boxData = boxes[i];
if (knownIPs.indexOf(boxData.localip) === -1) {
this.addBox(boxData);
}
}
With for ... of
, using block scoped let
and adding a variable.
for(let boxData of boxes) {
// giving this a name makes it clearer what you're doing, without requiring comments.
let known = knownIPs.indexOf(boxData.localip) === -1;
if(known) this.addBox(boxData);
}
With the ES6 Array.include()
method:
for(let boxData of boxes) {
if(knownIPs.includes(boxData.localip)){
this.addBox(boxData);
}
}
Add basic package info to package.json, this could be done with npm init
.
Let's use mayor version 0, until the public api settles down. (NPM init defaults to 1.0.0) More info:
Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.
From: http://semver.org/
In the old doodle3d-client Printer class we checked the state to make sure we didn't send more gcode to a printer that was stopped
https://github.com/Doodle3D/doodle3d-client/blob/master/js/Printer.js#L195
In the client that's used on the WiFi-Box we have a lot of checks to handle connection issues, this library should also perform these.
Relevant code: From: https://github.com/Doodle3D/doodle3d-client/blob/master/js/Printer.js
The logic in pseudo code:
Start checking printer status
Send print print
if print to large:
overrule state to idle
start checking status
enable warning about leaving when still sending.
send first part (supply seq_number & seq_total)
when receiving response
if response.status success:
if print sending completed
remove leave warning
else
if state is printing / buffering:
send next part
else if state is disconnected:
retry sending same part after a delay
else if response.status fail:
if reason buffer full:
wait for buffer space...
else if reason seq_num_mismatch and sequence number is current sequence number:
// we probably missed a response and the box is one chunk ahead
send next part
else:
if status isn't stopping:
display error
start checking status
when sending times out:
retry sending same part after a delay
Wait for buffer space
if WiFi-Box's buffer is above a certain ratio:
call this function after a delay
else
if state is printing / buffering
send same part
On stop
clear all delays / timeouts
remove leave warning
on response
start checking status
on timeout
retry stop after delay
start checking status
Check printer status (/info/status)
on response:
if response.status succes
state = data.state
else
status = unknown
try checking status again after delay
on timeout
status = disconnected
try checking status again after longer delay
When state is overridden
store state
stop checking status
If we include the connect API (#8) it might make sense to restructure the library slightly.
var d3d = new Doodle3DAPI();
d3d.refresh(); // or d3d.autoRefresh()
d3d.on("boxAppeared",(box) => {
// includes box.id retrieved from connect.doodle3d.com
console.log(`New Doodle3D WiFi-Box found: '${box.id}' with ip: '${box.ip} '`);
box.printer.print("G1 X1 X2");
box.info.autoRefresh();
box.info.on("status",(status) => {
console.log(`${box.id} status: `,status);
});
})
Or skipping our connect api:
var d3d = new Doodle3DAPI();
var box = d3d.getBox("192.168.5.1"); // box.id not (yet) available. Maybe we can do a separate request to the box to fill this in?
box.info.autoRefresh();
box.info.on("status",(status) => {
var id = box.id? box.id : box.ip;
console.log(`${id} status: `, status);
});
More inspiration:
Remove jquery and use framework specificly for ajax calls or write own ajax calls.
Maybe we can use the upcoming fetch()
?
http://jakearchibald.com/2015/thats-so-fetch/
Looks like it isn't included in Babel, maybe we can use the following polyfill: https://github.com/github/fetch
Currently there is a lot of printing specific code in the main file, shouldn't we move this to the printer endpoint class?
Currently there is only an auto update status function for the info endpoint, but this could also be useful for the update and network endpoints.
Reset interval before starting a new one:
https://github.com/Doodle3D/Doodle3D-API/blob/develop/src/doodle3dmanager.js#L17
var knownIPs = [];
for (var i = 0; i < this.boxes.length; i ++) {
var boxData = this.boxes[i].boxData;
knownIPs.push(boxData.localip);
}
Can be also be done like:
var boxes = [
{ localIP:'10.0.0.1' },
{ localIP:'10.0.0.2' },
{ localIP:'10.0.0.3' }
];
var knownIPs = boxes.map((boxData) => boxData.localIP);
console.log(knownIPs)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.