Coder Social home page Coder Social logo

particle-io's Introduction

Particle-io

Build Status

Particle-io is a Firmata-compatibility IO class for writing node programs that interact with Particle devices (formerly Spark). Particle-io was built at Bocoup

Getting Started

In order to use the particle-io library, you will need to load the special voodoospark firmware onto your device. We recommend you review VoodooSpark's Getting Started before continuing. There is also a screencast of how to get started: Get Your Motor Running: Particle Photon and Johnny Five.

We also recommend storing your Particle token and device ID in a dot file so they can be accessed as properties of process.env. Create a file in your home directory called .particlerc that contains:

export PARTICLE_TOKEN="your particle token"
export PARTICLE_DEVICE_ID="your device id"

Then add the following to your dot-rc file of choice:

source ~/.particlerc

Ensure your host computer (where you're running your Node.js application) and the Particle are on the same local network.

Blink an Led

The "Hello World" of microcontroller programming:

var Particle = require("particle-io");
var board = new Particle({
  token: process.env.PARTICLE_TOKEN,
  deviceId: process.env.PARTICLE_DEVICE_ID
});

board.on("ready", function() {
  console.log("Device Ready..");
  this.pinMode("D7", this.MODES.OUTPUT);

  var byte = 0;

  // This will "blink" the on board led
  setInterval(function() {
    this.digitalWrite("D7", (byte ^= 1));
  }.bind(this), 500);
});

Troubleshooting

If your board is connecting, but the board.on("ready", ...) event is not occuring, ensure the wifi network you are connected to allows for direct TCP client/server sockets (this form of communication is often blocked by public wifi networks).

Johnny-Five IO Plugin

Particle-io can be used as an IO Plugin for Johnny-Five:

var five = require("johnny-five");
var Particle = require("particle-io");
var board = new five.Board({
  io: new Particle({
    token: process.env.PARTICLE_TOKEN,
    deviceId: process.env.PARTICLE_DEVICE_ID
  })
});

board.on("ready", function() {
  console.log("Device Ready..");
  var led = new five.Led("D7");
  led.blink();
});

See the above Troubleshooting section if your board is connecting, but the board.on("ready", ...) event is not occuring.

API

Constructor The Particle component can be connected using one of three mechanisms: deviceId, deviceName, or host/port. Both deviceId and deviceName require an additional token so that the host and port of the device can be retrieved from the Particle cloud.

Example:

var Particle = require("particle-io");

var byId = new Particle({
  token: process.env.PARTICLE_TOKEN,
  deviceId: process.env.PARTICLE_DEVICE_ID
});

var byName = new Particle({
  token: process.env.PARTICLE_TOKEN,
  deviceName: process.env.PARTICLE_DEVICE_NAME || "crazy_pickle"
});

var byIp = new Particle({
  host: '192.168.0.111',
  port: 48879
});

device properties You can get the information that the component knows about the chip with some read-only device properties. This is useful for retrieving the IP address of the Particle so that you can swith over to host/port mode if necessary.

The available properties are:

  • deviceId: The ID of the device
  • deviceName: The name of the device
  • deviceIp: The IP address of the device on the local network
  • devicePort: The port the device is listening on for connections

Example:

var Particle = require("particle-io");

var board = new Particle({
  token: process.env.PARTICLE_TOKEN,
  deviceName: process.env.PARTICLE_DEVICE_Name || "crazy_pickle"
});

board.on("ready", function() {
  console.log(
    "Connected to " + board.deviceName + 
    " (" + board.deviceId + ") " +
    "at " + board.deviceIp + ":" + board.devicePort
  );
});

MODES

The MODES property is available as a Particle instance property:

var board = new Particle(...);
board.MODES;
  • INPUT: 0
  • OUTPUT: 1
  • ANALOG: 2
  • PWM: 3
  • SERVO: 4

pinMode(pin, MODE)

Set a pin's mode to any one of the MODES.

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Set digital pin 7 to OUTPUT:
  this.pinMode("D7", this.MODES.OUTPUT);

  // or just use the integer:
  this.pinMode("D7", 1);

});

PWM Support (Servo support is also limited to these pins):

  • Core pins: A0, A1, A4, A5, A6, A7, D0, D1.
  • Photon pins: A4, A5, D0, D1, D2, D3
  • P1 pins: A4, A5, D0, D1, D2, D3

digitalWrite(pin, value)

