Please forgive the juvenile question. I’ve been successfully using my photons for a while now. I interface with them via a website on my cell phone. Essentially when I want to do something I use the URL to call a function and drive specific behavior (basically using: https://docs.particle.io/reference/api/#call-a-function). Now I would like to cut the cell phone out, and use another photon to do the same job. Is there any way I can use another photon and “post” (I think that’s the term)? I’m trying to keep compatibility with the cellphone… so I see the idea of subscribing, etc… but I’m trying to see if I can not change the current implementation and simply have the photon “click” the same link that I push on the website. Man I hope this makes sense… lol.
An example of my site code:
function ON1() {
var requestURL = “https://api.particle.io/v1/devices/” +deviceID1 + “/” + setOffOn + “/”;
$.post( requestURL, { params: onValue, access_token: accessToken1 });
}
… I’m wondering if the photon could do the same thing… the video at the bottom of this post my help clarify my current implementation: WiFi LED Driver
Not really, because there are two basic problems with this scheme: 1. The Photon doesn’t support https (TLS/SSL encryption) without a fairly cumbersome library. 2. None of the Particle devices can call a function on another device because it’s not supported either.
However, there is an easy solution to this problem that won’t break your phone app. There is no reason why the receiving Photon can’t implement both a function AND a subscription handler.
Here’s the sender code. With a switch connected between D2 and ground, it toggles the light on the receiver when pressed.
If you don’t want a mix of functions and publish/subscribe, why not switch over the web side of things to publishes as well? Then they use a common system that can be used for both.
@rickkas7 Rick, you were saying about a year ago… [quote=“rickkas7, post:2, topic:23056”]
None of the Particle devices can call a function on another device because it’s not supported either.
[/quote] - do you know if in that respect anything has changed with the firmware updates in the meantime? I mean, whether or not it is possible to call a particle function from another particle device?
The reason why I ask is the following. I have a number of particle devices set up (a home automation system) and they communicate with each other through the particle cloud by posting events. Actually, I use two “channels”, i.e. one event for requests (i.e. make another particle do something) and a second one for status messages (will be parsed and saved by the particles locally, e.g. as boolean variables). The system works fine although I notice a little lag, which probably is normal (fractions of a second to a second). I was just curious whether a direct function call, if technically possible, would be even faster (lower lag time) and whether such a setup would have any advantages?
Thanks for you opinion.
It's (unfortunately, still) not possible to directly call Particle.function()s between devices.
I don't think it would be much faster, if at all. The request would still need to make a round-trip to the very same servers, so there won't be much of a noticeable difference there. You could play around with local communications over your own network if the latency is annoying you that much.
@hbierau, the only “direct” call you could make is if you are running a TCP, UDP or Web Server on the target Photon and the calling Photon knows its local IP. Otherwise, pub/sub is your best way.