Arduino “having11” Guy
Published © GPL3+

2-Way Particle Photon Communication

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

EasyShowcase (no instructions)1 hour801
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

Schematic bb egovvk2pzt

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

26 projects • 181 followers
IoT, Arduino, and Raspberry Pi. I can create design, code, and build projects for only $22/hr. Just message me with your project request.
Contact

Comments

Add projectSign up / Login