Connecting Two photons Together

I have been working on a small project recently which has two parts. THE FIRT part involves reading the temperature values on my mobile using a photon and the BLYNK app AND it has been successfully concluded however, I am yet to figure out the second part as it involves sending the temperature data from one photon to be displayed via WIFI. I want to ask IF IT IS POSSIBLE TO USE TWO PHOTONS, one acting as a transmitter and the other acting as a receiver Because I want to send the temperature values to another photon where the values will be displayed on an LCD. Please bear with me that am very new to all the programming stuff so don’t laugh… :grinning:. Please @peekay123, @ScruffR and others help me out with this and I will be very grateful for any help or clue :smiley: Thanks

This is definetly possible and there are numerous ways to do this.
But one common prerequisite is that both Photons need to be connected to a WiFi access point. At the moment there is no way to have them talk with eachother direct.

The standard cloud-bound way to have two Particles talk with eachother is Particle.publish()/Particle.subscribe().
Without cloud connection but WiFi, you can use TCPServer/TCPClient and UDP even between different networks.
If both devices are connected to the same AP UDP broadcast/multicast would be a way to go too.

And there also non-WiFi options (wired & wireless).

2 Likes

As a follow-up to what @ScruffR posted…
The documentation has this example which demonstrates the type of communication you’re looking for. (Communication via the cloud with Publish & Subscribe)
https://docs.particle.io/guide/getting-started/examples/photon/#the-buddy-system-publish-and-subscribe

3 Likes

You can use Blynk Bridge Widget for that. It’s experimental feature but it works.


http://docs.blynk.cc/#widgets-other-bridge

Am trying to use the > Spark.publish() function to publish the temperature data to the dashboard which I will retrieve with another photon. I have read the references on how to do it but I still don’t understand how am gonna publish and later retrieve i.e. I have a data called “tempC” from the code below: but i don’t know which function name to use to publish the data. Please @ScruffR, @peekay123 and any other person should please help me out with this and thanks for your support again am very grateful.

CODE:

void loop() 
{
    //char Body-Temperature;
    Blynk.run();
    tempC = mlx.readObjectTempC();
    tempF = mlx.readObjectTempF();
   // Serial.println("................*C            *F............");
    Serial.println("         ");
    Serial.print("Body temperature = ");
    Serial.print(tempC);
    Serial.print("*C");
    //Particle.publish("Body temperature", "*C");
    //Particle.publish("tempC", PRIVATE);
  //  Serial.println(tempF);
    Blynk.virtualWrite(V0, mlx.readObjectTempC());
    Blynk.virtualWrite(V3, mlx.readObjectTempC());
    Serial.println();
    delay(3000);
}

What do you mean with later? Currently there is (AFAIK) no such thing as a defered subscribe to previously published events (despite the TimeToLive parameter ;-)).

But for the publishing as such, this would be one way to go

  Particle.publish("BodyTemp", String::format("%3.1f *C", (float)tempC));  // format a float as "#0.0 *C"
  //Particle.publish("BodyTemp", String::format("%3.1f *C", (float)tempC), 60, PRIVATE);  // or private

You just need to make sure you limit your publishing attempts to one per second (the delay(3000) will do for that).
If you go for PRIVATE then your subscribe needs to use the MY_DEVICES parameter.

1 Like

Thanks a lot @ScruffR I managed to get it published and I can now see the values on the dashboard however, Am trying to subscribe to the event (I used private) but Am not sure how to go about it. Please if you have any ideas how I can go about it regarding the code i used to publish then please help me out. Thanks

Have a look in the docs and the sample code there
https://docs.particle.io/reference/firmware/photon/#particle-subscribe-

Particle.subscribe("BodyTemp", theHandler, MY_DEVICES); should work for PRIVATE events.

Do the transmitting and receiving photons absolutely have to be connected via Wi-Fi router/access point? Is there any way to have them connect and send data using only the 2 photons and no additional hardware?

This is not yet possible, but if you look for SoftAP in this forum or in the “issues” section of the firmware open source section, you might find some hints and/or progress reports.

@ScruffR, thank you very much!