Problems with photon publishing data

Firstly, i have been looking all morning at content online to try and solve this but i have no idea whats wrong.

I am unsure what my particle is doing, as it would connect, breath cyan or like 5 seconds and then flash green.
None of the code i flashed in those 5 seconds of connection (which flashed successfully) worked, even copied code.

today im just trying to read data from a DHT11 and publish it, simple, but nothing is coming up. (yes i checked the wiring)
I even just loaded a code only with Particle.publish line and still nothing,
on the console it logs the “device came online” and offline but nothing else.

I want to see if the DHT11 data is coming in, but i have no idea because i cant see values.

Thank you

Here is the code, copied from a tutorial

SYSTEM_THREAD(ENABLED) 

// Variables
int temperature;
int humidity;
int light;
// Pins
int light_sensor_pin = A1;
// DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
    
    // Start DHT sensor
    dht.begin();
}
void loop() {
    
    // Humidity measurement
    temperature = dht.getTempCelcius();
    
    // Humidity measurement
    humidity = dht.getHumidity();
    
    // Light level measurement
    float light_measurement = analogRead(light_sensor_pin);
    light = (int)(light_measurement/4096*100);
    
    // Publish data
    Particle.publish("temperature", String(temperature) + " °C");
    delay(2000);
    Particle.publish("humidity", String(humidity) + "%");
    delay(2000);
    Particle.publish("light", String(light) + "%");
    delay(2000);
    
}

Does safe mode work? If so, could you try flashing it when in safe mode?

Where are DHTPIN and DHTTYPE defined?
So is the include statement for the library missing.
You don’t seem to have copied the code completely.

Hence I doubt this code would ever be building without errors either.

@anthonydes, here is the minimum code needed to make the DHT work. Depending on which specific DHT you use (11, 22 or 2302), change the define. If you pick the wrong type, it will not work. Here is an easy way to remember:

white = DHT22
blue = DHT11
wire leads = AM2303 (configure as DHT22)

Don’t forget the resistor…10 KOhm between Vcc and data pin.

#include <Adafruit_DHT.h>

#define DHTTYPE     DHT22
#define DHTPIN      A0

DHT dht(DHTPIN, DHTTYPE);

float t, h;

dht.begin();
t = dht.getTempFarenheit();
h = dht.getHumidity();

// do something with the results

// minimum delay between reads
delay(2000);  
1 Like

Thank you everyone for replying and my apologies, i actually didnt select all of my code when i copied it to here, at the top there is

// This #include statement was automatically added by the Particle IDE.
#include “Adafruit_DHT/Adafruit_DHT.h”

// DHT parameters
#define DHTPIN 5
#define DHTTYPE DHT11

I am also getting power_down without doing anything

By this line of code it appears you were building your code for some older Device OS (system firmware).
Double check the selected target version, just to make sure.

BTW, I prefer this DHT library.

So, at uni today i tried the same code and set up with their particle and sensors and everything worked perfectly !

So i know that it isnt the code, it must be my stuff ?

Have you checked that?

1 Like

I checked it but i dont understand why it worked on the other particle and not mine?

The dht11 i was using until the new temp&humidity sensor i bought arrived. I got the dht11 to work at uni as i said earlier, so now im moving on to the si7021.

So i am using a new sensor that came today. the adafruit si7021.
I hooked it up, and ran the code but once again i got nothing in the console. The photon also still breathes cyan and then breathes green the rest of the time.

i dont understand why the power_down is happening ?
The console registers, resets, and the device coming on and off line.
it shouldnt be a wifi problem then?

I soldered the headers on it, could it be that i stuffed it up somehow?

The code is here.

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_Si7021.h>

Adafruit_Si7021 sensor = Adafruit_Si7021();
double h;
double t;

void setup() {
    sensor.begin();
    
    // Variable for IFTTT
    Particle.variable("t", &t, DOUBLE);
    Particle.variable("h", &h, DOUBLE);
}

void loop() {
    
    h = sensor.readHumidity();
    t = sensor.readTemperature();
    
    // Publish data
    String temperature = String(t);
    String humidity = String(h);
    
    temperature = temperature.format("%1.2f", t);

    Particle.publish("temperature", temperature, PRIVATE);
    
    delay(3000);
     
    Particle.publish("humidity", humidity, PRIVATE);
 
    delay(3000);
}

Everything seems normal, it just doesn’t put out any data

This usually indicates that the code gets stuck somewhere and stops servicing the cloud process.

You can add SYSTEM_THREAD(ENABLED) to prevent the breathing green, but to know where the code stalls you should add some debugging statements (e.g. Serial.println()) and check whether your checkpoints are reached or not.

How have you connected the devices?
Have you got some high-res images of your soldering?

So, good news, everything is working again moors7 was right. I put it into safe mode, flashed a blink led code and then reset it. After that is started working :slight_smile:

Ive taken this as a positive learning experience, and i would like to thank everyone for their help.
Moors7 thank you for your suggestion, sorry it took me so long to try it :expressionless:

3 Likes