Arduino “having11” Guy
Published © GPL3+

2-Way Particle Photon Communication

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

BeginnerShowcase (no instructions)1 hour2,323
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

Arduino “having11” Guy

Arduino “having11” Guy

105 projects • 895 followers
20 year-old IoT and embedded systems enthusiast. Also produce content for Hackster.io and love working on projects and sharing knowledge.

Comments

Add projectSign up / Login