Tutorial: Getting Started with Spark.publish()

All - as a total neophyte, I was following this but I can’t seem to get the html file to work. When I open in a browser I just get the text of the file to show up, no Connect button or anything like that. Any ideas? Thanks!

If you’re using an OSX system, check this out: http://stackoverflow.com/questions/14439513/browser-shows-plain-text-instead-of-html-in-mac

Thanks a lot! I am now getting the HTML file to work and show the Connect button. It turns blue on click but then nothing happens. I brought up the Javascript console window but the message I get isn’t helpful to me: Uncaught SyntaxError: Unexpected token ILLEGAL

Could you paste the full output here, if possible? Have you copy&pasted your accesstoken/deviceID correctly?

I believe I pasted the device and access token properly, I did not try to type.

Hi! Very informative post. Where can I find an equivalent sample code in vb.net or c#? What I want to do is have an application running on my server that “listens” to publish events.

This might give you some starting point

I espevially liked @cloris' library

2 Likes

Unfortunately it is not compatible with Visual Studio 2010 :frowning:

My problem is that I don’t know what the process of listening to publish events is called and therefore I don’t know what I need to look for in Google.

What exactly is incompatible with VS2010 that is not possible to overcome?


BTW: Why are you still using VS2010? Have you given VS 2015 Community a try?

1 Like

Try "server sent events" :smile:

2 Likes

Or SSE :wink:

Both terms are mentioned in the linked thread

3 Likes

The project won't load and so I can't test it, nor can I figure out which parts of it I need for the task of listening to the publish event.

When I looked up “vb.net SSE” in Google all I got was HTML5 examples. From what I could gather, there is no vb.net equivalent of the addEventListener command used in this tutorial.

What tutorial are you refering to?

And may I ask how adept you are with C#?

If you have to use VS 2010 and can’t try VS 2015 Community you might need to just import the CS files into a new project and hand-craft some of the VS 2012 features that are used in above library, but that might need some “deeper” C# insight :sunglasses:

1 Like

The thread in which we are now. bko explains how to handle the publishes using javascript. I want to do the same using win forms with vb.net (ideally).

I can convert C# code to vb.net but I would rather it was vb.net from the start. The reason I want to stick to vb.net is because I want to implement SSE in an existing application written in vb.net.

I am installing VS2015 community while writing this. Will let you know how it goes. Thanks for introducing me to it.

Duh, I didn't read the topic title and only scrolled up till it started reloading prev posts once :blush:

You do know, that .NET is happily mixing C# with VB.NET? So you could just use the C# lib and call the functions from VB.NET.

Reading the event stream is really just doing an HTTP GET request that you keep open forever and don't (typically) allow your system to buffer (you want to get the events in real-time since you are not assembling a web page). Any programming language and framework that can do a HTTPS SSL/TLS request can do events.

The only minor complication is that the Particle server sends "keep-alive" characters to your code every 10 seconds or so to make sure the connection is not closed; you just have to ignore them.

I suggest you start by reading @cloris code on github and get a feel for what the EventAPI is doing.

Javascript already had a SSE callback framework for dealing with things like mouse events and so the natural way to handle cloud events was to use that, but with just a bit more work you could do it with just a HTTPS get request stream.

1 Like

OK. So with the help of @ScruffR, @Moors7 and @bko I have managed to reference the @cloris dll in my application to do basic stuff like getting the Core/Photon name. The next step is to get the SSE events to fire like regular .net events, so any help to get there would really be appreciated. I’m sure there is an example in the sample code provided by @cloris but I can’t seem to find it or understand how to use it.

1 Like

@bko
I used your examples but still getting Errored! on the chrome … any help ?

Sorry, but I have to ask: did you make sure to replace your credentials accordingly?