mountaindude / Node-RED-Telldus-to-MQTT-bridge

Node-RED code to get data from Telldus Live API, then publish the data as MQTT messages
5 stars 2 forks source link

I cannot setup this for the node-red dist "Thethingbox" on a RPi #1

Open tvillingett opened 8 years ago

tvillingett commented 8 years ago

I've tried to add the module in the thethingsbox.js, to get it globally avaible but when I add it the Thethingbox won't start after restarting. Also it installs the npm package, but when it try it in a simple function node with only:

var TelldusAPI = require('telldus-live');
return msg;

the debug window says: ReferenceError: require is not defined (line 1, col 18)

I changed in the thethingbox.js

var http = require('http');
var express = require("express");
var RED = require("node-red");

var settings = require('./settingsttb');

var PORT = 1880;

// Create an Express app
var app = express();

// Add a simple route for static content served from 'public'
app.use("/", express.static("public"));
app.use(express.favicon(__dirname + '/node_modules/node-red/public/favicon.ico')); 

// Create a server
var server = http.createServer(app);

var settings_ttb = settings.loadSettings();
// console.log("Settings TTB:" + JSON.stringify(settings_ttb));

// Create the settings object
var userDir="/root/userdir/";
var flowDir=userDir;
var settings_nodered = { // http://nodered.org/docs/configuration.html
    httpAdminRoot:"/",
    httpNodeRoot: "/api/",
    userDir: userDir,
    flowDir: flowDir, // TTB specific
    flowFile: flowDir + "flows.json",
    verbose: true,
    flowFilePretty: true,
    paletteCategories:['subflows', 'input', 'output', 'function', 'social', 'storage', 'analysis', 'advanced'],
    hiddenWorkspaces: [ ],
    functionGlobalContext: {
        settings: settings_ttb
        ,userDir: userDir
        ,wpi: require('node-red/node_modules/wiring-pi') // https://www.npmjs.com/package/wiring-pi
        ,CryptoJS: require('node-red/node_modules/crypto-js') // https://www.npmjs.com/package/cryptojs
        ,HID: require('node-red/node_modules/node-hid') // https://www.npmjs.com/package/node-hid
        ,TelldusAPI: require('~/thethingbox/node_modules/telldus-live')
    }
};

    // Initialise the runtime with a server and settings
    RED.init(server,settings_nodered);

    // Serve the editor UI from /
    app.use(settings_nodered.httpAdminRoot,RED.httpAdmin);

    // Serve the http nodes UI from /api
    app.use(settings_nodered.httpNodeRoot,RED.httpNode);

    server.listen(PORT);

    //Start the runtime
    RED.start();
MrEngineer1 commented 4 years ago

I am having the same issue. What was the solution?