Example of Meteor interacting with photon using particle-api-js

I’m working on a project that uses Meteor js to subscribe to Particle events and send commands to my Photon. With the migration from sparkjs to particle-api-js and its use of promises, I’ve found myself at a standstill.

I’ve reviewed a couple tutorials on Meteor and promises, but I can’t figure out how to apply it to the updated api. Any help would be greatly appreciated.

Thanks,

Total newbie on Meteor myself. Would also love to see anyone’s integration with Meteor and Particle with the updated api.

There’s a thread on the Meteor forums that someone posted a few links to github projects using the current api. I looked through them, but wasn’t able to glean what I was looking for. Maybe you’ll have better luck: https://forums.meteor.com/t/need-some-help-importing-npm-beginner/19775/10

I am new aswell and struggling, i posted those link on meteor forum. If you are able to get à good example to work please post easy example for us or make à tutorial :slight_smile:

I Will do the same but im stuck with this error when i try the login Issues with Wildcard and particle-api-js

Please IF you guys encounter the same, post in the Thread your code and issue. Remember to use chrome since ie and firefox shows an other error with bad explanation

Br
Dimi

Yes - just now, all of a sudden, getting similar errors while using Meteor. Code is server-side… any resolution you’ve found?

Hello phillytep.

My resolution was to use this code on the server side.

    var Particle = require('particle-api-js');
    var particle = new Particle();
    
    particle.login({username: 'email@example.com', password: 'pass'}).then(
      function(data){
        console.log('API call completed on promise resolve: ', data.body.access_token);
      },
      function(err) {
        console.log('API call completed on promise fail: ', err);
      }
    ); 

Are you using 1.3?, try by creating a new project in 1.3 and put the code in a js file under the server folder and test.
Thats whats eventually made it work for me. The load order is pretty important in meteor. Since im a beginner as well i cant really explain it for you, but as a start you can make and modify the example that meteor has on their site to fit your need.

You also need to import some stuff, the boilerplate is not needed but it helps make the app looks good with little effort.
and i used it to study what other people do with their code.

npm install particle-api-js
git copy materalize boilerplate (https://github.com/Differential/meteor-boilerplate/tree/materialize)
meteor add module 
npm install -g meteor-npm // to make command "require" work 

Hope it helps.
Br
Dimi

1 Like

I have a problem inserting variables into a Mongo collection. Do you know what my mistake(s) is?

Server.jsx

Meteor.startup(function() {

    console.log('SERVER STARTUP.JSX - Logging in Particle Cloud');
    let deviceName = {};
    let device_id = {};
    let cell = {};
    let allDevices = {};

    particle = new Particle();

    particle.login({username: Meteor.settings.private.username, password: Meteor.settings.private.password}).then(
        function(data){
            console.log('API call completed on promise resolve: ', data.body.access_token);
            let token = data.body.access_token;
            let devicesList = particle.listDevices({ auth: token });
            devicesList.then(
                function(devices){

                    allDevices = devices["body"];
                    
                    _.each(allDevices, function(device) {
                        deviceName = device.name;
                        device_id = device.id;
                        cell = device.cellular;

                        ParticleDevicesData.insert({
                            name: deviceName,
                            id: device_id,
                            cellular: cell
                        });
                    });
                }
            );
            particleGetAllMyEventStreams();
        },
        function(err) {
            console.log('API call completed on promise fail: ', err);
        }
    );
});

Hello there, Sorry i have been away for a while.
My coding skill is very bad so i cant really Help.

A tip would be to check for other peoples code on github. That was what i did.

BR
Dimi

I fixed it. Thanks anyway:)