2016-07-25 7 views
0

"npm install"と "npm start"の実行後、私はlocalhostで私のWEPAPを起動するとerrormessageを受け取ります。私はWindows 10でPowershellを使ってコマンドを実行します。ここで "npm start"を起動し、localhostでwebappを実行した後、https dosn't workでデータを要求します。

"NPMインストール" 後の出力:

var express = require('express'); 
var path = require('path'); 
var favicon = require('serve-favicon'); 
var logger = require('morgan'); 
var cookieParser = require('cookie-parser'); 
var bodyParser = require('body-parser'); 

var routes = require('./routes/index'); 
var users = require('./routes/users'); 

var app = express(); 
var request = require('request'); 
/* url */ 
var humidity_url = "https://iot.seeed.cc/v1/node/GroveTempHumD0/humidity?access_token=xxx"; 

var temperature_url = "https://iot.seeed.cc/v1/node/GroveTempHumD0/temperature?access_token=xxx"; 

var light_url = "https://iot.seeed.cc/v1/node/GenericAInA0/analog?access_token=xxx"; 

var moisture_url = "https://iot.seeed.cc/v1/node/GroveBaroBMP085I2C0/pressure?access_token=xxx"; 

var quality_url = "https://iot.seeed.cc/v1/node/GroveBaroBMP085I2C0/altitude?access_token=xxx"; 

//var humidity_url = "https://120.25.216.117/v1/node/GroveTempHum/humidity?access_token=6b53bce4b8c63c886f4449efa782e232"; 

//var temperature_url = "https://120.25.216.117/v1/node/GroveTempHum/temperature?access_token=6b53bce4b8c63c886f4449efa782e232"; 

//var light_url = "https://120.25.216.117/v1/node/GroveDigitalLight/lux?access_token=6b53bce4b8c63c886f4449efa782e232"; 

//var moisture_url = "https://cn.iot.seeed.cc/v1/node/GroveMoisture/moisture?access_token=bf162002b220b9d45028bb0053b4a17f"; 

//var quality_url = "https://120.25.216.117/v1/node/GroveAirquality/quality?access_token=6b53bce4b8c63c886f4449efa782e232"; 

app.io = require('socket.io')(); 

app.io.on('connection', function(socket){ 
    console.log('a user connected'); 
    var humidity_data ; 
    update_humidity_data = function(){ 
     request({method: 'GET', 
       url:humidity_url, 
       json: true, 
       strictSSL: false, 
       rejectUnhauthorized : false 
       }, function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
     //var info = JSON.parse(body) 
      humidity_data = body.msg.humidity 
     console.log(body.msg.humidity) 
     socket.emit('humidity_data',humidity_data); 
     //console.log(info) 
     }else 
      console.log(error) 
    }) 
    } 

    update_temperature_data = function(){ 
     request({method: 'GET', 
       url:temperature_url, 
       json: true, 
       strictSSL: false, 
       rejectUnhauthorized : false 
       }, function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
     //var info = JSON.parse(body) 
      temperature_data = body.msg.temperature 
     console.log(body.msg.temperature) 
     socket.emit('temperature_data',temperature_data); 
     //console.log(info) 
     }else 
      console.log(error) 
    }) 
    } 

    update_moisture_data = function(){ 
     request({method: 'GET', 
       url:moisture_url, 
       json: true, 
       strictSSL: false, 
       rejectUnhauthorized : false 
       }, function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
     //var info = JSON.parse(body) 
      moisture_data = body.msg.moisture; 
     console.log(body.msg.moisture); 
     socket.emit('moisture_data',moisture_data); 
     //console.log(info) 
     }else 
      console.log(error) 
    }) 
    } 

    update_light_data = function(){ 
     request({method: 'GET', 
       url:light_url, 
       json: true, 
       strictSSL: false, 
       rejectUnhauthorized : false 
       }, function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
     //var info = JSON.parse(body) 
      light_data = body.msg.lux; 
     console.log(body.msg.lux) 
     socket.emit('light_data',light_data); 
     //console.log(info) 
     }else 
      console.log(error) 
    }) 
    } 

    update_quality_data = function(){ 
     request({method: 'GET', 
       url:quality_url, 
       json: true, 
       strictSSL: false, 
       rejectUnhauthorized : false 
       }, function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
     //var info = JSON.parse(body) 
      quality_data = body.msg.quality; 
     console.log(body.msg.temperature); 
     socket.emit('quality_data',quality_data); 
     //console.log(info) 
     }else 
      console.log(error) 
    }) 
    } 

    update_date =function(){ 
     update_humidity_data(); 
     update_temperature_data(); 
     update_light_data(); 
     update_moisture_data(); 
     update_quality_data(); 
    } 

    setInterval(update_date,2000); 
    // setInterval(update_humidity_data,1000); 
    // setInterval(update_temperature_data,1500); 
    // setInterval(update_moisture_data,1000); 
    // setInterval(update_light_data,2000); 
    // setInterval(update_quality_data,2500); 
    socket.on('chat message', function(msg){ 
    console.log('message: ' + msg); 
    }); 
}); 

