Hi,
I’m Andrew and very new here.
coding skills are mediocre at best, dabbled in plenty of coding languages, enough to be a bit familiar then I lose interest and try another, so I may be mixing it up a bit by mistake.
I’ve done some trawling through a tonne of posts on various forums, but can’t seem to find much information for the BME280 on Cayenne and can’t seem to figure out this error.
I managaged to get it compiling with just the relay module and even added a bit of code I found on here for the addition of a DHT11 with no problems, but run into issues with the BME280.
The code posted below is a mixture of about 6 projects i’ve found and merged as well as my own input, I’m sure its something simple, but the extra help/guidence would be greatly appreciated.
Project running on a NodeMCU 1.0
Cheers
Andrew
#include <CayenneMQTTESP8266.h>
#include <Wire.h>
#include <SPI.h>
#include <DFRobot_BME280.h>
#define SEA_LEVEL_PRESSURE 1013.25f
#define Relay1 D1
#define Relay2 D2
#define Relay3 D3
#define Relay4 D4
#define Relay5 D5
#define Relay6 D6
#define Relay7 D7
#define Relay8 D8
#define SEALEVELPRESSURE_HPA (978.36)
DFRobot_BME280 bme;
// WiFi network info.
char ssid[] = "MyWIFI";
char wifiPassword[] = "Superduperhardpassword";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "usename goes here";
char password[] = "Cayenne project password";
char clientID[] = "clientID";
float temp, pressure, hum, alt;
void setup()
{
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
pinMode(Relay6, OUTPUT);
pinMode(Relay7, OUTPUT);
pinMode(Relay8, OUTPUT);
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, HIGH);
digitalWrite(Relay4, HIGH);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, HIGH);
digitalWrite(Relay7, HIGH);
digitalWrite(Relay8, HIGH);
Cayenne.loop();
//Send BME280 data to Cayenne
Cayenne.virtualWrite(0, temp); //Send temperature
Cayenne.virtualWrite(1, pressure); // Send pressure
Cayenne.virtualWrite(2, hum); // Send humidaty
}
void Get_Values()
{
temp = bme.temperatureValue();
pressure = bme.pressureValue() / 100.0F;
hum = bme.humidityValue();
alt = bme.altitudeValue(SEA_LEVEL_PRESSURE);
delay(100);
//print sensor data
Serial.println("Collect data");
Serial.print("Temperature :");
Serial.print(temp);
Serial.println(" C");
Serial.print("Pressure:");
Serial.print(pressure);
Serial.println(" hPa");
Serial.print("Humidity :");
Serial.print(hum);
Serial.println(" %");
Serial.print("Approx. Altitude:");
Serial.print(alt);
Serial.println(" m");
Serial.println("------END------");
}
// Relay wired as normally open low activation
CAYENNE_IN(1)
{
int status = getValue.asInt();
if (status == 0) {
digitalWrite(Relay1, LOW);
} else {
digitalWrite(Relay1, HIGH);
}
}
CAYENNE_IN(2)
{
int status = getValue.asInt();
if (status == 0) {
digitalWrite(Relay2, LOW);
} else {
digitalWrite(Relay2, HIGH);
}
}
CAYENNE_IN(3)
{
int status = getValue.asInt();
if (status == 0) {
digitalWrite(Relay3, LOW);
} else {
digitalWrite(Relay3, HIGH);
}
}
CAYENNE_IN(4)
{
int status = getValue.asInt();
if (status == 0) {
digitalWrite(Relay4, LOW);
} else {
digitalWrite(Relay4, HIGH);
}
}
CAYENNE_IN(5)
{
int status = getValue.asInt();
if (status == 0) {
digitalWrite(Relay5, LOW);
} else {
digitalWrite(Relay5, HIGH);
}
}
CAYENNE_IN(6)
{
int status = getValue.asInt();
if (status == 0) {
digitalWrite(Relay6, LOW);
} else {
digitalWrite(Relay6, HIGH);
}
}
CAYENNE_IN(7)
{
int status = getValue.asInt();
if (status == 0) {
digitalWrite(Relay7, LOW);
} else {
digitalWrite(Relay7, HIGH);
}
}
CAYENNE_IN(8)
{
int status = getValue.asInt();
if (status == 0) {
digitalWrite(Relay8, LOW);
} else {
digitalWrite(Relay8, HIGH);
}
}