How do I get values to post to Spark Cloud

Not sure why my code isn’t working to publish to the cloud thing. I want to see a constant stream of the values from the DHT22 sensor I’m using for this.

I know there isn’t a dashboard of graphs for this yet to visualize data. Does anyone recommend one? Is Adafruit.io compatible with the Particle Photon yet?

#include "Adafruit_DHT/Adafruit_DHT.h"

#define DHTPIN 2     // what pin on the DHT we're connected to (also seems to be the one on the photon? idfk)
#define DHTTYPE DHT22		// DHT 22 (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() 
{
	Serial.begin(8000); 
	Particle.publish("startup", "Initializing Sausage-Fridge Monitor");

	dht.begin();
}

void loop() 
{
	delay(1000);

	float h = dht.getHumidity();
	float f = dht.getTempFarenheit();
  
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(f))
	{
		Particle.publish("error","Can't read data from sensor!");
		return;
	}
	
// Print To Particle Cloud

// Print To Console
	Serial.print("\nHumidity: "); 
	Serial.print(h);
	Serial.print("% - ");
	
	Serial.print("\nTemperature: "); 
	Serial.print(f);
	Serial.print("*F -");

	Serial.println(Time.timeStr());
}

Was there supposed to be a call to Particle.publish() below this line?

Thats where I want to do all the particle publishing. I just don’t know how to send the values inside of a publish call.

Ah, got it. The way I’d do it is like so:

Particle.publish("temp_f", String(f));

You can use sprintf if you need to do any formatting during conversion to string.

1 Like