Particle Photon and DS18B20 Temp Sensor


#18

Hello Adam,

I’m trying to setup my Particle Photon to connect to cayenne, looking at the code you provided, however I’m unable to make the correlation from my cayenne mqtt username and password to the authtoken. Can you point me in the right direction?

Thanks!


#19

That’s was actually an old unsupported connection method. I’m not sure if there are any examples here to connect with mqtt. I’m not at my computer right now but I’ll see what I can come up with this weekend. @shramiksalgaonkar before I go digging in drawers for my photon do you know of example code?


#20

I never had my hands on particle photon. Let me check it with the team. Give it a try and see if you can get it working.


#21

@shramiksalgaonkar I tried to connect my Particle but it’s not happening. Do you know anyone that has one in the Cayenne team? I’m not sure how to tell why it’s not working. There are no errors that I can see, it just doesn’t connect. Here is the code I tried:

// This #include statement was automatically added by the Particle IDE.
#include <DS18B20.h>
//DS18B20 ds18b20(D0);

// This #include statement was automatically added by the Particle IDE.
#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() {
    Serial.begin(9600);
    delay(5000); // Allow board to settle
    client.connect("cayenne", "username", "password");
    //Particle.publish("setup finished");
}

int counter = 0;
void loop() {
    //Particle.publish("loop");
    counter = counter++;
    
    if (client.isConnected()){
        Particle.publish("connected");
        client.loop();
    
        String mesasge = "temp,f=" + counter;
    
        client.publish("v1/username/things/clientid/data/1", mesasge);
    }
    
    delay(1000);
}

#22

thank you @adam for giving it a try. We currently do not have an official support for the photon.


#23

Guess I’ll try to connect to a local MQTT server to see if it’s a problem with Cayenne, the library, or the device. The photon is a cool easy to use device, I think it would be wise to get official support on it. @jburhenn


Feature Request - Support for Particle Devices
#24

The (unsupported) library that someone ingenuously forked from Blynk to allow Particle to work with Cayenne no longer works. Ever since having to go MQTT. I have spent hours trying to use the Arduino-MQTT library for Cayenne and make it work with Particle and so far no luck. I have made an official request for MyDevices to get together with Particle and work on Integration. With Particle releasing thier new Mesh products I think there is going to be more of a demand for Cayenne users wanting to use Particle devices with their projects. I have a number of projects I have had to switch up to using a NodeMCU instead of Photon for this reason. I love the Photon!


#25

@Tim_G_Tech photon support is on the roadmap, there are a lot of tasks to be completed before that and it will take time to release.


#26

I figured it was. I know you guys have a heavy workload already. Was just throwing something out there. I will be happy to do some beta testing when that time comes. Keep up the good work! :slight_smile:


#27

we let you know when we release and more than happy if you could do some testing on it :slightly_smiling_face:


#28

@Tim_G_Tech I set up a local MQTT server to mimic the Cayenne MQTT server (same user/pass/clientID) and I’m able to send data locally so I don’t believe it’s the device or MQTT library. I can even see that the photon is connecting (or it at least thinks it is) to the Cayenne server but as soon as it sends any data it’s being disconnected and the last data received on the dashboard doesn’t update. I pinged the slack group, waiting to hear back what’s going on at the server.


#29

Which library are you using specifically? I would like to try it. Thanks.


#30

It’s just called mqtt https://build.particle.io/libs/MQTT/0.4.27/tab/MQTT.cpp I think that link should work

You can use my code up a few posts if you want to test it.


#31

I took a loot at this MQTT library and compared with the Cayenne-Arduino-MQTT library downloaded from GitHub. It looks like there is a ton of stuff missing. Mostly a lot of other supporting libraries to make it all work properly.
I may attempt to fork it if I can make the time.
Here’s the link to the GitHub repo: https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino


#32

The only things missing will be the cayenne.virtual write, etc. You can still send properly formatted payloads. Have a look at my project here


#33

@Tim_G_Tech I found my mistake. I was putting in the wrong value for client ID. Try this code, it will just increment a temp widget.

// This #include statement was automatically added by the Particle IDE.
#include <DS18B20.h>
//DS18B20 ds18b20(D0);
// This #include statement was automatically added by the Particle IDE.
#include <MQTT.h>
void callback(char* topic, byte* payload, unsigned int length);
String username = "";
String password = "";
String clientID = "";
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() {
    Serial.begin(9600);
    delay(5000); // Allow board to settle
    client.connect(clientID, username, password);
}
int counter = 0;
void loop() {
    counter = counter + 1;
    
    if (client.isConnected()){
        Particle.publish("connected");
        client.loop();
    
        String mesasge = "temp,f=" + String(counter);
    
        client.publish("v1/" + username + "/things/" + clientID + "/data/1", mesasge);
    }
    
    delay(2000);
}

#34

Interesting. I’m glad you got it to work and thanks for sharing! I am going to try it out. I’ll post back my outcome.


#35

@adam you got your particle photon connected to cayenne and is sending data?


#36

Yep! With help from @ecoqba


#37

Nice :+1: