callFunction from Node == Extra Bytes?

I am using the Node.js Spark library to invoke a function on my Photon. The data being sent over is a string generated by JSON.stringify( obj ). The function on the Photon is called, but it seems to be getting extra bytes. My guess is a wrong encoding set somewhere, but since I’m using the Spark library, I don’t have much visibility into the call.

Any ideas as to what’s going on here?

I console.log( obj ) before sending, and the content is the JSON string I expect. When it gets to the Photon and is spit out via Serial.println() I get something that looks like the following …

���?�C�!IQ!
Mode: �?�C�!IQ!
Color: 0, 0, 0
Ticker: �?�C�!IQ!

The first line is the string as received into the Photon function, printed via Serial.println(). It is literally the first line executed in the function. The following lines are my attempt to parse the incoming string. If I paste the string from the console.log() operation, into the Photon code, everything functions as expected (correct parsing).

I know I’m missing something simple, but I’m just not sure what. Help?!

Thanks,
Kevin

Could you show how you parse the string on the Photon side?
And the code how you trigger the function on your remote side?

If possible post you full Photon code, but at least the full function.

BTW:

You can have a look into the library here

So … It seems the Spark JS library was magically deprecated overnight. Generally Particle has been very good about communication with the community. Not so much this time. Would have been nice to have a heads up. I have a Photon hands-on lab I give at conferences which relies on the Spark JS library. Now I suddenly have a lot of unscheduled changes to make on the course materials.

As for the new library (Particle API JS) …

I tried the “login” example, and was met with a 404 error “errorDescription: ‘HTTP error 404 from /oauth/token’”. Did I miss something?

var Particle = require( 'particle-api-js' );

var particle = new Particle();

particle.login( {
    username: 'my@email.address',
    password: 'my_password'
} ).then( function( data ) {
    console.log( 'Token: ' + data.access_token );
}, function( err ) {
    console.log( err );
} );

Thanks,
Kevin

Ongoing research here …

I eventually found out the problem I was having with garbage coming across - I was sending more than 63 characters. Neither the Spark JS, nor the Particle API JS, documentation mention this limitation. Might be worth adding to the respective documentation.

After struggling with the Particle-provided wrappers for the Cloud API, and in needing only a few of the features, I decided to roll my own wrapper. As I worked through calling a function, there it was - 63 character limitation. I reformatted the string argument to the function call, keeping it under 63 characters, and everything worked!

This of course doesn’t solve the 404 with using the Particle API JS library … Baby steps.

Thanks,
Kevin

Yup, on the firmware side the limit is documented well enough, but a note on the JS side would not harm either.

https://docs.particle.io/reference/firmware/photon/#particle-function-

The thing is, the JS side has no problem sending long strings, but the receiver couldn't handle it, so this might have been the place to start investigation.

If we could have had a peek at the code(s) right away it might have sprung into our eyes earlier :eyes: :wink: