Red Flash after calling function

Hello,

Not sure if this is the right thread for this but I hope it’s fine…

I’m not very familiar with programming and I’m getting red flashes on my photon after calling the following function. I followed the example code from the included libraries and tried to troubleshoot it myself but I don’t see what I’m missing.

// This #include statements add functionality for the humidity Sensor 
#include <DHT.h>
#include <Adafruit_Sensor.h>

#define DHTTYPE DHT11
#define DHTPIN 	D2
int Humidity,Temperature;
DHT dht(DHTPIN, DHTTYPE);

SYSTEM_MODE(SEMI_AUTOMATIC);
/* This function is called once at start up ----------------------------------*/
void setup()
{
    
    WiFi.on();
    Particle.function("CheckSensor", Dht);

   //-----------------------------------------------------------------------------
   //Register the functions for the sensor
  Serial.begin(9600);
  dht.begin();  
 
}    
  // It's important to do this here, inside the setup() function rather than outside it or in the loop function.
void loop()
{}

int Dht(String command) 
{if (command=="on") {
	//Read Humidity
	int h = dht.readHumidity();
	
    // Read temperature as Celsius
    int t = dht.readTemperature();
    
    
    Humidity=(int)h;
    Temperature=(int)t;    
    delay(2000); 
   //Take temperature and humidity readings and publish the results
   Particle.publish("Temperature", String(Temperature) + "°C");
   delay(2000); 
   // Wait a few seconds between measurements.
   Particle.publish("Humidity", String(Humidity) + "%");
   delay(2000); 

}}

You have no return statement in your function but the int Dht() signature demands your code to return an integer.

1 Like

Thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.