Device gets disconnected after 30-40 seconds


#1

#include <CayenneMQTTESP8266Shield.h>
#include <Ultrasonic.h>
#include "DHT.h
#define CAYENNE_DEBUG // Uncomment to show debug messages

#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int flowPin = 2; //This is the input pin on the Arduino
double flowRate; //This is the value we intend to calculate.
volatile int count;
#include <CayenneTemperature.h>
char ssid[] = “NETGEAR92”;
char wifiPassword[] = “waterychair234”;
char username[] = “953984c0-6624-11e7-9c17-adc0b1d0cf53”;
char password[] = “976d0b8359210203a75feba0170a8b347aa3a637”;
char clientID[] = “83ad0e50-16f7-11e8-9f38-9fae3d42ebf0”;
#define EspSerial Serial
ESP8266 wifi(&EspSerial);
const int thermistorPin = 0;
const float resistance = 19800;
Thermistor thermistor(A0, 19800);
int led = LOW;
int led1 = LOW;
int led2 = LOW;
int led3 = LOW;
Ultrasonic ultrasonic(12, 13);

void setup()
{
pinMode(3, OUTPUT); // button
pinMode(4, OUTPUT);
pinMode(7, INPUT);
pinMode(flowPin, INPUT); //Sets the pin as an input
attachInterrupt(0, Flow, RISING);
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(115200);
delay(10);

Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}

void loop()
{
Cayenne.loop();
}

CAYENNE_IN(1) {
int value = getValue.asInt();
digitalWrite(3, value);
}

CAYENNE_IN(2) {
int value = getValue.asInt();
digitalWrite(4, value);
}
CAYENNE_OUT(5)
{
Cayenne.celsiusWrite(5, thermistor.getCelsius());
delay(10);
}
CAYENNE_OUT(6)
{
Cayenne.virtualWrite(6, ultrasonic.distanceRead());
}

CAYENNE_OUT(9){
float h = dht.readHumidity();
Cayenne.virtualWrite(9,h);
}
CAYENNE_OUT(10){
float t = dht.readTemperature();
Cayenne.virtualWrite(10,t);}

CAYENNE_OUT(11)
{count = 0; // Reset the counter so we start counting from 0 again
interrupts(); //Enables interrupts on the Arduino
delay (1000); //Wait 1 second
noInterrupts(); //Disable the interrupts on the Arduino

//Start the math
flowRate = (count * 2.25); //Take counted pulses in the last second and multiply by 2.25mL
flowRate = flowRate * 60; //Convert seconds to minutes, giving you mL / Minute
flowRate = flowRate / 1000; //Convert mL to Liters, giving you Liters / Minute
Cayenne.virtualWrite(11,flowRate);

}
void Flow()
{
count++; //Every time this function is called, increment “count” by 1
}


#2

@mohdsufiyanhussain you have created two different topic. use only one to post all your problem.


#3

I see you are messing with interrupts. I wonder if this is impacting things.