Giter VIP home page Giter VIP logo

senzations14-galileo-nodejs's Introduction

senzations14-galileo-nodejs

Examples for Galileo/node.js workshop at Senzations 2014

senzations14-galileo-nodejs's People

Contributors

jpwright avatar

Stargazers

Chris Barsolai avatar

Watchers

James Cloos avatar  avatar

Forkers

alignan d1runberg

senzations14-galileo-nodejs's Issues

sensors on galileo

I want to make an opc-ua server on galileo gen 2, with a yocto built version of linux.
I've made, with some help from git, a complete version of that kind of server for raspberry pi 3, but i have some problems with porting it to galileo. I'm using for the server dht11 and ds18b20 sensors, but i can't manage to make it work on galileo.

Here is my code:

var opcua = require("node-opcua");
var w1bus = require("node-w1bus");
var bus = w1bus.create();
var rpiDhtSensor = require("rpi-dht-sensor");

function read_sensor(sensor,callback) {
bus.getValueFrom(sensor)
.then(function(res){ callback(null,res.result); })
.catch(callback);
};

function start_server() {

    var server = new opcua.OPCUAServer({
            port: 1234
    });

    server.buildInfo.productName ="Rapsberry OPCUA Server"

    function post_initialize() {

            var addressSpace = server.engine.addressSpace;
            var devices = addressSpace.addFolder("ObjectsFolder",{ browseName: "Devices"});
            var temperatureSensor = "28-041460c2a3ff";
            install_sensor(temperatureSensor);
    };

    var tempValue = -20.0;
    var tempValue1 = -20.0;
    var humValue = -20.0;

    function install_sensor(sensor) {
            var addressSpace = server.engine.addressSpace;
            var sensorName = "ds18b20";
            var sensorName1 = "dht11";
            var devices = addressSpace.rootFolder.objects.devices;
            var sensor  = addressSpace.addObject({
                    organizedBy: devices,
                    browseName:  sensorName
            });

            var dht = new rpiDhtSensor.DHT11(27);

            setInterval(function() {
                    var temperatureSensor = "28-041460c2a3ff";
                    read_sensor(temperatureSensor,function(err,result) {
                            tempValue = result.value;
                    });
                    var readout = dht.read();
                    tempValue1 = readout.temperature.toFixed(2);
                    humValue = readout.humidity.toFixed(2);
            },3000);

            addressSpace.addVariable({
                    propertyOf: sensor,
                    browseName: "temperature1",
                    dataType:   "Double",
                    value: {
                            get: function () {
                                    return new opcua.Variant({dataType: opcua.DataType.Double, value: tempValue });
                            }
                    }
            });

            addressSpace.addVariable({
                    propertyOf: sensor,
                    browseName: "temperature2",
                    dataType:   "Double",
                    value: {
                            get: function () {
                                    return new opcua.Variant({dataType: opcua.DataType.Double, value: tempValue1 });
                            }
                    }
            });

            addressSpace.addVariable({
                    propertyOf: sensor,
                    browseName: "humidity",
                    dataType: "Double",
                    value: {
                            get: function() {
                                    return new opcua.Variant({dataType: opcua.DataType.Double, value: humValue });
                            }
                    }
            });
    };

    server.initialize(post_initialize);

    server.start(function() {
            console.log("\n\nTemperature - OPCUAServer");
            var endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl;
            console.log("Server endpoint url is ", endpointUrl );
            console.log("\n");
    });

}

start_server();
I'm actually trying to get the values from the sensors...
Some help for making it work on Galileo, please??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.