Particle Photon


#1

I am working on adding a particle photon to cayenne but looks like the cayenne-particle library is out of date. The library requires an auth token instead of username, password and client id. Am i missing something? If anyone has a particle photon communicating with cayenne, i would like to hear your suggestions.

Thanks,
-Dalibor


#2

Hi @sherkon18 ,

Are you referring to this library? If so, yes, that’s deprecated. Technically you can try using any MQTT client library available for Photon and they should work.
Such as: https://github.com/hirotakaster/MQTT

Thanks


#3

This is good info. I am trying to use this library and have had no success. Wondering if i am using it incorrectly?

 #include "application.h"
#include "MQTT.h"


void callback(char* topic, byte* payload, unsigned int length);

MQTT client("mqtt.mydevices.com", 1883, callback);

// recieve message
void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;

    if (!strcmp(p, "RED"))
        RGB.color(255, 0, 0);
    else if (!strcmp(p, "GREEN"))
        RGB.color(0, 255, 0);
    else if (!strcmp(p, "BLUE"))
        RGB.color(0, 0, 255);
    else
        RGB.color(255, 255, 255);
    delay(1000);
}


void setup() {
    RGB.control(true);

    client.connect("client id goes here", "mqtt user name goes here", "mqtt password goes here");

    // publish/subscribe
    if (client.isConnected()) {
        client.publish("miningRigTempHum","hello world");
        client.subscribe("miningRigTempHum/message");
    }
}

void loop() {
    if (client.isConnected())
        client.loop();
}

#4

As long as you are using the right credentials provided by the dashboard, the only thing you should focus on is the MQTT topic. To send data publish to: v1/USERNAME/things/CLIENT_ID/data/CHANNEL

CHANNEL can be any number from 1-99


#5

As @asanchezdelc said, at a quick glance it looks fine to me. If it is not working let me know. I have one somewhere that I can test your code with.


#6

Thats my code below, even with suggested topic format by @asanchezdelc i am not able to connect. Keep the suggestion coming.

#include “application.h”
#include “MQTT.h”

char USR[] = "user id # goes here";
char PSS[] ="password # goes here";
char CLIENT_ID[] = "client id goes here";


void callback(char* topic, byte* payload, unsigned int length);

MQTT client("mqtt.mydevices.com", 1883, callback);

// recieve message
void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;

    if (!strcmp(p, "RED"))
        RGB.color(255, 0, 0);
    else if (!strcmp(p, "GREEN"))
        RGB.color(0, 255, 0);
    else if (!strcmp(p, "BLUE"))
        RGB.color(0, 0, 255);
    else
        RGB.color(255, 255, 255);
    delay(1000);
}


void setup() {
    RGB.control(true);

    client.connect(CLIENT_ID,USR,PSS);

    // publish/subscribe
    if (client.isConnected()) {
        client.publish("vi/CLIENT ID GOES HERE/things/USERNAME GOES HERE/data/1","hello world");
       
    }
}

void loop() {
    if (client.isConnected())
        client.loop();
}

#7

Seems fine your code. I slightly modified the right payload format and turn the LED green once its connected. Also you had vi instead of v1.

https://mydevices.com/cayenne/docs/cayenne-mqtt-api/#cayenne-mqtt-api-mqtt-messaging-topics-send-sensor-data

char USR[] = "user id # goes here";
char PSS[] ="password # goes here";
char CLIENT_ID[] = "client id goes here";


void callback(char* topic, byte* payload, unsigned int length);

MQTT client("mqtt.mydevices.com", 1883, callback);

// recieve message
void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;

    if (!strcmp(p, "RED"))
        RGB.color(255, 0, 0);
    else if (!strcmp(p, "GREEN"))
        RGB.color(0, 255, 0);
    else if (!strcmp(p, "BLUE"))
        RGB.color(0, 0, 255);
    else
        RGB.color(255, 255, 255);
    delay(1000);
}


void setup() {
    RGB.control(true);

    client.connect(CLIENT_ID,USR,PSS);

    // publish/subscribe
    if (client.isConnected()) {
         RGB.color(0, 255, 0);
        client.publish("v1/CLIENT ID GOES HERE/things/USERNAME GOES HERE/data/1","temp,c=19");
       
    }
}

void loop() {
    if (client.isConnected())
        client.loop();
}