Sets the pin to 1 or 0, which either connects it to 3.3V (the maximum voltage of the system) or to GND (ground).

Example:

var board = new Particle(...);

board.on("ready", function() {

  // This will turn ON the on-board LED
  this.digitalWrite("D7", 1);

  // OR...

  // This will turn OFF the on-board LED
  this.digitalWrite("D7", 0);

});

analogWrite(pin, value)

Sets the pin to an 8-bit value between 0 and 255, where 0 is the same as LOW and 255 is the same as HIGH. This is sort of like sending a voltage between 0 and 3.3V, but since this is a digital system, it uses a mechanism called Pulse Width Modulation, or PWM. You could use analogWrite to dim an LED, as an example. PWM is available on D0, D1, A0, A1, A4, A5, A6 and A7.

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Set an LED to full brightness
  this.analogWrite("A7", 255);

  // OR...

  // Set an LED to half brightness
  this.analogWrite("A7", 128);

});

servoWrite(pin, value)

Sets the pin to a value between 0 and 180, where the value represents degrees of the servo horn. The value is converted to a PWM signal. PWM is available on D0, D1, A0, A1, A4, A5, A6 and A7.

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Move a servo to 90 degrees
  this.servoWrite("D0", 90);

});

digitalRead(pin, handler) Setup a continuous read handler for specific digital pin (D0-D7).

This will read the digital value of a pin, which can be read as either HIGH or LOW. If you were to connect the pin to a 3.3V source, it would read HIGH (1); if you connect it to GND, it would read LOW (0).

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Log all the readings for D1
  this.digitalRead("D1", function(data) {
    console.log(data);
  });

});

analogRead(pin, handler) Setup a continuous read handler for specific analog pin (A0-A7). Use with all analog sensors

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Log all the readings for A1
  this.analogRead("A1", function(data) {
    console.log(data);
  });

});

License

See LICENSE file.

particle-io's People

Contributors

briangenisio avatar cat-haines avatar deadprogram avatar makenai avatar reconbot avatar remy avatar resseguie avatar rwaldron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

particle-io's Issues

pin.replace is not a function

Hi--

I am running into a similar error issue 1 , issue 2. I am pretty new to this so any guidance is greatly appreciated.

  • Particle Photon Board
  • Shield Shield
  • Johnny Five
  • Particle-io
  • Continous Servo

Here's the script:

Pretty much this example

var five = require("johnny-five");
var Particle = require("particle-io");
var board = new five.Board({
  io: new Particle({
    token: "...",
    deviceId: "..."
  })
});

board.on("ready", function() {

  console.log("Use Up and Down arrows for CW and CCW respectively. Space to stop.");

  var servo = new five.Servo.Continuous(10);

  process.stdin.resume();
  process.stdin.setEncoding("utf8");
  process.stdin.setRawMode(true);

  process.stdin.on("keypress", function(ch, key) {

    if (!key) {
      return;
    }

    if (key.name === "q") {
      console.log("Quitting");
      process.exit();
    } else if (key.name === "up") {
      console.log("CW");
      servo.cw();
    } else if (key.name === "down") {
      console.log("CCW");
      servo.ccw();
    } else if (key.name === "space") {
      console.log("Stopping");
      servo.stop();
    }
  });
});

Here's the error:

1471134659325 Device(s) particle-io  
1471134661721 Connected particle-io  
1471134661821 Repl Initialized  
>> Use Up and Down arrows for CW and CCW respectively. Space to stop.
/Users/IanTMoritz/Desktop/Dash of Love/node_modules/particle-io/lib/particle.js:458
  pinInt = (pin.replace(/A|D/, "") | 0) + offset;
                ^

TypeError: pin.replace is not a function
    at Particle.pinMode (/Users/IanTMoritz/Desktop/Dash of Love/node_modules/particle-io/lib/particle.js:458:17)
    at Servo.Controllers.Standard.initialize.value (/Users/IanTMoritz/Desktop/Dash of Love/node_modules/johnny-five/lib/servo.js:59:19)
    at new Servo (/Users/IanTMoritz/Desktop/Dash of Love/node_modules/johnny-five/lib/servo.js:189:8)
    at new Servo.Continuous (/Users/IanTMoritz/Desktop/Dash of Love/node_modules/johnny-five/lib/servo.js:514:10)
    at Board.<anonymous> (/Users/IanTMoritz/Desktop/Dash of Love/bot4.js:16:15)
    at emitNone (events.js:72:20)
    at Board.emit (events.js:166:7)
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickDomainCallback (node.js:390:13)

