- Device & model you are using : ESP8266 E12 module
- What dashboard are you using? (Web)
i used this code to control the builtin LED of ESP8266 E12 module and every thing was fine , i tried to use 2 switch buttons to control the LED and a DHT 11 sensor but sometimes when i turn on the sensor from the WEB dashboard, the LED button gets turned off by itself !!
can any one explain to me whats happening ?
NOTE: i modified the first 4 line so they appear , i was not able to use any hashtags
#include <CayenneMQTTESP8266.h>
#include <DHT.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#char ssid[] = "................";
char wifiPassword[] = ".............";
char username[] = "............................";
char password[] = "...........................";
char clientID[] = "....................";
DHT dht(D2, DHT11);
unsigned long lastMillis = 0;
float x = 0;
void setup() {
// put ur setup codes here, to run ONCE:
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(D7,OUTPUT) ;
digitalWrite(D7,HIGH);
pinMode(2,OUTPUT) ;
digitalWrite(2,HIGH);
for (int i=0;i<5; i++)
{
digitalWrite(2 ,HIGH);
delay(700);
digitalWrite(2 ,LOW);
delay(700);
}
}
void loop() {
// put ur main code here, to run repeatedly:
Cayenne.loop();
if (millis() - lastMillis > 1000) {
lastMillis = millis();
x= (lastMillis/1000);
Cayenne.virtualWrite(3, x);
}
float temp = dht.readTemperature(true); // fahrenhit
float hum = dht.readHumidity();
Cayenne.virtualWrite(1, temp, TYPE_TEMPERATURE, UNIT_FAHRENHEIT);
Cayenne.virtualWrite(2, hum , TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
delay (5000);
}
CAYENNE_IN(0)
{
int currentValue=getValue.asInt();
if(currentValue==0)
{
digitalWrite(2,HIGH);
}
else{
digitalWrite(2,LOW);
}
}
CAYENNE_IN(10)
{
int currentValue=getValue.asInt();
if(currentValue==1)
{
digitalWrite(D7,HIGH);
}
else{
digitalWrite(D7,LOW);
}
}