Java example: How to create a Weather Station using Raspberry Pi and JavaScript

I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo. I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo. I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// This simple example code reads DHT11 sensor values

// connected to Raspberry Pi GPIO pin 4 and sends them as HTTP POST

// to Remion Regatta server.

// Pre-conditions:

// 1.Obtain the Regatta server URL and APIKey from : www.remion.com

// 2.Install latest node for Raspberry PI

// 3.Install BCM2835 library

// 4.Install node-dht-sensor module
var sensor = require('node-dht-sensor');

var request = require('request');

var oldTemperature=0.0;

var oldHumidity=0.0;

var interval=1000; // sensor measurement cycle
function start() {

setTimeout(start, interval); //milliseconds
// Read data from DHT11 sensor in pin 4:

sensor.read(11, 4, function(err, temperature, humidity) {

if (!err) {

if (temperature !== oldTemperature || humidity !== oldHumidity){

//sensor value changed

console.log('temp: ' + temperature.toFixed(1) + '°C, ' + 'humidity: ' + humidity.toFixed(1) + '%');

oldTemperature=temperature;

oldHumidity=humidity;
var options = {

uri: 'https://demo.remion.com/regattaportal/v1/device/data?apikey=52cb0b67-5a10-45da-b9e1-6810e8d2c01c',

method: 'POST',

json: {

"names": ["temperature","humidity"], "valueRows":

[

{"values": [temperature, humidity]}

]

}

};
request(options, function (error, response, body) {

if (!error && response.statusCode == 200) {

console.log('POST OK')

}

else {

console.log(error);

console.log("Status Code: " +response.statusCode);

}});

} else {

// data is not changed - do nothing

}

} // if err
}); // sensor read
} //func start
start();