Skip to content

Commit

Permalink
replaced node-progress with cli-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDittrich committed Dec 13, 2015
1 parent eacfce0 commit 861667a
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 12 deletions.
9 changes: 5 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
### 1.1.0 ###
Added: NodeMCU-Tool to use the connector as well as all CLI functions programmatic
Added: NodeMCU-Tool.js to use the connector as well as all CLI functions programmatically
Added: Colorized terminal messages
Changed: the bin tool has been separated in two files (CLI and API layer)
Changed: all errors are handled as callbacks (node.js standard)
Bugfix: Replaced the progress bar to avoid random empty line terminal output
Added: Low Level API for direct interactions with the LUA interpreter
Changed: The bin tool has been separated in two files (CLI and API layer)
Changed: all errors are handled as callbacks (Node.js standard)
Bugfix: Replaced the progress bar with [cli-progress](https://www.npmjs.com/package/cli-progress) to avoid random empty lines on the terminal

### 1.0.0 ###
Initial public release
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,37 @@ Therefore keep attention to the following limitations:
* You cannot upload files over the serial connection with more than **235 characters per line**
* Your script must not use the string initialization sequence **[===[**


Low Level API
-------------
It's possible to use the underlying "NodeMcuConnector" in your own projects to communicate with a NodeMCU based device.
For more details, take a look into the sources!

**Low Level Example**
Run `node.compile()` on NodeMCU and display the output

```js
var _connector = require('nodemcu-tool').Connector;

// create a new connector instance
var con = new _connector('/dev/ttyUSB4', 9600);

// open the serial connection
con.connect(function(err, response){
// get version, flashid ... message
console.log(response);

// run a command on the LUA command line
con.executeCommand('node.compile("testfile.lua");', function(err, echo, response){
if (err){
console.error('IO Error - ', err);
}else{
console.log(response);
}
});
});
```

Any Questions ? Report a Bug ? Enhancements ?
---------------------------------------------
Please open a new issue on [GitHub](https://github.com/AndiDittrich/NodeMCU-Tool/issues)
Expand Down
23 changes: 16 additions & 7 deletions bin/nodemcu-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// load utils
var _cli = require('commander');
var _progressbar = require('progress');
var _progressbar = require('cli-progress');
var _pkg = require('../package.json')
var _prompt = require('prompt')
var _nodemcutool = require('../lib/NodeMCU-Tool');
Expand Down Expand Up @@ -62,14 +62,23 @@ _cli
.option('-c, --compile', 'Compile LUA file to bytecode (.lc) and remove the original file after upload', false)

.action(function(localFile, options){
var p = null;
// initialize a new progress bar
var bar = new _progressbar.Bar({
format: 'Upload Status {percentage}% [{bar}] | ETA {eta}s',
clearOnComplete: true
});

_nodemcutool.upload(_cli.port, _cli.baud, localFile, options, function(current, total){

if (p){

}else{

// bar initialized ?
if (current == 0) {
bar.start(total, 0);
}else {
bar.update(current);

// finished ?
if (current >= total) {
bar.stop();
}
}
});
});
Expand Down
25 changes: 25 additions & 0 deletions lib/NodeMCU-Tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ var Tool = {
connector.onError(errorHandler);

connector.connect(function(error, response){
if (error){
logError('NodeMCU-Tool', 'Unable to establish connection');
return;
}

logStatus('NodeMCU-Tool', 'Connected');
logStatus('NodeMCU', response);

Expand Down Expand Up @@ -86,6 +91,11 @@ var Tool = {
connector.onError(errorHandler);

connector.connect(function(error, response){
if (error){
logError('NodeMCU-Tool', 'Unable to establish connection');
return;
}

logStatus('NodeMCU-Tool', 'Connected');
logStatus('NodeMCU', response);
logStatus('NodeMCU-Tool', 'Uploading "' + localFile + '" ...');
Expand Down Expand Up @@ -137,6 +147,11 @@ var Tool = {
connector.onError(errorHandler);

connector.connect(function(error, response){
if (error){
logError('NodeMCU-Tool', 'Unable to establish connection');
return;
}

logStatus('NodeMCU-Tool', 'Connected');
logStatus('NodeMCU', response);

Expand Down Expand Up @@ -166,6 +181,11 @@ var Tool = {
connector.onError(errorHandler);

connector.connect(function(error, response){
if (error){
logError('NodeMCU-Tool', 'Unable to establish connection');
return;
}

logStatus('NodeMCU-Tool', 'Connected');
logStatus('NodeMCU', response);

Expand All @@ -192,6 +212,11 @@ var Tool = {
connector.onError(errorHandler);

connector.connect(function(error, response){
if (error){
logError('NodeMCU-Tool', 'Unable to establish connection');
return;
}

logStatus('NodeMCU-Tool', 'Connected');
logStatus('NodeMCU', response);
logStatus('NodeMCU', 'Formatting the file system...this will take around ~30s');
Expand Down
12 changes: 12 additions & 0 deletions lib/NodeMcuConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,16 @@ NodeMcuConnector.prototype.run = function(filename, cb){
}.bind(this));
};

// LOW LEVEL - run a lua command directly
NodeMcuConnector.prototype.executeCommand = function(cmd, cb){
// check connect flag
if (!this.isConnected){
cb('Cannot execute remote file - device offline', null);
return;
}

// run the lua interpreter
this.device.executeCommand(cmd, cb);
};

module.exports = NodeMcuConnector;
2 changes: 1 addition & 1 deletion package.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"author": "Andi Dittrich (http://andidittrich.de)",
"license": "MIT",
"dependencies": {
"cli-progress": "^1.0.1",
"colors": "^1.1.2",
"commander": "^2.9.0",
"progress": "^1.1.8",
"prompt": "^0.2.14",
"serialport": "^2.0.5"
}
Expand Down

0 comments on commit 861667a

Please sign in to comment.