-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
64 lines (48 loc) · 2.37 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*jslint node:true,vars:true,bitwise:true,unparam:true */
/*jshint unused:true */
/*
The Local Temperature Node.js sample application distributed within Intel® XDK IoT Edition under the IoT with Node.js Projects project creation option showcases how to read analog data from a Grover Starter Kit Plus – IoT Intel® Edition Temperature Sensor, start a web server and communicate wirelessly using WebSockets.
MRAA - Low Level Skeleton Library for Communication on GNU/Linux platforms
Library in C/C++ to interface with Galileo & other Intel platforms, in a structured and sane API with port nanmes/numbering that match boards & with bindings to javascript & python.
Steps for installing MRAA & UPM Library on Intel IoT Platform with IoTDevKit Linux* image
Using a ssh client:
1. echo "src maa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/intel-iotdk.conf
2. opkg update
3. opkg upgrade
Article: https://software.intel.com/en-us/html5/articles/iot-local-temperature-nodejs-and-html5-samples
*/
var B = 3975;
var mraa = require("mraa");
var coap = require('coap');
//GROVE Kit A0 Connector --> Aio(0)
var myAnalogPin = new mraa.Aio(0);
/*
Function: startSensorWatch(socket)
Parameters: socket - client communication channel
Description: Read Temperature Sensor and send temperature in degrees of Fahrenheit every 4 seconds
*/
var startSensorWatch = function() {
'use strict';
setInterval(function () {
var data;
//connect to CoAP server
var coapWriable = coap.request('coap://192.168.0.100:8000/object/testman/send');
var a = myAnalogPin.read();
console.log("Analog Pin (A0) Output: " + a);
//console.log("Checking....");
var resistance = (1023 - a) * 10000 / a; //get the resistance of the sensor;
//console.log("Resistance: "+resistance);
var celsius_temperature = 1 / (Math.log(resistance / 10000) / B + 1 / 298.15) - 273.15;//convert to temperature via datasheet ;
//console.log("Celsius Temperature "+celsius_temperature);
var fahrenheit_temperature = (celsius_temperature * (9 / 5)) + 32;
var obj = {
temperature: fahrenheit_temperature
};
data = JSON.stringify(obj);
console.log("Sending: " + data);
//send to COAP broker
coapWriable.end(new Buffer(data));
}, 4000);
}
console.log("Sample Reading Grove Kit Temperature Sensor");
startSensorWatch();