var ejs=require('ejs');//新增 
//添加以下 
app.engine('.html',ejs.__express); 
app.set('views', path.join(__dirname, 'views')); 
app.set('view engine', 'html'); 




// view engine setup 

//app.set('view engine', 'jade'); 

// uncomment after placing your favicon in /public 
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); 
app.use(logger('dev')); 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({ extended: false })); 
app.use(cookieParser()); 
app.use(express.static(path.join(__dirname, 'public'))); 

app.use('/', routes); 
app.use('/users', users); 

// catch 404 and forward to error handler 
app.use(function(req, res, next) { 
    var err = new Error('Not Found'); 
    err.status = 404; 
    next(err); 
}); 

// error handlers 

// development error handler 
// will print stacktrace 
if (app.get('env') === 'development') { 
    app.use(function(err, req, res, next) { 
    res.status(err.status || 500); 
    res.render('error', { 
     message: err.message, 
     error: err 
    }); 
    }); 
} 

// production error handler 
// no stacktraces leaked to user 
app.use(function(err, req, res, next) { 
    res.status(err.status || 500); 
    res.render('error', { 
    message: err.message, 
    error: {} 
    }); 
}); 


module.exports = app; 

C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo [master ≡ +1 ~1 -0 !]> npm install 
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade 
npm WARN deprecated [email protected]: Deprecated, use jstransformer 
npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130 

[email protected] install C:\Users\Antonio\Documents\GitHub\IoTWebAPP>\IoTWebDemo\node_modules\bufferutil 
node-gyp rebuild 


C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\bufferutil>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild) else (node "" rebuild) 
Die Projekte in dieser Projektmappe werden nacheinander erstellt. Um eine parallele Erstellung zu ermöglichen, müssen Sie den Schalter "/m" hinzufügen. 
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\x64\PlatformToolsets\v140\Toolset.targets(36,5): error 
MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK vers 
ion in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Users\Antoni 
o\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\bufferutil\build\bufferutil.vcxproj] 
gyp ERR! build error 
gyp ERR! stack Error: `msbuild` failed with exit code: 1 
gyp ERR! stack  at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23) 
gyp ERR! stack  at emitTwo (events.js:106:13) 
gyp ERR! stack  at ChildProcess.emit (events.js:191:7) 
gyp ERR! stack  at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12) 
gyp ERR! System Windows_NT 10.0.10586 
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" 
gyp ERR! cwd C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\bufferutil 
gyp ERR! node -v v6.3.0 
gyp ERR! node-gyp -v v3.3.1 
gyp ERR! not ok 
npm WARN install:[email protected] [email protected] install: `node-gyp rebuild` 
npm WARN install:[email protected] Exit status 1 

[email protected] install C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\utf-8-validate 
node-gyp rebuild 


C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\utf-8-validate>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild) else (node "" rebuild) 
Die Projekte in dieser Projektmappe werden nacheinander erstellt. Um eine parallele Erstellung zu ermöglichen, müssen Sie den Schalter "/m" hinzufügen. 
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\x64\PlatformToolsets\v140\Toolset.targets(36,5): error 
MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK vers 
ion in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Users\Antoni 
o\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\utf-8-validate\build\validation.vcxproj] 

