Examples for Galileo/node.js workshop at Senzations 2014
jpwright / senzations14-galileo-nodejs Goto Github PK
View Code? Open in Web Editor NEWExamples for Galileo/node.js workshop at Senzations 2014
Examples for Galileo/node.js workshop at Senzations 2014
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??
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.