Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node no_hardware.js #79

Open
ghost opened this issue Dec 5, 2018 · 9 comments
Open

node no_hardware.js #79

ghost opened this issue Dec 5, 2018 · 9 comments

Comments

@ghost
Copy link

ghost commented Dec 5, 2018

I am getting the error as shown as below
Please guide, the command I ran was

node no_hardware.js

snipper

@jjlytle
Copy link

jjlytle commented Dec 6, 2018

same here update these examples

@ghost
Copy link
Author

ghost commented Dec 6, 2018

Did not get you, I have updated all pulled complete repo. How to sort out this error

@jjlytle
Copy link

jjlytle commented Dec 6, 2018 via email

@ghost
Copy link
Author

ghost commented Dec 6, 2018 via email

@jjlytle
Copy link

jjlytle commented Dec 6, 2018 via email

@jjlytle
Copy link

jjlytle commented Dec 6, 2018 via email

@ghost
Copy link
Author

ghost commented Dec 7, 2018

I am still getting error, please guide.

@ghost
Copy link
Author

ghost commented Dec 7, 2018

iot

Please find attachment with error

@jjlytle
Copy link

jjlytle commented Dec 7, 2018

Besides using this code as your new no_hardware.js also make sure the name of your function is
logTemperatureReading. In the original no_hardware.js it was named impWrite and would never have connected to the logTemeratureReading function the tutorial has you create. you must also install the MongoDB Server side sdk. so run

nom install mongodb-stitch-server-sdk

at the command line.
You must also turn on AnonymousCredential setting in your Stitch app under getting started tab,
as in this code I am using AnonymousCredential instead of an API Key easier to get working for now.
and of course put you where it belongs in the code.

// Set-up the Stitch client
// here is the code besides running. npm install
// also run. npm install mongodb-stitch-server-sdk
// then everything should work as advertised
const {
Stitch,
AnonymousCredential,
} = require('mongodb-stitch-server-sdk');

// Send sample data while within this loop
function generateData(stitchClient) {
// Create a random temperature and humidity data point with
// temp ranging from -20 to 20 °C
const myData = {
"temp" : Math.floor(Math.random() * 20) - 20,
"humid" : Math.floor(Math.random() * 100)
};

// Print to the console
console.log(myData);

// Simulate write to MongoDB every 2 minutes
stitchClient.callFunction("logTemperatureReading", [myData] ).then(
setTimeout(() => generateData(stitchClient), 120000)
);
}

// Use AnonymousCredential to load data
const stitchClient = Stitch.initializeDefaultAppClient('<your-app-id>');

stitchClient.auth.loginWithCredential(new AnonymousCredential())
.then(() => {
generateData(stitchClient);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant