Adding a New Device using MQTT

this hasn’t worked either

When I chose the Arduino microcontroller, the board didn’t match the W1 D1 R1 that I use now. so the results still didn’t work, the serial monitor didn’t display anything

sorry, i mean wemos d1 r1

the above screenshot you shared is not what it should be if you had followed the steps i mentioned. So clearly you have not followed it.

in my opinion, it is exactly the steps above,

the only different board in the arduino editor I choose as shown below

read it properly, i mention on cayenne dashboard and not on arduino IDE

hallo, I want to ask, if when finished entering the username mqtt, mqtt password, clientid, ssid and wifi password, the cayenne browser immediately changes?

yes, it should show a blank dashboard once connected and then a green widget once the device publishes data.

what often causes waiting board connected? as shown below

still you not followed the steps. so i cannot help until then.

I have uploaded the esp8266 code, is there something wrong with the code, sir?
or is there a code that needs to be added?

/*
This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. If you have not already installed the ESP8266 Board Package install it using the instructions here: GitHub - esp8266/Arduino: ESP8266 core for Arduino.
  2. Select your ESP8266 board from the Tools menu.
  3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  4. Set the network name and password.
  5. Compile and upload the sketch.
  6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
    */

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.

char ssid = “sadfg”;
char wifiPassword = “opitert”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.

char username = “fhaahglaha-63hdjbaka-r8rbffahka”;
char password = “gyhajbabka-ajabkabka-ajkakhkakk”;
char clientID = “agjkanah-viaakakamcka-fgakbkabka”;

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

void loop() {
Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

do you understand english or which language are you comfortable? from last couple of reply i have told you to follow the steps but seems like you do not understand it.

create a new device on cayenne dashboard- add new —> devices/widget ----> microcontroller —> arduino —> next and you will get the screen showing MQTT credentials Copy the MQTT credentials into the code and upload.

I’m sorry I used a new account, because my account sarahbaras020 can’t be used anymore.

after I try the following steps like this results,
(I use the microcontroller wemos)

  1. create a new device on cayenne dashboard- ` add new —> devices/widget ----> microcontroller —

  1. then I got the MQTT Credential in cayenne dashboard

  2. then I copy the mqtt username, mqtt password and client id to Arduino IDE
    (Board : wemos d1 r1, Port : port 7)

  3. (Board : wemos d1 r1, Port : COM 7)

  4. finished uploading

  5. check serial monitor

  6. the display of the cayenne dashboard has been uploaded on the Arduino ID.
    the cayenne dashboard doesn’t change its appearance, it’s always pending

Ps:

  1. I am from Indonesia.

  2. i understand indonesian language and english sir language

  3. I stopped until the step. I really ask for help so you can help me.

Gb.

dont select “bring your own thing”. select arduino. that is what i am trying to explain from quite a long time but you never understand.

looking at the serial, it looks like your device never gets connected to the wifi.

thank you for responding, but the solution you provided is still not working. The following are the results of my trial

  1. I have chosen Arduino

ps:I am confused, I am using a Wemos d1r1 microcontroller, but why did you tell me to choose Arduino on cayenne?

  1. Check results from the serial monitor

sukses2

  1. There are no changes to Cayenne

Ps:

  1. Until now I have not succeeded in connecting the sensor to Cayenne. can you explain how wrong I am at what step

  2. The reason I chose “bring your own thing” to Cayenne, is because in the adding new device tutorial that you made, there the “bring your own thing” button is selected.

  3. please give instructions, sir. tomorrow morning I have to do my final project presentation about this, sir. I hope you can give the instructions.

first of all, your device is not connecting to the wifi, it is just stuck at connecting to baras which is the wifi you has specified in the code. make sure your wifi credentials are right or try connecting to another wifi.
there are some bug with bring your own thing that is why i suggested to use arduino.

thank you Sir… its work…

sorry if I have many questions :slight_smile:

1 Like

Sir, i have problem about sending data sensor temperature ds18b20 to cayene dashboad.

1.The following code that I have and the steps that I have done

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>

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

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “4986540g-966e-ahja0-dv877-15efasshgj686bf4”;
char password = “ee434x0bda91m9pce5l1lef6p4el9q8hffhd1cr5678”;
char clientID = “19c182f0-a476-11ea-so2e7eusso-6aga9yeh-ags3567”;

unsigned long lastMillis = 0;

#define SENSOR_PIN 2
OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);
float suhuSekarang;

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

void loop() {
Cayenne.loop();
suhuSekarang = ambilSuhu();
Serial.println(suhuSekarang);
delay(30);
}

float ambilSuhu()
{
sensors.requestTemperatures();
float suhu = sensors.getTempCByIndex(0);
return suhu;
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

  1. Display data out on the Arduino IDE serial monitor

  1. display that appears on the cayenne dashboard ()

Ps

  1. the data that comes out on the serial monitor on the Arduino IDE is not the same as the dashboard that appears on Cayenne
  2. I do not understand if I have a mistake sir?

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

thank you sir, for displaying body temperature on cayenne I have succeeded sir.

but to display the results of the heart rate sensor on the dashboard cayenne has not succeeded, sir

A. The following is the heart rate sensor code that I used, sir

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#define pulsePin A0

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

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “0bd74a6bd0-966e-1139d67f-15e30d90bbf4”;
char password = “eaf0-a476-11ea-883c-6-a491d98c1fbdc37c2”;
char clientID = “19c182e6434d8d8ce44e51cf624e9890c23d”;

#define VIRTUAL_CHANNEL 4

unsigned long lastMillis = 0;
const int postingInterval = 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;
#define ACTUATOR_PIN 3

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;

}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{

Cayenne.virtualWrite(4, millis());

Cayenne.virtualWrite(4,3);
}

CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
}

B. display on the serial monitor
** Ps**

  1. only connected to cayenne

  2. Does not display the results of the heartbeat sensor

  3. display on cayenne dashboard
    ** Ps**

  4. successfully displays channel 4

  5. but cannot display the results of the heart rate sensor

C. heart rate sensor circuit using wemos

jantung 3

Ps
I managed to display the channel on the Cayenne dashboard but didn’t issue a value on the dashboard

can you help me solve the problem sir?
I tried a few days but the results did not work, sir