Does it have something to do with the mapping of the shield?

Thanks!

Add mDNS support for Robustness.

During the last NodeBoats workshops at JSConf.Asia, I realised that backhaul from the router to the SparkCloud was super critical and if SparkCore couldn't connect to the SparkCloud, for whatever reasons (flaky connection, too many simultaneous requests, etc), there was no way to connect to the SparkCore.

This was ironic since the SparkCore is actually connected to the same router as the controller, and we just need the SparkCloud to know the IP address of the SparkCore. Asking some friends, I realised that mDNS solves this exact issue using multicast.

So I spent today prototyping to see if this would work. As long as the multiple SparkCores on the same network broadcast a unique hostname, it seems to work quite robustly. I used this node mdns implementation which is really straightforward.

Would such a mechanism help to reduce reliance on backhaul and SparkCloud? If it makes sense, I can clean up my prototype implementation and raise a PR. Also I would love to know if there are other ways to get around this solution which we can explore.

P.S. This will also need a corresponding change in voodoospark to be able to optionally get the IP Address from mDNS instead of SparkCloud. There exists a library which does mDNS on the SparkCore, we will need to integrate it into the voodoospark firmware.

endpoint not reachable

Hi, I tried flashing the voodoospark firmware with the web interface and via the cli now but everytime I want to connect I just get

Error: Unable to connect to spark cloud.

and if I curl the endpoint-url with my token and device-id it just gives me a 404 and says

{
  "ok": false,
  "error": "Variable not found"
}

Test with new Spark Photon / Electron

Spark just announced the new Photon. Maybe we can get a prototype to test early and make sure it works with spark-io and voodoospark out of the gate?

Error connecting to particle cloud

I'm using a photon.

This is the error:

Error: Unable to connect to particle cloud.: code: 404 undefined
at IncomingMessage. (/Volumes/Lychee/Users/andrewh/Development/node/node_modules/particle-io/lib/particle.js:346:19)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:919:16
at process._tickCallback (node.js:419:13)

I'm using your sample code:

var Particle = require("particle-io");
console.log("Token = " + process.env.PARTICLE_TOKEN);
console.log("Device ID = " + process.env.PARTICLE_DEVICE_ID);

var board = new Particle({
token: process.env.PARTICLE_TOKEN,
deviceId: process.env.PARTICLE_DEVICE_ID
});

board.on("ready", function() {
console.log("CONNECTED");
this.pinMode("D7", this.MODES.OUTPUT);

var byte = 0;

// This will "blink" the on board led
setInterval(function() {
this.digitalWrite("D7", (byte ^= 1));
}.bind(this), 500);
});

Any ideas?

Allow connecting to devices via device name

This is mostly for convenience, but also for use in a lab setting where the devices are already provisioned and named. In our case, the chips will have the names on a sticker, so doing something like this would be nice:

var board = new five.Board({
  io: new Particle({
    token: 'MY_TOKEN',
    deviceName: 'downton_abbey' 
  })
});

At connection time, we'd query the devices on the given API token, find the device by name, and get the ID that way.

Thoughts? Objections? I'll probably pair that with a PR for allowing direct connections when you know the IP address: #67

Spark API changes

It seems that the spark API changed certain request parameters as follows:

  • spark.js line 226
    It creates the url with a /endpoint param, when that url is manually tested it returns this error:
{
  "ok": false,
  "error": "Variable not found"
}

I did not notice a endpoint parameter in the spark API docs, setting line 218 to null seemed to bypass that error, creating a new one farther on.

Where did you get your resources for creating this lib? As the API seems to have changed, I could send a PR once the changes are known to fix the issue.

Unable to connect to spark cloud.: code: 404

While I'm able to use the Web IDE and spark-cli, I can't connect using spark-io (created .sparkrc and modified .bashrc).
The code:

var Spark = require("spark-io");
var board = new Spark({
  token: process.env.SPARK_TOKEN,
  deviceId: process.env.SPARK_DEVICE_ID
});

board.on("ready", function() {
  console.log("CONNECTED");
  this.pinMode("D7", this.MODES.OUTPUT);

  var byte = 0;

  // This will "blink" the on board led
  setInterval(function() {
    this.digitalWrite("D7", (byte ^= 1));
  }.bind(this), 500);
});


