Tutorial: Getting Started with Spark.publish()

@Moors7
Totally forgot that :slight_smile: Thanks for the reply

But have some trivial questions right now ,

  • how to get the access token of my photon ?

  • and should i identify variables in that way var deviceID = “<< XX>>” or var deviceID = << XX>> ?

  • and lastly ,shall i leave this variable the same without modification
    var eventSource = new EventSource(“https://api.spark.io/v1/devices/” + deviceID + “/events/?access_token=” + accessToken);

I’m pretty new with html …

@Moors7
Already found it , how to get it working … Thanks anyway

1 Like

For future reference, if anybody else faces the same issues:

It can be found in the settings pane of the web IDE (the cog icon). It's actually the accesstoken to your account, not a single device. With that in mind, treat it as you would your password, since they're almost interchangable in regards to security.

The former is correct, e.g. var deviceID = "yadayada123"

Yes, assuming you have changed the variables above, these should not (don't have to) be changed, since they will use the values from above.

3 Likes

I am struggling with the need for changing the Core ID & Access Token from decimal to hex. With the html having decimal ID & token, the form asks a “connect click,” shares “Waiting for data,” but none is displayed on Chrome. Checking JavaScript console says “Opened” but no stream. Photon is breathing cyan.
When I convert the ID to Hex, but leave the 40 character token as is (how can you change a string of digits and letters into Hex?) the form indicates waiting for data, but JavaScript says "Errored."
I’m sure I’m the one at fault here - but where? I would sure appreciate your help.

New here.
Failed with using Pushover so I decided to try some easier, can’t seem to get this going either.
Chrome browser console lists Errored!

Hi @Mike6745

Did you update these two lines in the web page source?

 var deviceID = "<<hex device id here>>";
 var accessToken = "<<hex access token here>>";

The part between the " "'s needs to be replaced with your particular ID and token. These are available in the online web IDE (Build button) under the target icon and the gear icon, respectively.

1 Like

Thanks, I already had them in there and just double checked them.
Still nothing

Ah Ha!
I forgot to remove the << >>

Working now.
Thanks

1 Like

Hi , I am currently doing a project similar to this and still new here, and unfortunately it did not work. Just wondering with var deviceID, you mentioned ‘hex device ID’ , I am assuming I have to convert my device ID from decimal to hexa numbers. How about converting the access token?

Thanks !

The device ID you get from the various tools already is a string featuring a hex number - just copy paste.

1 Like

Thanks for the reply ! @ScruffR
I did try inserting the device ID I got from IDE particle itself, but not sure why if I use those number my html would not even let me click the ‘connect now’ button, giving this error on my safari.

SyntaxError: Invalid character '\u8364’
The error is pointed towards the device ID on line 14.

I tried on google chrome too but still not working.

Could you share your code as well as a Screenshot of the error message?

Could you have a comment on the like above it with a non-ASCII character? That is the unicode character for "meat diet; strong smelling" which is odd on a number of levels.

What editor are you using to edit the HTML source? You need a plain text editor.

3 Likes

Also, have you removed the << and >> symbols from the line?

You can post the line of code - the device ID isn’t as much a secret as the access token should be - if you still have concerns, you can PM one of the Elites.

Hi !

I am using textedit on macbook pro. I am not too sure if I accidentally comment something on my HTML code with a non-ASCII character or not, but when I tried the code again today, IT IS WORKING now !!! @bko

and yes I did removed both symbols from the line, but the code is working now when I tried it today.
Thank you for response anyway @Moors7 @ScruffR !

3 Likes

Hi, is it possible to use publish for stream data? I need to transfer sound data overr internet, but I don´t wan´t to use a TCP-IP socket.

Not really.
Particle.publish() has a rate limit of one publish per second with a maximum payload of 622 UTF-8 characters and you cannot transmit raw binary data with it.

1 Like