Virtual pins not available on my dashboard


#1

I am trying to set up my dashbord to connect to display data from a DHT22 connected to a NodeMCU. In the guidlines it’s done using a custom widget and virtual pins - but I can’t choose virtual pins in the custom widget. They are no in the drop down menus.
Any ideas?


#2

@Craftbrewer Will appear after you selected your device:


#3

@Craftbrewer are you using MQTT or regular connection?


#4

Not in my dashboard. As you see the channel select box stays dimmed. I can write in the box, but it does not seem to accept the entry.


#5

I am using MQTT.


#6

in Mqtt you had add the number yourself in the channel field.
for example if your code is:

CAYENNE_IN(1)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
  }
}

then you have add channel as 1.


#7

Your suggestion works for me when using af button. But not for a virtual pin.

I have tried V0 for virtual pin 0. Does not work for me though.

My code:
}
CAYENNE_OUT(V0)
{

	Cayenne.virtualWrite(V0, temperature);

}


#8

for sending data to cayenne using MQTT use this:

void loop() {
	Cayenne.loop();

	//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
	if (millis() - lastMillis > 10000) {
		lastMillis = millis();
		//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
		Cayenne.virtualWrite(0, temperature);

	}
}

this will show a value widget on your dashboard. add it and then change the name and icon by clicking on setting icon.


#9

Hi @Craftbrewer to be honest there is room for some improvement:

  • utilise the power of this community; searching a bit is required; it is not so hard to find ESP8266 MQTT Virtual Pins+DHT22 with a complete answer. Despite some anying errors in the sketch (Incorrect print line characters and for me a missing Adafruit library) you do not need to do anything in Cayenne. My result with any further actions (after sketch properly compiled for x time) looks like this:

  • When your problem is new try to be complete so my assumption could be avoided and the better question from @shramiksalgaonkar was not required. Always helpfull are device, sketch and prints.


#10

shramiksalgaonkar & wj4me - Thanks for helping this ignorant (me!).

I got it working, although I don’t understand all my code - but here it is. I have a relay and a DHT22 connected:

#include <CayenneMQTTESP8266.h>
#include “DHT.h”
#include <CayenneDefines.h>

#define DHTPIN 12 // what digital pin the DHT22 is conected to
#define DHTTYPE DHT22 // there are multiple kinds of DHT sensors
DHT dht(DHTPIN, DHTTYPE);
float h;
float t;

//#include <CayenneMQTTESP8266.h>

#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char username[] = “xxxxxx”;
char mqtt_password[]=“xxxf”;
char client_id[]=“xxxx”;
char ssid[] = “xxxx”;
char password[] = “xxxx”;

void setup()
{
dht.begin();
Serial.begin(115200);

Cayenne.begin(username, mqtt_password, client_id, ssid, password);
pinMode(D4,OUTPUT);
digitalWrite(D4,HIGH);
}

void loop()
{
Kald_DHT();
Kald_til_Cayenne();
}

void Kald_DHT()
{
h = dht.readHumidity();
t = dht.readTemperature();
Serial.println(h);
Serial.println(t);
}

void Kald_til_Cayenne()
{
Cayenne.loop();

Cayenne.virtualWrite(2, t, "temp", "c");
Cayenne.virtualWrite(1, h, "rel_hum", "p");

}

CAYENNE_IN(0)
{
digitalWrite(D4, !getValue.asInt());
}


#11

@Craftbrewer no problem at all. we are here to help you. if you need any more help please ask and good to hear that you got your problem solved.


#12

just made some small changes to your code and let me know what you dint understand.

#include <CayenneMQTTESP8266.h>
#include “DHT.h”
#include <CayenneDefines.h>

#define DHTPIN 12 // what digital pin the DHT22 is conected to
#define DHTTYPE DHT22 // there are multiple kinds of DHT sensors
DHT dht(DHTPIN, DHTTYPE);
float h;
float t;

//#include <CayenneMQTTESP8266.h>

#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char username[] = “xxxxxx”;
char mqtt_password[]=“xxxf”;
char client_id[]=“xxxx”;
char ssid[] = “xxxx”;
char password[] = “xxxx”;

void setup()
{
dht.begin();
Serial.begin(115200);

Cayenne.begin(username, mqtt_password, client_id, ssid, password);
pinMode(D4,OUTPUT);
digitalWrite(D4,HIGH);
}

void loop()
{
Cayenne.loop();
h = dht.readHumidity();
t = dht.readTemperature();
Serial.println(h);
Serial.println(t)    
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
	lastMillis = millis();
            Cayenne.virtualWrite(2, t, "temp", "c");
            Cayenne.virtualWrite(1, h, "rel_hum", "p");
    }    
}
CAYENNE_IN(0)
{
digitalWrite(D4, !getValue.asInt());
}

#13

Hi @Craftbrewer no problem and sorry, I am just a blunt Dutch guy and to be a honest I can pop my own question and find 5 seconds later the answer (or not) . BTW do not understand why it is so humid in your place. Scandinavia, Sweden? And what kind of beer do you craft?

BTW this was my second experience with MQTT myself and would have been clueless till I found this example.
Anyone is there an overview how to address sensors like example Cayenne.virtualWrite(2, t, “temp”, “c”);
(and yes did not push the search button first)


#14

What I don’t understand is why Cayenne.virtualWrite is just a ‘line statement’ and digitalWrite.is ‘wrapped’ like this:

CAYENNE_IN(0)
{
digitalWrite(D4, !getValue.asInt());
}


#15

It’s not that humid here in Denmark. I just held it in my hand to see a response. BTW, i don’t trust the DHT22, so I substituted it with BME280.
I brew all beer style. This time of year I brew lager. Right now a Munchener Dunkel is taking up space in my fermenter.


#16

what you are trying to say is why Cayenne.virtualWrite is not in:

Cayenne_OUT(0)
{
            Cayenne.virtualWrite(2, t, "temp", "c");
}

for all your answer have a look at this Converting Cayenne Arduino LIbrary sketches to Cayenne MQTT Arduino


#17

Yes.


#18

Also helpful is this article Data types for Cayenne MQTT API. Just sharing, had some problem finding it myself :grin:


#19

@Craftbrewer Cayenne.virtualWrite sends data to the Cayenne servers while digitalWrite is changing the state of the pins on your device. Does that make sense?