board.on('error', function(err) {
    console.log(err);
});

I'm getting this error:

Error: Unable to connect to spark cloud.: code: 404
    at IncomingMessage.<anonymous> (/home/a0viedo/Documents/jsPlayground/node_modules/spark-io/lib/spark.js:282:19)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickCallback (node.js:442:13)

Any ideas?

Support I2C devices

This will be in conjunction with a VoodooSpark update as well. I'm starting work on this, but I wanted to create an issue to track questions and conversations here.

Flip the polarity of data connection

Due to the following issues:

  • Connection retries
  • Address confusion
  • Server setup requirement
  • Firewall concerns

It is recommended to switch the polarity of the local spark communication from:

TCP server being on the host computer and TCP client being on the Spark

to:

TCP server being on the Spark and TCP client being on the Host Computer

This will allow the host computer to control retries/reconnects, not have to worry about firewalls (Spark doesn't have a firewall as best I can tell), or multiple network interfaces. This will make the code base for spark-io significantly easier. Pull request coming soon (today).

Pin Error: D1 is not a valid PWM pin

I just got my spark today and started to play around a little with Johnny-Five and then tried to do led.pulse() via the REPL with this code:

board.on("ready", function() {
  var led = new Five.Led("D1");

  this.repl.inject({
    led: led
  });
});

but then I only got this:

1400795647364 Device(s) spark-io 
1400795648347 Connected spark-io 
1400795648347 Repl Initialized 
>> led.pulse()
Error: Pin Error: D1 is not a valid PWM pin (Led)
    at Function.Pins.Error (/Users/udo/Desktop/spark-test/node_modules/johnny-five/lib/board.pins.js:70:9)
    at Led.pulse (/Users/udo/Desktop/spark-test/node_modules/johnny-five/lib/led.js:211:16)
    at repl:1:6
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)

do you see what I'm doing wrong here? Thanks :)

Two Servos at one time don't work.

I have a proof of concept with two servos but I observed it with a pwm and a servo on a different project. In this POC the first servo works fine, but the second one doesn't get any signal from the pin. I confirmed with an arduino using pulseIn() to check to see if any pulses were being sent, but if you hook up servos you get a nice visual.

board.on("ready", function() {
  console.log("CONNECTED");

  var byte = 0;
  var s1 = 'D0';
  var s2 = 'A1';

  var MAX = 180;
  var MIN = 0;

  this.pinMode(s1, this.MODES.SERVO);
  this.pinMode(s2, this.MODES.SERVO);

  setInterval(function() {
    if(byte ^= 1) {
      console.log(MAX);
      this.servoWrite(s1, MAX);
      this.servoWrite(s2, MAX);
    } else {
      console.log(MIN);
      this.servoWrite(s1, MIN);
      this.servoWrite(s2, MIN);
    }
  }.bind(this), 1000);
});

screen shot 2014-10-14 at 11 26 59 pm

Error messages not helpful in certain situations

While setting up at RobotsConf, I got:

'Error code 400 - error connecting to cloud' when my Spark token was expired.

Then, 'Error code 404 - error connecting to cloud' when Spark returned a 'variable not found' error (not displayed - had to dump the error body out) indicating I had an old or nonexistent version of VoodooSpark installed.

These could return some more useful hints / messages.

Unable to connect to spark cloud 404 error

Hi,

I wrote 2 scripts a few months ago that were working well with the spark cloud. Yesterday I fired them up again for NodebotsDay and ran into the following error:

Error: Unable to connect to spark cloud.: code: 404 {
"ok": false,
"error": "Variable not found"
}
at IncomingMessage. (/Users/kold/spark-io-scripts/node_modules/spark-io/lib/spark.js:246:19)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:919:16
at process._tickCallback (node.js:419:13)

This is the code I'm running to generate this:

var Spark = require("spark-io");
var five = require("johnny-five"),
  board, photoresistor;

board = new Spark({
  token: process.env.SPARK_TOKEN,
  deviceId: process.env.SPARK_DEVICE_ID
});

Debugging a bit, it seems that an action of "endpoint" is no longer supported by the Spark Cloud, although I cannot find a deprecation:

https://github.com/rwaldron/spark-io/blob/master/lib/spark.js#L226

I am certain that my device is connecting and reporting a variable as I am able to use the spark-cli and monitor the variable in realtime and it reports correctly:

