-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.js
47 lines (39 loc) · 1.02 KB
/
request.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
var request = require('request');
var counter = 0;
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/ttyS0", {
baudrate: 9600
});
var json_config = {
"machine_data":"netdb's linkit",
};
serialPort.on("open", function () {
serialPort.on('data', function (data) {
console.log(date);
formData = {
"bugZapperId": "143",
"lng": 120.229160,
"lat": 23.997916,
"cnt": parseInt(data)
}
var url = 'http://52.196.80.43:3000/bugZapper/'
var options = {
method: 'post',
body: formData,
json: true,
url: url
}
request(options, function (err, res, body) {
if (err) {
console.error('error posting json: ', err)
throw err
}
var headers = res.headers
var statusCode = res.statusCode
console.log('headers: ', headers)
console.log('statusCode: ', statusCode)
console.log('body: ', body)
})
// request.post('http://52.196.80.43:3000/bugZapper/', payload);
});
});