Hardware Reference
In-Depth Information
Solution
Because your Bone is on the network, it's not hard to access the current weather conditions
from a weather API. First, install a JavaScript module:
bone# npm install -g weather-js (Took about 4 minutes on a slow
connection)
Then add the code in Example 6-9 to a file named weather.js .
Example 6-9. Code for getting current weather conditions (weather.js)
#!/usr/bin/env node
// Install with npm install weather-js
var weather = require ( 'weather-js' );
// Options:
// search: location name or zipcode
// degreeType: F or C
weather . find ({ search : 'Terre Haute, IN' , degreeType : 'F' },
function ( err , result ) {
if ( err ) {
console . log ( err );
}
console . log ( JSON . stringify ( result , null , 2 ));
console . log ( JSON . stringify ( result [ 0 ]. current , null , 2 ));
console . log ( JSON . stringify ( result [ 0 ]. forecast [ 0 ], null , 2 ));
});
Prints everything returned by the weather site.
Prints only the current weather conditions.
Prints the forecast for the next day.
Run this by using the following commands:
 
 
 
 
Search WWH ::




Custom Search