How to Display the Temperature readings?

Hi @csh13

Try safe mode and then flash clean code:

https://docs.particle.io/guide/getting-started/modes/photon/#safe-mode

Normally blinking green means that the code you put on the device is blocking the cloud service.

1 Like

so why are we chasing the Particle.publish() red herring?

do you have the CLI installed?

2 Likes

Thank you! it works now.
One more Question, what does this mean?
/src/dht_example.cpp:129:1: error: expected unqualified-id before ‘{’ token
Blynk.notify("You pressed the button and I know it ");

impossible to see the real cause without the code, but I’d guess there is a semicolon wedged in to a function definition like this

void myFunction();  // <<<<<<< semicolons don't belong here!!!
{
  //function thingies here 
}
2 Likes

Please don’t blame the photon before ruling out all possible causes on your end. Malfunctioning code is more than capable of ‘crashing’ devices or making them unable to connect. The people that have responded here are highly experienced with Particle, and when the majority wants to look at your code, there’s a good chance there’s something wrong with it.
Long story short, if you’re asking for help, please be willing to provide the resources we ask for, if you’re expecting us to be able to help.

3 Likes

Ok, for some reason the repeater that I had been trying to connect to was not working. I unplugged it and now the photon is working perfect. thank you so much for your patients and effort.
I still cant figure out[quote=“csh13, post:63, topic:7968”]
/src/dht_example.cpp:129:1: error: expected unqualified-id before ‘{’ token Blynk.notify("You pressed the button and I know it ");
[/quote]

And neither can we since you won’t post your code. If you expect to get help, then post your code, and indicate which line is line 129.

4 Likes

Oh I get it! Its at line 129 !!
Yay thank you!!!

Hmm, what a surprise when looking a the error message

3 Likes

Well I’m not all that of an expert on error messages…

Btw, how do I fix the green breathe (connected to Wifi but not cloud)?

Post. Your. Code.

1 Like
/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social groups:              http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 *
 * No coding required for direct digital/analog pin operations!
 *
 * WARNING: It is recommended to use SparkCorePolledTimer library
 *          to make periodic actions (similar to SimpleTimer on Arduino).
 *
 **************************************************************/

#define BLYNK_PRINT Serial  // Set serial output for debug prints
//#define BLYNK_DEBUG       // Uncomment this to see detailed prints

#include "blynk.h"

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*****************";

// Attach a Button widget (mode: Switch) to the Digital pin 7 - and control the built-in blue led.
// Attach a Graph widget to Analog pin 1
// Attach a Gauge widget to Analog pin 2








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

/*
 * FILE:        DHT_example.cpp
 * VERSION:     0.4
 * PURPOSE:     Example that uses DHT library with two sensors
 * LICENSE:     GPL v3 (http://www.gnu.org/licenses/gpl.html)
 *
 * Example that start acquisition of DHT sensor and allows the
 * loop to continue until the acquisition has completed
 * It uses DHT.acquire and DHT.acquiring
 *
 * Change DHT_SAMPLE_TIME to vary the frequency of samples
 *
 * Scott Piette (Piette Technologies) scott.piette@gmail.com
 *      January 2014        Original Spark Port
 *      October 2014        Added support for DHT21/22 sensors
 *                          Improved timing, moved FP math out of ISR
 *      September 2016      Updated for Particle and removed dependency
 *                          on callback_wrapper.  Use of callback_wrapper
 *                          is still for backward compatibility but not used
 */











#include "PietteTech_DHT.h"  // Uncomment if building in IDE
//#include "PietteTech_DHT.h"                 // Uncomment if building using CLI

// system defines
#define DHTTYPE  DHT22              // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   D3         	    // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   2000  // Sample every two seconds

/*
 * NOTE: Use of callback_wrapper has been deprecated but left in this example
 *       to confirm backwards compabibility.  Look at DHT_2sensor for how
 *       to write code without the callback_wrapper
 */
//declaration
void dht_wrapper();// must be declared before the lib initialization

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

// globals
unsigned int DHTnextSampleTime;	    // Next time we want to start sample
bool bDHTstarted;		    // flag to indicate we started acquisition
int n;                              // counter

void setup()
{
    Serial.begin(9600);
    delay(5000); // Allow board to settle

    Blynk.begin(auth);
}

// Attach a Button widget (mode: Push) to the Virtual pin 1 - and send sweet tweets!
BLYNK_WRITE(V1)
{
    if (param.asInt() == 1)
    {   
        // On button down...
        // Tweeting!
        // Note:
        //   We allow 1 tweet per minute for now.
        //   Twitter doesn't allow identical subsequent messages.
        Blynk.tweet("My Particle project is tweeting using @blynk_app and it’s awesome!\n @Particle #IoT #blynk");
        // Pushing notification to the app!
        // Note:
        //   We allow 1 notification per minute for now.
        Blynk.notify("You pressed the button and I know it");
        
    }
}


/*
    Serial.begin(9600);
    while (!Serial.available()) 
    {
        Serial.println("Press any key to start.");
		Particle.process();
        delay (1000);
    }
    Serial.println("DHT Example program using DHT.acquire and DHT.aquiring");
    Serial.print("LIB version: ");
    Serial.println(DHTLIB_VERSION);
    Serial.println("---------------");

    DHTnextSampleTime = 0;  // Start the first sample immediately

*/
/*
 * NOTE:  Use of callback_wrapper has been deprecated but left in this example
 * to confirm backwards compatibility.
 */
// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper()
{
    DHT.isrCallback();
}

void loop()
{
  // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
	if (!bDHTstarted) {		// start the sample
	    Serial.print("\n");
	    Serial.print(n);
	    Serial.print(": Retrieving information from sensor: ");
	    DHT.acquire();
	    bDHTstarted = true;
	}

	if (!DHT.acquiring())
	{		// has sample completed?

	    // get DHT status
	    int result = DHT.getStatus();
        int Tempf = (int)DHT.getFahrenheit();
        
	    Serial.print("Read sensor: ");
	    switch (result) {
		case DHTLIB_OK:
		    Serial.println("OK");
		    break;
		case DHTLIB_ERROR_CHECKSUM:
		    Serial.println("Error\n\r\tChecksum error");
		    break;
		case DHTLIB_ERROR_ISR_TIMEOUT:
		    Serial.println("Error\n\r\tISR time out error");
		    break;
		case DHTLIB_ERROR_RESPONSE_TIMEOUT:
		    Serial.println("Error\n\r\tResponse time out error");
		    break;
		case DHTLIB_ERROR_DATA_TIMEOUT:
		    Serial.println("Error\n\r\tData time out error");
		    break;
		case DHTLIB_ERROR_ACQUIRING:
		    Serial.println("Error\n\r\tAcquiring");
		    break;
		case DHTLIB_ERROR_DELTA:
		    Serial.println("Error\n\r\tDelta time to small");
		    break;
		case DHTLIB_ERROR_NOTSTARTED:
		    Serial.println("Error\n\r\tNot started");
		    break;
		default:
		    Serial.println("Unknown error");
		    break;
	    }

	    Serial.print("Humidity (%): ");
	    Serial.println(DHT.getHumidity(), 2);

	    Serial.print("Temperature (oC): ");
	    Serial.println(DHT.getCelsius(), 2);

	    Serial.print("Temperature (oF): ");
	    Serial.println(DHT.getFahrenheit(), 2);
        
        //Particle.publish ("Tempature in F =" + (DHT.getFahrenheit()));
        
	   //Serial.print("Temperature (K): ");
	   //Serial.println(DHT.getKelvin(), 2);

	   //Serial.print("Dew Point (oC): ");
	   //Serial.println(DHT.getDewPoint());

	   //Serial.print("Dew Point Slow (oC): ");
	   //Serial.println(DHT.getDewPointSlow());
        
        Particle.publish  ("Tempature in F =" + Tempf, PUBLIC);
        
        //Spark.publish (Tempf);
	}
	    n++;  // increment counter
	    bDHTstarted = false;  // reset the sample flag so we can take another
	    DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
	    Blynk.run();
  
  }
}

(ScruffR: You can edit posts, you don’t have to repost)

It came out funny

Which is why you should use code formatting. There’s even a button that does that for you…

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social groups:              http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 *
 * No coding required for direct digital/analog pin operations!
 *
 * WARNING: It is recommended to use SparkCorePolledTimer library
 *          to make periodic actions (similar to SimpleTimer on Arduino).
 *
 **************************************************************/

#define BLYNK_PRINT Serial  // Set serial output for debug prints
//#define BLYNK_DEBUG       // Uncomment this to see detailed prints

#include "blynk.h"

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "25a3bf6a28934262a0c680bf7590cb83";

// Attach a Button widget (mode: Switch) to the Digital pin 7 - and control the built-in blue led.
// Attach a Graph widget to Analog pin 1
// Attach a Gauge widget to Analog pin 2








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

/*
 * FILE:        DHT_example.cpp
 * VERSION:     0.4
 * PURPOSE:     Example that uses DHT library with two sensors
 * LICENSE:     GPL v3 (http://www.gnu.org/licenses/gpl.html)
 *
 * Example that start acquisition of DHT sensor and allows the
 * loop to continue until the acquisition has completed
 * It uses DHT.acquire and DHT.acquiring
 *
 * Change DHT_SAMPLE_TIME to vary the frequency of samples
 *
 * Scott Piette (Piette Technologies) scott.piette@gmail.com
 *      January 2014        Original Spark Port
 *      October 2014        Added support for DHT21/22 sensors
 *                          Improved timing, moved FP math out of ISR
 *      September 2016      Updated for Particle and removed dependency
 *                          on callback_wrapper.  Use of callback_wrapper
 *                          is still for backward compatibility but not used
 */











#include "PietteTech_DHT.h"  // Uncomment if building in IDE
//#include "PietteTech_DHT.h"                 // Uncomment if building using CLI

// system defines
#define DHTTYPE  DHT22              // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   D3         	    // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   2000  // Sample every two seconds

/*
 * NOTE: Use of callback_wrapper has been deprecated but left in this example
 *       to confirm backwards compabibility.  Look at DHT_2sensor for how
 *       to write code without the callback_wrapper
 */
//declaration
void dht_wrapper();// must be declared before the lib initialization

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

// globals
unsigned int DHTnextSampleTime;	    // Next time we want to start sample
bool bDHTstarted;		    // flag to indicate we started acquisition
int n;                              // counter

void setup()
{
    Serial.begin(9600);
    delay(5000); // Allow board to settle

    Blynk.begin(auth);
}

// Attach a Button widget (mode: Push) to the Virtual pin 1 - and send sweet tweets!
BLYNK_WRITE(V1)
{
    if (param.asInt() == 1)
    {   
        // On button down...
        // Tweeting!
        // Note:
        //   We allow 1 tweet per minute for now.
        //   Twitter doesn't allow identical subsequent messages.
        Blynk.tweet("My Particle project is tweeting using @blynk_app and it’s awesome!\n @Particle #IoT #blynk");
        // Pushing notification to the app!
        // Note:
        //   We allow 1 notification per minute for now.
        Blynk.notify("You pressed the button and I know it");
        
    }
}


/*
    Serial.begin(9600);
    while (!Serial.available()) 
    {
        Serial.println("Press any key to start.");
		Particle.process();
        delay (1000);
    }
    Serial.println("DHT Example program using DHT.acquire and DHT.aquiring");
    Serial.print("LIB version: ");
    Serial.println(DHTLIB_VERSION);
    Serial.println("---------------");

    DHTnextSampleTime = 0;  // Start the first sample immediately

*/
/*
 * NOTE:  Use of callback_wrapper has been deprecated but left in this example
 * to confirm backwards compatibility.
 */
// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper()
{
    DHT.isrCallback();
}

void loop()
{
  // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
	if (!bDHTstarted) {		// start the sample
	    Serial.print("\n");
	    Serial.print(n);
	    Serial.print(": Retrieving information from sensor: ");
	    DHT.acquire();
	    bDHTstarted = true;
	}

	if (!DHT.acquiring())
	{		// has sample completed?

	    // get DHT status
	    int result = DHT.getStatus();
        int Tempf = (int)DHT.getFahrenheit();
        
	    Serial.print("Read sensor: ");
	    switch (result) {
		case DHTLIB_OK:
		    Serial.println("OK");
		    break;
		case DHTLIB_ERROR_CHECKSUM:
		    Serial.println("Error\n\r\tChecksum error");
		    break;
		case DHTLIB_ERROR_ISR_TIMEOUT:
		    Serial.println("Error\n\r\tISR time out error");
		    break;
		case DHTLIB_ERROR_RESPONSE_TIMEOUT:
		    Serial.println("Error\n\r\tResponse time out error");
		    break;
		case DHTLIB_ERROR_DATA_TIMEOUT:
		    Serial.println("Error\n\r\tData time out error");
		    break;
		case DHTLIB_ERROR_ACQUIRING:
		    Serial.println("Error\n\r\tAcquiring");
		    break;
		case DHTLIB_ERROR_DELTA:
		    Serial.println("Error\n\r\tDelta time to small");
		    break;
		case DHTLIB_ERROR_NOTSTARTED:
		    Serial.println("Error\n\r\tNot started");
		    break;
		default:
		    Serial.println("Unknown error");
		    break;
	    }

	    Serial.print("Humidity (%): ");
	    Serial.println(DHT.getHumidity(), 2);

	    Serial.print("Temperature (oC): ");
	    Serial.println(DHT.getCelsius(), 2);

	    Serial.print("Temperature (oF): ");
	    Serial.println(DHT.getFahrenheit(), 2);
        
        //Particle.publish ("Tempature in F =" + (DHT.getFahrenheit()));
        
	   //Serial.print("Temperature (K): ");
	   //Serial.println(DHT.getKelvin(), 2);

	   //Serial.print("Dew Point (oC): ");
	   //Serial.println(DHT.getDewPoint());

	   //Serial.print("Dew Point Slow (oC): ");
	   //Serial.println(DHT.getDewPointSlow());
        
        Particle.publish  ("Tempature in F =" + Tempf, PUBLIC);
        
        //Spark.publish (Tempf);
	}
	    n++;  // increment counter
	    bDHTstarted = false;  // reset the sample flag so we can take another
	    DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
	    Blynk.run();
  
  }
}












