Adding a New Device using MQTT

can you show me the line in your code where it is sending the sensor data to cayenne.

Cayenne.virtualWrite(4,3);
for sending data to cayenne

it is showing value “4” on channel “3”. it is showing what you are sending.

can the heart rate sensor be used on cayenne?

in the above code, in which variable is the heart rate sensor data is stored? You just need to pass it in Cayenne.virtualWrite(4, data); where data is the variable.

I’m sorry sir, I used a code from the internet.
so I want to ask sir, is the code correct for the data
saved to Signal = analogRead (pulsePin); ?

please help me sir, I have tried it many times but it can’t work too, sir. please give directions, sir

first of all, remove cayenne code and just see if you getting heart rate sensor data in the serial monitor. This will help you understand the heart rate sensor code.

if we choose from Device / widget, what kind of sensor choice is suitable for heart rate sensor sir?

Did you try this?

Heart rate sensor is not officially supported but you can add any sensor to cayenne if you get the sensor reading correctly onto your arduino.

I deleted the code for Cayenne and tried to understand the code through the serial monitor. but the results only display channel 0 on the cayenne dashboard.

  1. The following code I took from comunity is titled (BPM using wemos d1r1)
    #define pulsePin A0
    #define CAYENNE_PRINT Serial
    #include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid = “Baras”;
char wifiPassword = “vespaantik”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “474a68ce51d9c311ea-a67f-15e30d90bbf4”;
char password = “e649c1ea-d8c182a68ce51d9c311ea-a67f0-a-c2”;
char clientID = “1c-638476-1966e-7e474a68ce51d9c311ea4c23d”;

const int postInterval = 10 * 1000;

int rate [10];
unsigned long sampleCounter = 0;
unsigned long lastBeatTime = 0;
unsigned long lastTime = 0, N;
int BPM = 0;
int IBI = 0;
int P = 512;
int T = 512;
int thresh = 512;
int amp = 100;
int Signal;
boolean Pulse = false;
boolean firstBeat = true;
boolean secondBeat = true;
boolean QS = false;

void setup () {
Serial.begin (115200);
Cayenne.begin (username, password, clientID, ssid, wifiPassword);
}

void loop () {
Cayenne.loop ();
if (QS == true) {
Serial.println (“BPM:” + String (BPM));
QS = false;
} else if (millis ()> = (lastTime + 2)) {
readPulse ();
lastTime = millis ();
}
}

void readPulse () {

Signal = analogRead (pulsePin);
sampleCounter + = 2;
int N = sampleCounter - lastBeatTime;

detectSetHighLow ();

if (N> 250) {
if ((Signal> thresh) && (Pulse == false) && (N> (IBI / 5) * 3))
pulseDetected ();
}

if (Signal <thresh && Pulse == true) {
Pulse = false;
amp = P - T;
thresh = amp / 2 + T;
P = thresh;
T = thresh;
}

if (N> 2500) {
thresh = 512;
P = 512;
T = 512;
lastBeatTime = sampleCounter;
firstBeat = true;
secondBeat = true;
}

}

void detectSetHighLow () {

if (Signal <thresh &&N> (IBI / 5) * 3) {
if (Signal <T) {
T = Signal;
}
}

if (Signal> thresh && Signal> P) {
P = Signal;
}

}

void pulseDetected () {
Pulse = true;
IBI = sampleCounter - lastBeatTime;
lastBeatTime = sampleCounter;

if (firstBeat) {
firstBeat = false;
return;
}
if (secondBeat) {
secondBeat = false;
for (int i = 0; i <= 9; i ++) {
rate [i] = IBI;
}
}

word runningTotal = 0;

for (int i = 0; i <= 8; i ++) {
rate [i] = rate [i + 1];
runningTotal + = rate [i];
}

rate [9] = IBI;
runningTotal + = rate [9];
runningTotal / = 10;
BPM = 60000 / runningTotal;
QS = true;

}
CAYENNE_OUT_DEFAULT ()
{
Cayenne.virtualWrite (0, BPM);
}

** Ps **
Cayenne.virtualWrite (0, BPM);

BPM = variable is the heart rate sensor data is stored
0 = channel number used on the cayenne dashboard.

  1. Chanel 0 display that has been successfully created but does not display data from the heart sensor.

Please help me Sir, I have tried but until now I have not managed to find a way out sir :frowning:

first see if you getting output from the sensor using:

BPM = 60000 / runningTotal;
println(BPM);

okey thank u sir. it is clear sir. :slight_smile: :slight_smile: :slight_smile:

Sir I want to ask again, can the contents of the message from the trigger on the Cayenne dashboard that we make can be changed?

My plan is just to send a notification if the heartbeat isn’t normal, sir. Can it be like that, sir?

please take direction, sir

The following is a sample notification that I got through the message Sir.

can you create a separate topic, it is populating this topic with non related stuff.

Sir, I want to ask, I have a project called the elderly health monitoring system.
which is where I use three types of sensors namely PIR sensor, body temperature sensor and heart rate sensor.

and using two Wemos D1 R1 microcontrollers, one is used for PIR sensors and the other is used for heart rate and body temperature sensors.

To connect to the Cayenne dashboard I use the same MQTT username, MQTT password, Client ID, SSID, and WiFi password.

which is the question

  1. When all three sensors are run using each of their microcontrollers simultaneously, is it possible that all three use the same IP address? and is it possible that the IP address can be changed or not settled?

  2. The second question, when running each sensor in the same time condition,
    Are the results of all three sensors sent simultaneously? or is the result of the shipment based on the channel number? or could there be a delay on each channel?

please help me sir, because I really need the answer sir.

For your attention I say thank you sir.

why you want to use two wemos when a single one can do all the thing. You can have same username and password but not client id. Each device connecting to cayenne should have unique client id. You cannot have same IP on both devices. The publish time is very fast so there is no delay when you are publishing two or more data.

The reason I use two wemos is because wemos that use PIR sensors will be attached to the room of the house by implementing 8 PIR sensors. and other wemos will be affixed to ArmBand which contains body temperature sensors and heart rate sensors for the elderly.

like I use wemos by implementing a body temperature sensor and a heart rate sensor that will be attached to the elderly arm. then the question becomes, if a successful heart rate sensor is detected and a body temperature sensor is unsuccessful, can the results of the two sensors not be sent? or only the heart rate sensor has been sent?

you can use a if condition to publish data.