NodeMCU compiling error with Cayenne

Noob here -

I’m trying to build a remote temp monitor using a DHT22 and ESP8266 NodeMCU. I found some coding on a project website but I keep getting an error while trying to compile it.

Here is the code -


#include <dht.h>

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <DHT.h>

#define DHTPIN D5 // what pin the DHT is connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)

const int TEMPERATURE_INTERVAL = 30;
unsigned long last_temperature_sent = 0;

const int HUMIDITY_INTERVAL = 30;
unsigned long last_humidity_sent = 0;
String display_temp;
String display_humid;

DHT dht(DHTPIN, DHTTYPE);

// Your network name and password.
char ssid[] = “”;
char wifiPassword[] = “”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “”;
char password[] = “”;
char clientID[] = “”;

 

void getSendTemperature() {
if (millis() – last_temperature_sent >= TEMPERATURE_INTERVAL * 1000UL || last_temperature_sent == 0) {
float temperature = dht.readTemperature(true);

if (isnan(temperature)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
display_temp = temperature;
Serial.print(“Temperature: “);
Serial.print(temperature);

Serial.println(” °F”);
Cayenne.virtualWrite(8, temperature);
last_temperature_sent = millis();
}
}

void getSendHumid() {
if (millis() – last_humidity_sent >= HUMIDITY_INTERVAL * 1000UL || last_humidity_sent == 0) {
float humidity = dht.readHumidity();

if (isnan(humidity)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
display_humid = humidity;
Serial.print(“Humidity: “);
Serial.print(humidity);
Serial.println(” %”);
Cayenne.virtualWrite(9, humidity);
last_humidity_sent = millis();
}
}

 

 

void setup() {
// put your setup code here, to run once:
Serial.begin(230400);
dht.begin();
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
// put your main code here, to run repeatedly:
getSendTemperature();
getSendHumid();
Cayenne.loop();
}

//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(“CAYENNE_IN_DEFAULT(%u) – %s, %s”, request.channel, getValue.getId(), getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

#define DHTPIN D5 // what pin the DHT is connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)

const int TEMPERATURE_INTERVAL = 30;
unsigned long last_temperature_sent = 0;

const int HUMIDITY_INTERVAL = 30;
unsigned long last_humidity_sent = 0;
String display_temp;
String display_humid;

DHT dht(DHTPIN, DHTTYPE);

// Your network name and password.
char ssid[] = “Your WiFi SSID”;
char wifiPassword[] = “Your WiFi PWD”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “Your Cayenne MQTT Username”;
char password[] = “Your Cayenne MQTT Password”;
char clientID[] = “Your Cayenne MQTT Client ID”;

void getSendTemperature() {
if (millis() – last_temperature_sent >= TEMPERATURE_INTERVAL * 1000UL || last_temperature_sent == 0) {
float temperature = dht.readTemperature(true);

if (isnan(temperature)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
display_temp = temperature;
Serial.print(“Temperature: “);
Serial.print(temperature);

Serial.println(” °F”);
Cayenne.virtualWrite(8, temperature);
last_temperature_sent = millis();
}
}

void getSendHumid() {
if (millis() – last_humidity_sent >= HUMIDITY_INTERVAL * 1000UL || last_humidity_sent == 0) {
float humidity = dht.readHumidity();

if (isnan(humidity)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
display_humid = humidity;
Serial.print(“Humidity: “);
Serial.print(humidity);
Serial.println(” %”);
Cayenne.virtualWrite(9, humidity);
last_humidity_sent = millis();
}
}

void setup() {
// put your setup code here, to run once:
Serial.begin(230400);
dht.begin();
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
// put your main code here, to run repeatedly:
getSendTemperature();
getSendHumid();
Cayenne.loop();
}

//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(“CAYENNE_IN_DEFAULT(%u) – %s, %s”, request.channel, getValue.getId(), getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

Below here is the error message(s) that I’m receiving. I’m about to pull my hair out trying to figure this out.

Arduino: 1.8.9 (Windows 7), Board: “NodeMCU 0.9 (ESP-12 Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

DHT22:89:108: error: macro “CAYENNE_IN_DEFAULT” passed 1 arguments, but takes just 0

CAYENNE_LOG(“CAYENNE_IN_DEFAULT(%u) – %s, %s”, request.channel, getValue.getId(), getValue.asString());

                                                                                                        ^

DHT22:168:108: error: macro “CAYENNE_IN_DEFAULT” passed 1 arguments, but takes just 0

CAYENNE_LOG(“CAYENNE_IN_DEFAULT(%u) – %s, %s”, request.channel, getValue.getId(), getValue.asString());

                                                                                                        ^

exit status 1
macro “CAYENNE_IN_DEFAULT” passed 1 arguments, but takes just 0

Thank you in advance for helping a new guy out.

-Miles

Hi @MilesL

Try this simpler sample:

    // Tinkernlearn.com - This example shows how to connect the Wemos D1 pro & DHT11 with Cayenne using MQTT 

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

DHT12 dht12;

// WiFi network info.
char ssid[] = "WIFI_SSID";
char wifiPassword[] = "WIFI_PASSWORD";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "MQTT_CLIENT_ID";

unsigned long lastMillis = 0;

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

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();

    if(dht12.get()==0){
      Cayenne.celsiusWrite(1, dht12.cTemp);
      Cayenne.virtualWrite(2, dht12.fTemp, TYPE_TEMPERATURE, UNIT_FAHRENHEIT);
      Cayenne.virtualWrite(3, dht12.humidity, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
    }
	}
}

//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("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
	//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

I apologize. I should have mentioned the hardware I’m using.

I’m using a ESP8266 nodeMCU and a DHT22.

I’m not sure which library the wemos_dht12 comes from…

Hi @MilesL welcome to cayenne community.
Try to use optimised DHT library for nodemcu and esp32. You can get it from GitHub.

I am using it with out any problem.

Follow this tutorial and get DHT reading on your nodemcu https://learn.adafruit.com/dht/using-a-dhtxx-sensor
Once done you can add the DHT code in your this code https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/master/examples/Connections/ESP8266/ESP8266.ino

This was the best advice I have gotten.

I was able to get my board to read temperatures through dht test. Then separately I was able to get my board online with Cayenne.

After that I was able to cobble together code to get them both working together.

Thank you.

1 Like