Sprint 7: Particle.publish() released! Let's build a cloud-connected motion detector

Very cool feature. I just received 2 PIR sensors for free from a recent Parallax order so looks like I have a cool way to use them now.

Now I just have to wait for somebody to come up with a easy to follow template that shows how to take Published data and push it out via Text Message that would be very helpful for us Newbies who are just getting started with all this.

Keep up the Great work team! :rocket:

4 Likes

Does the Spark.publish() feature make it any easier for somebody to have a event trigger a Text Message to be sent to a cell phone? or a email?

I know other people have accomplished this in other ways that are beyond my understanding right now so I’m wondering if the new function could make sending a text message or email easier for us new guys?

This is great ! I could get it running also, my spark is updated the uptime (millis()) every 2 sec.
However I could get it working with curl, but not with a webpage html. My question is: how do you pass the access_token in argument in html?
In the link you provided as example, they say Note: If the URL passed to the EventSource constructor is an absolute URL, its origin (scheme, domain, port) must match that of the calling page.
I guess it doesn’t mean that we can’t connect from outside https://api.spark.io/ but then how?

2 Likes

Same question here. I found this: Yaffle/EventSource

It has a cross-domain service support…not sure if that could work. Will try!!

Yes, good question! This will make it much easier for code on your core to trigger something like a text message. We’re also testing webhooks support, which will let you register a website with the API that will listen for events for you. So a “motion” event or others would cause your page / another service’s page to be called and trigger something like a text, definitely. :slight_smile:

1 Like

Spark.publish is popular!

Well, that didn’t take long! :smiley: After rolling out Spark.publish today, the message counts quickly spiked and consumed a large chunk of server resources. We found some users publishing 2,000-4,000 messages a minute (probably by accident)!

We expected a flood of events, but it’s important everyone gets a chance to publish events.
A few hundred cores monopolizing the event stream wouldn’t be a good user experience. For that reason, (for now…) we think setting a maximum rate of 60 events a minute per core, with a burst rate of up to 4 per second, should allow for almost all use cases.

If you need to move more data / more quickly, it might make more sense to do a direct TCP / UDP socket instead of publishing an event. Please feel free to weigh in! We will continue to improve and optimize things, so this limit may change down the road.

Thanks!
David

1 Like

For the truly lazy, you can use Spark.publish() as a sort of remote Serial interface.[quote=“Dave, post:10, topic:3391”]
We found some users publishing 2,000-4,000 messages a minute (probably by accident)!
[/quote]

/me sheepishly raises hand. It may have been me. What’s a button debounce? :wink:

Maybe if the cores were limited to something closer to 16 MHz, they wouldn’t be able to spam the service so fast!

3 Likes

Great work team Spark - can’t wait to try it.

1 Like

It’s amazing what removing the “connected” barrier can enable. This product is awesome.

I’m really excited about the webhooks feature.
If you want an outsider beta tester, I’ll preparing my spark tools service for this.

1 Like

I have the same issue… CURL looks great… but how do we subscribe to events using the HTML5 examples? , if we cant instantiate the EventSource object with the sparkcore absolute URL. In addition, how do we send the Authorization Header (access token) using common HTML 5 subscription ??

I post about this same problem over here:

I can see the stream open so I don’t think the URL/URI is the problem, but I never get a message or onmessage callback.

Hi @omarojo and @Fabien

I got the HTML5 code to work over in the Registering A Callback thread.

I thought registerring a callback means the spark cloud is going to make a HTTP POST I think. I don’t want HTTP POST I want direct web socket notification as Server-Sent-Events works, which is much much faster and realtime. Is there another way to tests this spark core SSE’s other than terminal ?

Hi omarojo, I use bko code and adapt it to Node.js. (in Registering A Callback thread. )

Thank you

Hi @omarojo

You open the event stream with a GET request and then you need to create a listener on that stream for your particular event. From the listener you can do anything you could normally do from web page.

whoops… @bko code is working fine ! your are right. Didn’t know it was possible to pass the access_token in the URL. As you said best way might be to make a Node.js script that runs in server so that access_token is not exposed.
Also… after this code example… Im not getting what “Registering a CallBack thread” means… do you mean the eventSource.addEventListener() ??

Hi @omarojo

The “Registering a Callback” thread is another discussion here in the forum–sorry for any confusion over the use of thread for a discussion thread and not a code thread!

1 Like

Just go look at the other discussion(topic) names “Registering a callback”…in this forum. Just go back to the main menu.

thank you

1 Like

Confirmed !! example codes from @Playagood and @bko works just fine ! Thank you very much !

@omarojo So after getting this working what do you think is the easiest way for a beginner to get started using the Spark.publish() features?