gyp ERR! build error 
gyp ERR! stack Error: `msbuild` failed with exit code: 1 
gyp ERR! stack  at ChildProcess.onExit (C:\Program Files\nodejs 

\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23) 
gyp ERR! stack  at emitTwo (events.js:106:13) 
gyp ERR! stack  at ChildProcess.emit (events.js:191:7) 
gyp ERR! stack  at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12) 
gyp ERR! System Windows_NT 10.0.10586 
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" 
gyp ERR! cwd C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\utf-8-validate 
gyp ERR! node -v v6.3.0 
gyp ERR! node-gyp -v v3.3.1 
gyp ERR! not ok 
npm WARN install:[email protected] [email protected] install: `node-gyp rebuild` 
npm WARN install:[email protected] Exit status 1 
[email protected] C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo 
+-- [email protected] 
| +-- [email protected] 
| +-- [email protected] 
| +-- [email protected] 
| +-- [email protected] 
| | +-- [email protected] 
| | `-- [email protected] 
| +-- [email protected] 
| +-- [email protected] 
| | `-- [email protected] 
. 
. 
. 
    +-- [email protected] 
    | `-- [email protected] 
    +-- [email protected] 
    | +-- [email protected] 
    | | `-- [email protected] 
    | +-- [email protected] 
    | `-- [email protected] 
    | +-- [email protected] 
    | `-- [email protected] 
    +-- [email protected] 
    | +-- [email protected] 
    | +-- [email protected] 
    | +-- [email protected] 
    | +-- [email protected] 
    | +-- [email protected] 
    | | +-- [email protected] 
    | | +-- [email protected] 
    | | | `-- [email protected] 
    | | +-- [email protected] 
    | | | `-- [email protected] 
    | | +-- [email protected] 
    | | +-- [email protected] 
    | | +-- [email protected] 
    | | `-- [email protected] 
    | +-- [email protected] 
    | | `-- [email protected] 
    | +-- [email protected] 
    | +-- [email protected] 
    | +-- [email protected] 
    | | `-- [email protected] 
    | | `-- [email protected] 
    | `-- [email protected] 
    `-- [email protected] 
    +-- [email protected] 
    +-- [email protected] 
    +-- [email protected] 
    `-- [email protected] 
C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo [master ≡ +1 ~1 -0 !]> 

はlocalhostで "NPM開始" と始まるのwebappここ

C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo [master ≡ +2 ~1 -0 !]> npm start 

[email protected] start C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo 
node ./bin/www 

a user connected 
C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\app.js:48 
         humidity_data = body.msg.humidity 
               ^

TypeError: Cannot read property 'humidity' of undefined 
    at Request._callback (C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\app.js:48:28) 
    at Request.self.callback (C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\request\request.js:198:22) 
    at emitTwo (events.js:106:13) 
    at Request.emit (events.js:191:7) 
    at Request.<anonymous> (C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\request\request.js:1082:10) 
    at emitOne (events.js:101:20) 
    at Request.emit (events.js:188:7) 
    at IncomingMessage.<anonymous> (C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\node_modules\request\request.js:1009:12) 
    at emitNone (events.js:91:20) 
    at IncomingMessage.emit (events.js:185:7) 

npm ERR! Windows_NT 10.0.10586 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" 
npm ERR! node v6.3.0 
npm ERR! npm v3.10.3 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] start: `node ./bin/www` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node ./bin/www'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the aws package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node ./bin/www 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs aws 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls aws 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo\npm-debug.log 
C:\Users\Antonio\Documents\GitHub\IoTWebAPP\IoTWebDemo [master ≡ +2 ~1 -0 !]> 

app.jsファイルの後に

提案がありますか?

おかげ

+0

'body'オブジェクトに' msg'プロパティはありませんか? app.jsを投稿できますか?あるいは少なくとも関連する部分は、 'body'をどのように初期化しているかのようですか?また、アプリに送信しているリクエストがどのようなものかを示すものが役に立つかもしれません。 – Will

+0

'console.dir(body)'は 'update_humidity_data()'の 'request()'コールバックの中で何を出力しますか? 'response.headers'には何がありますか?おそらく 'response.headers ['content-type']!== 'application/json''ですか? – mscdex

+0

これはかなり簡単です。 'body'に' msg'フィールドはありません。 –

答えて

0

API documentationによるAPIサーバから返される結果にはmsgプロパティがありません。要求された値は返されたオブジェクトに直接添付されます(例:{ temp: 30 })。

+0

これでうまくいきます。私は "humidity_data = body.humidity;"を変更しました。 and "temperature_data = body.celsius_degree;"となります。ありがとうございます... – oxid2178

関連する問題