node-red-contrib-i2c
Advanced tools
Comparing version 0.5.2 to 0.6.0
@@ -15,3 +15,3 @@ module.exports = function(RED) { | ||
if (err) { | ||
node.error(errI); | ||
node.error(err); | ||
} else { | ||
@@ -49,46 +49,68 @@ | ||
node.on("input", function(msg) { | ||
var address = node.address || msg.address ; | ||
var command = node.command || msg.command ; | ||
address = parseInt(address); | ||
command = parseInt(command); | ||
var buffcount = parseInt(node.count); | ||
if (isNaN(address)) { | ||
this.status({fill:"red",shape:"ring",text:"Address ("+address+") value is missing or incorrect"}); | ||
return; | ||
} else if (isNaN(command) ) { | ||
this.status({fill:"red",shape:"ring",text:"Command value is missing or incorrect"}); | ||
return; | ||
} else if ((!buffcount) || isNaN(buffcount) ) { | ||
this.status({fill:"red",shape:"ring",text:"Read bytes value is missing or incorrect"}); | ||
return; | ||
} else { | ||
this.status({}); | ||
} | ||
var buffer = new Buffer(buffcount); | ||
node.port.readI2cBlock(address, command, buffcount, buffer, function(err, size, res) { | ||
if (err) { | ||
node.error(err); | ||
} else { | ||
var payload; | ||
if (node.count == 1) { | ||
payload = res[0]; | ||
} else { | ||
payload = res; | ||
} | ||
msg = Object.assign({}, msg); | ||
// node.log('log returned data'+ JSON.stringify([size, res.length, res, res.toString("utf-8")])); | ||
msg.address = address; | ||
msg.command = command; | ||
msg.payload = payload; | ||
msg.size = size; | ||
node.send(msg); | ||
} | ||
}); | ||
}); | ||
var address = node.address || msg.address ; | ||
var command = node.command || msg.command ; | ||
address = parseInt(address); | ||
command = parseInt(command); | ||
var buffcount = parseInt(node.count); | ||
if (isNaN(address)) { | ||
this.status({fill:"red",shape:"ring",text:"Address ("+address+") value is missing or incorrect"}); | ||
return; | ||
} else if ((!buffcount) || isNaN(buffcount) ) { | ||
this.status({fill:"red",shape:"ring",text:"Read bytes value is missing or incorrect"}); | ||
return; | ||
} else { | ||
this.status({}); | ||
} | ||
node.on("close", function() { | ||
node.port.closeSync(); | ||
}); | ||
var buffer = new Buffer(buffcount); | ||
if(isNaN(command)) { | ||
node.port.i2cRead(address, buffcount, buffer, function(err, size, res) { | ||
/* Bloc for read without command like pcf8574A and pcf8574 */ | ||
if (err) { | ||
node.error(err, msg); | ||
} else { | ||
var payload; | ||
if (node.count == 1) { | ||
payload = res[0]; | ||
} else { | ||
payload = res; | ||
} | ||
msg = Object.assign({}, msg); | ||
// node.log('log returned data'+ JSON.stringify([size, res.length, res, res.toString("utf-8")])); | ||
msg.address = address; | ||
msg.command = command; | ||
msg.payload = payload; | ||
msg.size = size; | ||
node.send(msg); | ||
} | ||
}); | ||
} else { | ||
node.port.readI2cBlock(address, command, buffcount, buffer, function(err, size, res) { | ||
/* Block for read with command */ | ||
if (err) { | ||
node.error(err); | ||
} else { | ||
var payload; | ||
if (node.count == 1) { | ||
payload = res[0]; | ||
} else { | ||
payload = res; | ||
} | ||
msg = Object.assign({}, msg); | ||
// node.log('log returned data'+ JSON.stringify([size, res.length, res, res.toString("utf-8")])); | ||
msg.address = address; | ||
msg.command = command; | ||
msg.payload = payload; | ||
msg.size = size; | ||
node.send(msg); | ||
} | ||
}); | ||
} | ||
}); | ||
node.on("close", function() { | ||
node.port.closeSync(); | ||
}); | ||
} | ||
RED.nodes.registerType("i2c in", I2CInNode); | ||
@@ -180,2 +202,2 @@ | ||
RED.nodes.registerType("i2c out", I2COutNode); | ||
} | ||
} |
{ | ||
"_from": "node-red-contrib-i2c@0.1.0", | ||
"_id": "node-red-contrib-i2c@0.1.0", | ||
"_inBundle": false, | ||
"_integrity": "sha1-+7Pu3cdlcOQ+h3xrAlkQXBw0Wk8=", | ||
"_location": "/node-red-contrib-i2c", | ||
"_phantomChildren": {}, | ||
"_requested": { | ||
"type": "version", | ||
"registry": true, | ||
"raw": "node-red-contrib-i2c@0.1.0", | ||
"name": "node-red-contrib-i2c", | ||
"escapedName": "node-red-contrib-i2c", | ||
"rawSpec": "0.1.0", | ||
"saveSpec": null, | ||
"fetchSpec": "0.1.0" | ||
"name": "node-red-contrib-i2c", | ||
"version": "0.6.0", | ||
"description": "A Node-RED node to talk to the Raspiberry PI's I2C port", | ||
"dependencies": { | ||
"i2c-bus": "^5.2.0" | ||
}, | ||
"_requiredBy": [ | ||
"#USER", | ||
"/" | ||
], | ||
"_resolved": "https://registry.npmjs.org/node-red-contrib-i2c/-/node-red-contrib-i2c-0.1.0.tgz", | ||
"_shasum": "fbb3eeddc76570e43e877c6b0259105c1c345a4f", | ||
"_spec": "node-red-contrib-i2c@0.1.0", | ||
"_where": "/home/pi/.node-red", | ||
"author": { | ||
"name": "Niels v.d. Spek", | ||
"email": "nielsnl68@gmail.com", | ||
"url": "https://github.com/nielsnl68/node-contrib-i2c" | ||
"main": "26-i2c.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"bundleDependencies": false, | ||
"dependencies": { | ||
"i2c-bus": "^1.2.2" | ||
}, | ||
"deprecated": false, | ||
"description": "A Node-RED node to talk to the Raspiberry PI's I2C port", | ||
"homepage": "https://github.com/nielsnl68/node-red-contrib-i2c#readme", | ||
"license": "Apache-2.0", | ||
"keywords": [ | ||
@@ -43,5 +18,6 @@ "node-red", | ||
], | ||
"license": "Apache-2.0", | ||
"main": "26-i2c.js", | ||
"name": "node-red-contrib-i2c", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/nielsnl68/node-red-contrib-i2c" | ||
}, | ||
"node-red": { | ||
@@ -52,10 +28,11 @@ "nodes": { | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/nielsnl68/node-red-contrib-i2c.git" | ||
"author": { | ||
"name": "Niels v.d. Spek", | ||
"email": "nielsnl68@gmail.com", | ||
"url": "https://github.com/nielsnl68/node-red-contrib-i2c" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"version": "0.5.2" | ||
"readmeFilename": "README.md", | ||
"bugs": { | ||
"url": "" | ||
} | ||
} |
# node-red-contrib-i2c | ||
This set of node-red nodes communicate with the Raspberry Pi I2C driver and uses the node-I2C package. | ||
@@ -12,32 +13,49 @@ Run the following command in the root directory of your Node-RED install, usually | ||
## Install | ||
Either use the Manage Palette option in the Node-RED Editor menu, or run the following command in your Node-RED user directory - typically `~/.node-red` | ||
npm install --unsafe-perm node-red-contrib-i2c | ||
Usage | ||
----- | ||
## Usage | ||
Provides three nodes - one to scan connected device, one to receive messages, and one to send. | ||
#### Configuration | ||
When you start using on of the below nodes you need first to configurate the I2C Device. | ||
The Raspberry PI uses an special device name to connect to the I2C controller. Depending on the Raspberry PI version it can be one of the below values; for the RPi Rev 1 it <i>/dev/i2c-0</i> and all Others it will be <i>/dev/i2c-1</i> (=default). In the config screen you can also set the default I2C-address to where the node sends the Messages and request's to. | ||
### Configuration | ||
When you start using one of the below nodes you need first to configure the I2C Device. | ||
The Raspberry PI uses an special device name to connect to the I2C controller. | ||
Depending on the Raspberry PI version it can be one of the below values; for the RPi Rev 1 it <i>/dev/i2c-0</i> and all Others it will be <i>/dev/i2c-1</i> (=default). | ||
In the config screen you can also set the default I2C-address to where the node sends the Messages and requests. | ||
### Scan I2C | ||
This will scan the I2C bus for connected devices and has one in point to trigger the scan process and 2 out put points: | ||
- The first output point give a list of all found decives in <b>msg.payload</b> and will be triggered once. | ||
- The second output point will be triggered for every found device the address will be in <b>msg.payload</b> | ||
### Input I2C | ||
This node will request data from a given device. The address and command can both be set in the dialog screen or dynamicly with <b>msg.address</b> and <b>msg.command</b>. This node outputs the result as a buffer in <b>msg.payload</b> and places the address in <b>msg.address</b> and command in <b>msg.command</b>. | ||
This will scan the I2C bus for connected devices. | ||
It has one input to trigger the scan process and 2 outputs: | ||
- The first output gives a list of all found devices in <b>msg.payload</b> and will be triggered once. | ||
- The second output will be triggered for every found device. The address will be in <b>msg.payload</b> | ||
### Input I2C | ||
This node will request data from a given device. | ||
The address and command can both be set in the dialog screen or dynamically with <b>msg.address</b> and <b>msg.command</b>. | ||
This node outputs the result as a buffer in <b>msg.payload</b> and places the address in <b>msg.address</b> and command in <b>msg.command</b>. | ||
### Output I2C | ||
This node will send a given String/array/buffer to a given device. The address and command can both be set in the dialog screen or dynamicly with <b>msg.address</b> and <b>msg.command</b>. | ||
The payload can be staticly or dynamicly (using msg.payload) set. This payload can be a Buffer, Array, String or Integer. When you use integers then the number of bytes to send is importend and can be set between 0 and 31 bytes. | ||
This node will send a given String/array/buffer to a given device. | ||
The address and command can both be set in the dialog screen or dynamically with <b>msg.address</b> and <b>msg.command</b>. | ||
The payload can be set statically or dynamically (using msg.payload). | ||
This payload can be a Buffer, Array, String or Integer. | ||
When you use integers the number of bytes to send is important and can be set between 0 and 31 bytes. | ||
NEW(0.5.0): you can daisychain this node, the input msg is send unchanged to the next node. | ||
### Important Note | ||
#### Inportend Note | ||
Version v0.5.0 is now using the I2C-bus package from fivdi. It looks more robust and better for asyncrone processes like node-red. I would like the maker as much thanks for his work as Kelly in the past version. You can vind his work on github: https://github.com/fivdi/i2c-bus | ||
Versions v0.5.0 onward are now using the I2C-bus package from @fivdi. It looks more robust and better for asyncrone processes like node-red. I would like the maker as much thanks for his work as Kelly in the past version. You can vind his work on github: https://github.com/fivdi/i2c-bus | ||
old version did use the work of kelly's I2C package to work. And i like to thank hem for the work he did on that package. | ||
The Old set of nodes did use the work of kelly's I2C package to work. | ||
And I would like to thank him for the work he did on that package. | ||
For more info check out his github account at: https://github.com/kelly/node-i2c |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
0
100
179
61
27504
3
+ Addedbindings@1.5.0(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedi2c-bus@5.2.3(transitive)
+ Addednan@2.22.0(transitive)
- Removedbindings@1.3.1(transitive)
- Removedi2c-bus@1.2.5(transitive)
- Removednan@2.8.0(transitive)
Updatedi2c-bus@^5.2.0