Author Topic: Node-RED Guidance TinkerForge Bricklets  (Read 3087 times)

rwblinn

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Node-RED Guidance TinkerForge Bricklets
« on: July 16, 2016, 14:17:07 »
Hi,

is there guidance available on how to use the TinkerForge Javascript Bindings in Node-RED.

Have tried to define a simple call to an ambilight bricklet in a Node-RED function, but received error 31=timeout.
Code: [Select]
//var Tinkerforge = require('/usr/lib/node_modules/tinkerforge');
var Tinkerforge = context.global.tinkerforge;
var HOST = '192.168.0.88';
var PORT = 4223;
var UID = 'mdh';
var ipcon = new Tinkerforge.IPConnection();
var al = new Tinkerforge.BrickletAmbientLight(UID, ipcon);
ipcon.connect(HOST, PORT,
    function (error) {
        node.warn('Connect Error: ' + error);
    }
);
ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED,
    function (connectReason) {
        al.getIlluminance(
            function (illuminance) {
                msg.payload = "{\"Illuminance\":" + illuminance/10.0 + "}";
                node.warn('Illuminance: ' + illuminance/10.0 + ' Lux');
            },
            function (error) {
                msg.payload = "{\"lluminance\":" + error + "}";
                node.warn('Get Error: ' + error);
            }
        );
    }
);
ipcon.disconnect();
return msg;
Note: defined in node-red settings, after installing tinkerforge via npm:
Code: [Select]
    functionGlobalContext: {
    tinkerforge:require('/usr/lib/node_modules/tinkerforge')

rwblinn

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
[SOLVED] Node-RED Guidance TinkerForge Bricklets
« Reply #1 on: July 18, 2016, 16:18:19 »
Solved by using the MQTT proxy as broker on localhost:1883.
Defined a simple test flow with:
  • Input Node "MQTT In" subscribing to topic "tinkerforge/bricklet/ambient_light/mdh/illuminance"
  • Function Node JSON to convert MQTT string to javascript object
  • Function Node Function to log the payload properties illuminance and _timestamp
  • Debug Node to log the MQTT payload (which is a JSON string)

Looks promising to explore further integration of TinkerForge in Node-RED.
« Last Edit: July 18, 2016, 16:19:52 by rwblinn »

hardillb

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Node-RED Guidance TinkerForge Bricklets
« Reply #2 on: July 25, 2016, 12:16:33 »
I've been working on some Node-RED Tinkerforge nodes

Feel free to kick the tires

https://github.com/hardillb/node-red-contrib-tinkerforge

All feedback welcome.

P.S. A guess about the error you had will be that you probably need a use the v2 Ambient Light Object if you have a v2 bricklet
« Last Edit: July 25, 2016, 12:19:57 by hardillb »

rwblinn

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Node-RED Guidance TinkerForge Bricklets
« Reply #3 on: July 25, 2016, 15:57:33 »
Great and Thanks a lot.

Could you pls advice how to install in Node-RED?
Tried npm install node-red-contrib-tinkerforge, but npm can not find the package.

rwblinn

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Node-RED Guidance TinkerForge Bricklets
« Reply #4 on: July 25, 2016, 17:02:28 »
UPDATE
Installed:
$sudo npm install -g tinkerforge
Added to NODE_PATH:
$export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules
Installed:
$npm install body-parser in the .node-red folder under node_modules
Created folder:
/home/pi/.node-red/node_modules/node-red-contrib-tinkerforge
Copied the lib folder and other files to node-red-contrib-tinkerforge
Started node-red
TinkerForge nodes available

COOL

Added the ambientlight (v1) sensor by amending lib/bricklets.js, tinkerforge.js & tinkerforge.html.

Again Thanks a Lot = Job Well Done

hardillb

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Node-RED Guidance TinkerForge Bricklets
« Reply #5 on: July 25, 2016, 17:08:53 »
It's not been packaged for npm just yet

but you can npm install direct from github with the following:

npm install hardillb/node-red-contrib-tinkerforge

If you run this in /home/pi/.node-red it will end up in the right place

I have only done a Ambient light v2.0 node as that's the only hardware I have available to test. But it should be pretty simple do v1.0 node if somebody can let me know the deviceIdentifier.

rwblinn

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Node-RED Guidance TinkerForge Bricklets
« Reply #6 on: July 25, 2016, 19:15:22 »
Thanks

Have added AmbientLight and UVLight (see attachement). Working fine.

The TF device identifies can be found www.tinkerforge.com/en/doc/Software/Device_Identifier.html.

Next: New LED Bricklet with ability to set the color = will use the LED strip as example.

20160725: Correction to AmbientLight (see attachment)
« Last Edit: July 26, 2016, 16:06:17 by rwblinn »

hardillb

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Node-RED Guidance TinkerForge Bricklets
« Reply #7 on: July 27, 2016, 10:47:35 »
Thanks for the link to the device identifiers.

Rather than posting zips of code changes here, a pull request on github would be great so we can track the changes.

Thanks

mtoko

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Node-RED Guidance TinkerForge Bricklets
« Reply #8 on: November 19, 2016, 15:05:36 »
I have brickd running on a Pi with a Master Brick and Analogue Out v2 connect on port D connected by USB. I am trying to control from Node Red and have installed node-red-contrib-tinkerforge. Brickviewer on the Pi can detect the master and analogue bricklet and can adjust the output correctly, so brickd seems to be working. Node red Analogue out node detects the Analogue node id correctly but does not change the output. The config is localhost:4223 which is the same as Brickviewer on the Pi. Any suggestions would be appreciated

RicaIii

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Node-RED Guidance TinkerForge Bricklets
« Reply #9 on: January 18, 2017, 17:25:42 »
Hi...i am a new user here. I think you can npm install direct from github with the following:npm install hardillb/node-red-contrib-tinkerforge
If you run this in /home/pi/.node-red it will end up in the right place.I have only done a Ambient light v2.0 node as that's the only hardware I have available to test. But it should be pretty simple do v1.0 node if somebody can let me know the device Identifier.

printed circuit board assembly
« Last Edit: February 14, 2017, 22:13:40 by RicaIii »