This is still wrong.

And Blynk.run() should not be inside that if (millis() > DHTnextSampleTime) { ... } block.

For debugging your issue, I would first comment out all the Blynk stuff and see if that changes anything.

I see a couple of small issues with your code. They may not be the cause of the problem, but I would recommend cleaning these up.

  1. The PietteTech library is included twice. You should only include it once:
#include <PietteTech_DHT.h>

and later on

#include "PietteTech_DHT.h"  // Uncomment if building in IDE
  1. The variable bDHTstarted is not defined when it is initialized or in setup.
    When you get to this line for the first time, we have no idea what the code will do since we don’t know what value bDHTstarted is. The experts may know if there is a default, but good practice is to set it to something you know, so the behavior of the code is known.
	if (!bDHTstarted) {		// start the sample

EDIT: The same problem applies to your variables DHTnextSampleTime and n. Do you even need the variable n? All you do is serial print (n), but it is never defined. I am sure this will cause some sort of strange behavior.

  1. Is this line 129? It looks like the semicolon at the end of the Particl.publish line is okay. However, you have some more code and some curly end braces } afterwards. Carefully check your code to make sure all the code is where it should be and that every curly open brace has a corresponding curly end brace. It needs to match up or else there might be warnings or errors or if unlucky then the code compiles but does not do what you expect.
Particle.publish  ("Tempature in F =" + Tempf, PUBLIC);
        
        //Spark.publish (Tempf);
	}
	    n++;  // increment counter
	    bDHTstarted = false;  // reset the sample flag so we can take another
	    DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
	    Blynk.run();

Give those a try to start and then see where you are at. I am not an expert; still working on it.
This should get you close and then the experts can take over and figure out if anything else needs to be fixed.

2 Likes

does all this affect my connection?

Maybe it affects your connection. If your code is busy doing strange behavior or tasks that are not required, it might be late in processing the connection or does not process it at all. When the Photon fails to process the connection in time, then you lose the connection. I have had a problem losing the connection in my code before, so it is something you learn to look out for.