spark variable monitor photoresisto

What's odd is that I"m not able to find any mention of "endpoint" in https://github.com/spark/spark-cli or https://github.com/spark/spark-server (even though it's fairly new).

Are other's seeing this issue?

I'm running:

[email protected]
[email protected]
[email protected]

pulseIn

Would be nice if support for "pulseIn" could be added.

The example:

board.on("ready", function() {
  var ping = new five.Ping('D4');
  ping.on("change", function() {
    console.log("Object is " + this.in + " inches away");
  });
});

results in:

TypeError: Object #<Spark> has no method 'pulseIn'
    at Ping.<anonymous> (/home/georgzahlz/johnny/node_modules/johnny-five/lib/ping.js:45:13)
    at wrapper [as _onTimeout] (timers.js:261:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

pin normalization issue when using particle-io and oled-js

In trying to use an SPI OLED screen with J5 / Particle-io with oled-io, I found a pin naming conflict. It seems that the normalization of pin names didnt carry over to using them in this way. I am playing with it more.

c:\Users....\node_modules\particle-io\lib\particle.js:458
pinInt = (pin.replace(/A|D/, "") | 0) + offset;
^
TypeError: pin.replace is not a function

Code I am trying to run...

var five = require('johnny-five');
var particle = require('particle-io');
var board = new five.Board({
io: new particle({
host: '192.168.43.118',
port: 48879
})
});
Oled = require('oled-js');

board.on('ready', function() {
console.log('Connected to Arduino, ready.');

var opts = {
width: 128,
height: 64,
slavePin: 'A5'
};

var oled = new Oled(board, five, opts);
oled.fillRect(1, 1, 10, 20, 1);
});

Support for Serial on Particle devices

VoodooSpark supports serial data functions but spark-io does not. Will you be adding this capability soon or are there specific barriers to doing so?

Cloud API not getting stream

Able to connect in Cloud API and get devices info but can't access device stream! Didn't change anything on the code and was scripts are smoothly running before not until yesterday!

Scripts able to get devices info using access token but can't get stream!

Thanks

A motor and a servo doesn't work

So using my handy pulse counting arduino, I can confirm that, this will only drive the servo. But if you comment out the servo, the motor works fine.

board.on('ready', function(){

  var motor = new five.Motor({
    pins: {
      pwm: "A0",
      dir: "D0",
      cdir: "D1"
    }
  });

  var servo = new five.Servo({
    pin:"A1"
  });

  this.repl.inject({
    s: servo,
    m: motor
  });

});

Deploying on AWS needs 'serialport' installed

I used spark-io as add-on for johnny-five and deployed my node app on EC2 in order to control my Spark core over the internet.

After running node index.js on EC2 linux, the error thrown:

It looks like serialport didn't compile properly. This is a common problem and its fix is well documented here https://github.com/voodootikigod/node-serialport#to-install

/home/ubuntu/spark-test/node_modules/johnny-five/node_modules/firmata/lib/firmata.js:29
    throw "Missing serialport dependency";
    ^
Missing serialport dependency

I digged into firmata.js and SerialportPort == Null so it threw the error. Is it possible to use this stack and deploy on the web? Or do I have to resort to the original Spark Cloud REST API? If it is, what's the best practice in using spark-io and johnny-five on the internet?

Auto generated docs from examples

Should we copy over the mechanism for auto-generating docs from examples as used in Johnny-Five?

The ones I added so far were manually copied and edited because I wasn't aware of the J5 auto-generated method at the time.

Board disconnect event

It would be great if there was some way to tell if the board has stopped responding. Be it due to failure, power, disconnect, etc. I don't need to know why, just that it's no longer connected. Similar to rwaldron/johnny-five#1037.

Address in use

Ran the hello world, and got this:

» node index.js
1394716774107 Device(s) spark-io

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1039:14)
    at listen (net.js:1061:10)
    at Server.listen (net.js:1135:5)
    at Object.Spark.Server.create (/Users/remy/Sites/hardware/node_modules/spark-io/lib/spark.js:189:18)
    at new Spark (/Users/remy/Sites/hardware/node_modules/spark-io/lib/spark.js:159:16)
    at Object.<anonymous> (/Users/remy/Sites/hardware/spark-blink/index.js:4:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

Took me a while to spot that a server was being spun up.

Stopped my other server and it runs.

So this line:

port: opts.port || 8001

...could be changed to || 0 and change:

state.server.listen(state.port);

To:

state.server.listen(state.port, function ()  {
  if (state.port === 0) {
    state.port = state.server.address().port;
  }
});

I've not tried this yet - and if I get the spark actually working (not your library, just getting timeouts!), then I'll see if I can send a PR if it's useful.

Led.pulse() kills Spark

Example:
https://gist.github.com/Resseguie/432c67fe4987d4867fcb

In this example, with Led.RGB.pulse(), it flashes white sporadically (really fast with a few slow flashes mixed in), then the led goes out and the Spark goes through it's reboot process (flashing green, etc). Then you usually can't reconnect to it (even after breathing cyan) unless you unplug USB and plug it back in.

.sparkrc

Hi

Sorry to open an issue, but I am stuck with the part where you create the .sparkrc file. I'm trying to get D7 to blink in my spark core with the spark-io plugin.

I flashed my spark core with the voodooSpark firmware. Then I created the .sparkrc file with my spark core token and device id and get the following error;

Error: Unable to connect to spark cloud.: code: 400 {
"code": 400,
"error": "invalid_grant",
"error_description": "The access token provided is invalid."
}
at IncomingMessage. (/home/phil/Documents/Spark/Hello World/node_modules/spark-io/lib/spark.js:243:19)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:929:16
at process._tickCallback (node.js:419:13)

also console.log(process.env.SPARK_TOKEN) gives an output of undefined.

Please help

Detect restart of photon

Hi, I'm using the voodoospark firmware and this library to send commands from a server to a photon.

I'm curious if there's an existing way that I'm not seeing to re-initialize a Particle instance if connection with the photon is lost. A digitalRead handler will just stop being called if, for example, the photon gets restarted. As far as I can tell the Particle object's 'error' handler will also never get called in this case.

It doesn't look like the net.socket object being used is exposed anywhere, nor are its 'close' or 'error' events handled. I can get around it by pinging the photon and reconnecting if it doesn't respond, but I'd prefer responding to the socket library's events.

Everything else is working as expected, thanks for your work on these libraries!

Incompatibilities with Spark CLI 1.2.0

When running Spark CLI 1.2.0, the only version that worked for us at JSConf, we had to flash voodoo spark with spark flash [id] voodoo, which is an older version of VoodooSpark. Our installation instructions are at https://github.com/opheliasdaisies/nodeboats-jsconf2015.

When we flash the latest version straight from GitHub, we would get a 404 error very quickly (less than a second after startup). This error came from the call that spark-io makes to get the device info (not from a voodoospark call).

This doesn't really make sense, but it's what we observed ¯_(ツ)_/¯.

This issue is mostly to track the problems we ran into that wasn't purely Spark Core based.

Blink example fails to connect

Despite succeeding with a curl connection, I cannot establish a spark-io / johny-five connection, using the same token/deviceId

voodoospark has been loaded, and the curl test is working.
when curling this:

 curl https://api.spark.io/v1/devices/{55ff6e065075555308401787}/endpoint?access_token={6e4a3368dda1aeb1742f17dbcd091cab8e81acf5}"

I get this result, as expected:

{
  "cmd": "VarReturn",
  "name": "endpoint",
  "result": "10.0.10.119:48879",
  "coreInfo": {
    "last_app": "",
    "last_heard": "2014-05-16T04:59:09.167Z",
    "connected": true,
    "deviceID": "55ff6e065075555308401787"
  }

However, no love when I test either rwaldron/spark-io, or johnny-five with spark-io as a plugin.
Here is my code, (including temporary access token):

var five = require("johnny-five");
var Spark = require("spark-io");

var board = new five.Board({
  io: new Spark({
    token: "6e4a3368dda1aeb1742f17dbcd091cab8e81acf5",
    deviceId: "55ff6e065075555308401787"
  })
});

board.on("ready", function() {
  var led = new five.Led("D7");
  led.blink();
});

Here is my console command, and the result from spark-io:

 nick$ node spark-io-nick.js
 1400215473876 spark-io Connecting... 

there is no LED blink, and no indication of a completed connection.

Any thoughts about the failure to connect?
Is there any chance that 'spark-io' is not picking up on the port number for the board?

new five.Button ( TypeError: pin.replace is not a function )

Hi folks,

I’ve come across an error when adding a new five.Button() to spark-io board.

I’ve looked through the examples in /eg, but there doesn’t seem to be one using a button,
so forgive me if Im missing something about buttons and spark-io - I’m kind of new to this.

"devDependencies": {
  "johnny-five": "^0.8.85",
  "spark-io": "^0.6.1"
}

Here’s the script

var five = require('johnny-five')
var Spark = require('spark-io')

var board = new five.Board({
  io: new Spark({
    token: process.env.SPARK_TOKEN,
    deviceId: process.env.SPARK_DEVICE_ID
  })
})

board.on('ready', function() {
  var button = new five.Button('D3') // Booo!

  button.on('down', function() {
    console.log('down')
  })
})

Here’s the error:

nodebots % node button.js
1438999226193 Device(s) spark-io  
1438999227426 Connected spark-io  
1438999227601 Repl Initialized  
>> /Users/chrisbuttery/Web/nodebots/node_modules/spark-io/lib/spark.js:318
  pinInt = (pin.replace(/A|D/, "") | 0) + offset;
                ^
TypeError: pin.replace is not a function
    at Spark.pinMode (/Users/chrisbuttery/Web/nodebots/node_modules/spark-io/lib/spark.js:318:17)
    at Button.Controllers.DEFAULT.initialize.value (/Users/chrisbuttery/Web/nodebots/node_modules/johnny-five/lib/button.js:29:17)
    at new Button (/Users/chrisbuttery/Web/nodebots/node_modules/johnny-five/lib/button.js:189:10)
    at Board.<anonymous> (/Users/chrisbuttery/Web/nodebots/game-buzzer.js:12:16)
    at emitNone (events.js:67:13)
    at Board.emit (events.js:163:7)
    at doNTCallback0 (node.js:415:9)
    at process._tickDomainCallback (node.js:385:13)

So here are the opts when johnny-five calls it’s button initialisation:

https://github.com/rwaldron/johnny-five/blob/master/lib/button.js#L187

if (typeof this.initialize === "function") {
  this.initialize(opts, function(data) {

    // opts = Options {pin: "D3", pinValue: "D3"}
  }
}

Here are the opts when the button is initialised:

https://github.com/rwaldron/johnny-five/blob/master/lib/button.js#L21

var Controllers = {
  DEFAULT: {
    initialize: {
      value: function(opts, dataHandler) {

        if (Pins.isFirmata(this) && typeof opts.pinValue === "string" && opts.pinValue[0] === "A") {
          opts.pinValue = this.io.analogPins[+opts.pinValue.slice(1)];
        }

        this.pin = +opts.pinValue;

        // opts = Options {pin: "D3", pinValue: "D3"}
        // this = Button {board: Board, io: Spark, id: null, pin: NaN, holdtime: 500…}
        // this.board.io.name = "spark-io"
        // 'Pins.isFirmata(this) = false
        // opts.pinValue = "D3"
        // opts.pinValue[0] === "A" = false
      }
    }
  }
}

… and the spark-io throws an error here:

https://github.com/rwaldron/spark-io/blob/master/lib/spark.js#L325

pinInt = (pin.replace(/A|D/, "") | 0) + offset;

// pin = NaN

Adding a "bypassCloud" parameter?

I'm thinking of adding a opts.bypassCloud configuration parameter. When set, it will use the opts.host and opts.port parameters instead of retrieve it from the cloud endpoint. I'll write the PR, but I wanted to talk about it first.

The goal is to allow for devices that have a predictable enough IP address on the local network (due to MAC address reuse at the router) to not need the internet to get the local address. I'm thinking of this as a way to solve unreliable internet connections at conferences.

The opts.bypassCloud option isn't specifically necessary. The presence of opts.host and opts.port should be enough. I can see pros and cons to having the opts.bypassCloud option.

In addition, I'll probaby add an event to the IO class that tells us the host/port when it DOES get it from the cloud so that the user store it.

Thoughts?

MPU6050 example not working

I tried the sample code for the MPU6050 with a Particle Photon and could not get it to work. I logged 0 for all values on start, and then never seems to fire the change event again.

1472520526381 Device(s) particle-io
1472520526767 Connected particle-io
1472520526806 Repl Initialized
>> accelerometer
  x            :  0
  y            :  0
  z            :  0
  pitch        :  0
  roll         :  0
  acceleration :  0
  inclination  :  0
  orientation  :  0
--------------------------------------

I am using VoodooSpark 4.0.0 and have tried with Particle-io 0.12.0 and 0.14.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.