How to Display the Temperature readings?


#70

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


#71

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


#72

Post. Your. Code.


#73
/**************************************************************
 * 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)


#74

It came out funny


#75

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


#76
/**************************************************************
 * 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();
  
  }
}













#77

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.


#78

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.


#79

does all this affect my connection?


#80

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.


#81

Yup, Particle has made sure that all global variables are initialised with zero valuse, so for boolean the default is false, but sure enough explicit initialisation is good practice :+1:

But there is another problem with this bDHTstarted. It should only be reset to false inside the if (!DHT.acquiring()) { ... } block, but it’s done outside of it.
The same is true for DHTnextSampleTime.

It may well do, but it definetly makes your code not work as expected


#82

Well, I got most of this from examples, so I didn’t do some of this
(I don’t need Particle publish any more if I can get blynk to work)


#83

That doesn’t change a thing. I’d guess you sprinkled your curly braces not exactly the way they were in the original code and that does make or break your code.


#84

@csh13, You can always test the examples on their own. However, when you combine examples together and add your own code, then it all has to be put together carefully. With experience you will learn why the libraries and examples are done the way they are. Sometimes the example fits your needs; sometimes your needs are different. Keep learning and working on coding; you will soon be doing it on your own.

Thinking of learning, thanks @ScruffR for the tip on default values. I just learned something.


#85
/src/blynk.cpp:29:19: fatal error: blynk.h: No such file or directory
 #include "blynk.h"

I didn’t do anything to the example, pressed the verify button and this came up.


#86

The examples have the example files, but there is more than just that. It is necessary to fully setup your project.
The example depends on two libraries; one of these libraries is mentioned in your error message: Blynk.
The error message clearly indicates that the Blynk.h file could not be found. Therefore, you have to do something so the file can be found.

What I would do is ensure you are using the Blynk library correctly.
First, remove any blynk.cpp and blynk.h files from your project.
Second, go over the instructions on using libraries in the documentation here.
Third, add the Blynk library to your project following the instructions.
Fourth, once you are done, you can double-check your project.properties file. It should look something like this (I named my project Test; yours might be different)

name=Test
dependencies.blynk=0.4.5
dependencies.PietteTech_DHT=0.0.5

If it looks different, then go back, check the details and keep working on it.

Give that a try. Once that is fixed, we can move onto any other errors.


#87

Even though it says
#include <blynk>
at the top, apparently doesn’t mean you have it in your project. you have to manually press the include in project button to make it work. the automatic version from the example needs it.


#88

I can write

#include <blynk.h>

in this post, that does - not apparently but definetly - not mean that library is now included in this post.
The same is the case with your source file - it’s only text.

And for that exact reason @cyclin_al gave you a link to the docs

https://docs.particle.io/guide/getting-started/build/photon/#using-libraries


#89

yes but it seemed that would be alright because it was already in the example