When i turn on load device turns offline
Heres the code:
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266Shield.h>
#include <Ultrasonic.h>
#include "DHT.h"
#define trigPin 12
#define echo 13
int led=LOW;
int led1=LOW;
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
Ultrasonic ultrasonic(12, 13);
char ssid[] = "";
unsigned long lastMillis = 0;
char wifiPassword[] = "";
char username[] = "";
char password[] = "";
char clientID[] = "";
#define EspSerial Serial
ESP8266 wifi(&EspSerial);
float time=0,distance=0;
void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, INPUT);
pinMode(8, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(trigPin,OUTPUT);
pinMode(echo,INPUT);
Serial.begin(9600);
delay(10);
EspSerial.begin(115200);
delay(10);
Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}
void loop()
{
Cayenne.loop();
}
CAYENNE_OUT(1){ int duration,distance,percentage,heightTank,deviation;
heightTank=12;
deviation=2;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin,LOW);
duration=pulseIn(echo,HIGH);
distance=(duration/2)/29.1;
percentage=100-(((distance-deviation)*100)/heightTank);
Cayenne.virtualWrite(1,percentage);}
CAYENNE_OUT(2){if(millis() - lastMillis > 500000) {
lastMillis = millis();
Cayenne.virtualWrite(2,dht.readHumidity());}}
CAYENNE_OUT(3){if(millis() - lastMillis > 500000) {
lastMillis = millis();
Cayenne.virtualWrite(3,dht.readTemperature());}}
CAYENNE_IN(4) {
int value = getValue.asInt();
digitalWrite(4, value);
}
CAYENNE_IN(5) {
int value = getValue.asInt();
digitalWrite(5, value);
led=value;
}
CAYENNE_OUT(6){if(millis() - lastMillis > 200) {
lastMillis = millis();
Cayenne.virtualWrite(6,analogRead(A0));}}
CAYENNE_OUT(7){ if (digitalRead(6) == HIGH)
{
Cayenne.virtualWrite(7,HIGH);}
else
{
Cayenne.virtualWrite(7,LOW);}}
CAYENNE_OUT(8){ if (digitalRead(8) == HIGH)
{
Cayenne.virtualWrite(8,HIGH);}
else
{
Cayenne.virtualWrite(8,LOW);}}
your code looks fine. can you just use the basic code and give it a try to find out whether actuator is causing the offline.
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266Shield.h>
char ssid[] = "";
unsigned long lastMillis = 0;
char wifiPassword[] = "";
char username[] = "";
char password[] = "";
char clientID[] = "";
#define EspSerial Serial
ESP8266 wifi(&EspSerial);
void setup()
{
pinMode(5, OUTPUT);
Serial.begin(9600);
delay(10);
EspSerial.begin(115200);
delay(10);
Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}
void loop()
{
Cayenne.loop();
}
CAYENNE_IN(5) {
int value = getValue.asInt();
digitalWrite(5, value);
}
What kind of load does your relay controls?