Data not updating when i add temp sensor

HI IM BEGINNER AND NEED HELP. I HAVE A CODE WHICH RUNS PERFECTLY AND DATA UPDATES EVERY 2 SECONDS BUT WHEN I ADD ANOTHER SENSOR IN THE CODE THE DEVICE GOES OFFLINE.
HERES THE CODE:

#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include <Ultrasonic.h>
#include "DHT.h"
#include "thermistor.h"
#include "HardwareSerial.h"
#define NTC_PIN               A0
THERMISTOR thermistor(NTC_PIN,        // Analog pin
                      10000,          // Nominal resistance at 25 ºC
                      3950,           // thermistor's beta coefficient
                      10000);         // Value of the series resistor
#define DHTPIN 7
uint16_t temp;

#define DHTTYPE DHT11   
DHT dht(DHTPIN, DHTTYPE);
Ultrasonic ultrasonic(12, 13);
char ssid[] = "NETGEAR92";
char wifiPassword[] = "waterychair234";
char username[] = "";
char password[] = "";
char clientID[] = "";
#define EspSerial Serial
ESP8266 wifi(&EspSerial);

void setup()
{
  Serial.begin(9600);
  delay(10); 
  EspSerial.begin(115200);
  delay(10);
  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);

  }

void loop()
{
  Cayenne.loop();
     float temp = thermistor.read();   // Read temperature

}

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

  Cayenne.virtualWrite(11,temp);
}

THE CAYENNE OUT 11 MAKES DEVICE GO OFFLINE

hey there @mohdsufiyanhussain,

It’s always best to delete your credentials after copy paste. It’s like giving out cake to the enemy.

Dumb question, have you tried refreshing page or waiting some more time for it to go back online? My boards tends to go offline for sometime when I make changes. Many times I have had to reresh.

Regards

@mohdsufiyanhussain first of all is your board online with basic cayenne code with adding sensor?.
next are you able to read to read sensor data on your serial monitor?

@mohdsufiyanhussain,

Change uint16_t temp; to float temp;

Then in your main loop, delete float.

The uint16_t temp is what you are writing out in your (11) function. The temp in your main loop is local to your main loop and not shared.

If you follow my directions, you are making temp global and thus it can be assigned in the main loop and used in the (11) function.

@rsiegel, there may be a bug passing an uninitialized uint16_t to virtualWrite.

Cheers,

Craig

yes
ultrasonic works fine