Evan Rust
Published © GPL3+

2-Way Particle Photon Communication

Make two Particle Photons "talk" via the usage of webhooks!

BeginnerShowcase (no instructions)1 hour2,490
2-Way Particle Photon Communication

Things used in this project

Hardware components

Photon
Particle Photon
×2

Software apps and online services

Particle Online IDE
Particle Cloud Console

Story

Read more

Schematics

Schematic

Code

First Photon

C/C++
#include <stdio.h>
#include <stdlib.h>

int counter = 0;
char *message;

void setup() {
    Particle.publish("test", "This is a test");
    Particle.subscribe("test2", handler);
    Particle.variable("Message", message);
}

void loop() {
    
    while(1){
        char buffer[32];
        char *str_counter = itoa(counter, buffer, 10);
        Particle.publish("test", str_counter);
        counter++;
        delay(5000);
    }
}

void handler(const char *event, const char *data){
    if(data){
        message = const_cast<char*> (data);
    }
}

Second Photon

C/C++
#include <stdio.h>
#include <stdlib.h>

int counter = 0;
char *message;

void setup() {
    Particle.publish("test2", "This is a test");
    Particle.subscribe("test", handler);
    Particle.variable("Message", message);
}

void loop() {
    while(1){
        char buffer[32];
        char *str_counter = itoa(counter, buffer, 10);
        Particle.publish("test", str_counter);
        counter++;
        delay(5000);
    }
}

void handler(const char *event, const char *data){
    if(data){
        message = const_cast<char*> (data);
    }
}

Credits

Evan Rust

Evan Rust

122 projects • 1091 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments