Connected but "variable not found" after awhile

A simple temperature and humidity app works great for a couple of hours, but then starts responding with “variable not found”.

{
“ok”: false,
“error”: “Variable not found”
}

When I omit the specific variable name, I get the following:

{
“id”: “xxx”,
“name”: “yyy”,
“connected”: true,
“variables”: {},
“functions”: [],
“cc3000_patch_version”: “1.29”
}

Spark core is breathing cyan. Build shows the spark connected. Once I reboot the core, it works well for a couple more hours.

Any help is greatly appreciated.
Muskie

@Muskie, you will need to share your code so we can help you better :smile:

Sorry I neglected to post the code. See below. Note that the analog temperature sensor was left over from a previous test. In practice I am only fetching the degrees F and humidity variables from the DHT22.

// This #include statement was automatically added by the Spark IDE.
#include "idDHT22/idDHT22.h"


int idDHT22pin = D4; 
void dht22_wrapper(); 

idDHT22 DHT22(idDHT22pin, dht22_wrapper);


double  tmp36           = 0.0;
double  dht22_temp_c    = 0.0;
double  dht22_temp_f    = 0.0;
double  dht22_humid     = 0.0;
double  dht22_dewpt     = 0.0;

void setup() {
    Spark.variable("tmp36", &temp_36, DOUBLE);
    pinMode(A7, INPUT);
    
    Spark.variable("dht22_temp_c", &dht22_temp_c, DOUBLE);
    Spark.variable("dht22_temp_f", &dht22_temp_f, DOUBLE);
    Spark.variable("dht22_humid", &dht22_humid, DOUBLE);
    Spark.variable("dht22_dewpt", &dht22_dewpt, DOUBLE);
}

void dht22_wrapper() {
    DHT22.isrCallback();
}

void loop() {
    int     sensorA2D   = 0;
    double  voltage     = 0.0;
    
    sensorA2D   = analogRead(A7);
    voltage     = (sensorA2D * 3.3) / 4095;
    tmp36       = ((((voltage - 0.5) * 100) * 9.0) / 5.0) + 32.0;
    
    DHT22.acquire();
    while (DHT22.acquiring())
    {
        ;
    }
    
    int dht22_result = DHT22.getStatus();
    
    switch (dht22_result)
    {
        case IDDHTLIB_OK:
            {
                dht22_humid     = DHT22.getHumidity();
                dht22_temp_c    = DHT22.getCelsius();
                dht22_temp_f    = DHT22.getFahrenheit();
                dht22_dewpt     = DHT22.getDewPoint();
            }
            break;
        case IDDHTLIB_ERROR_CHECKSUM:
            break;
        case IDDHTLIB_ERROR_ISR_TIMEOUT:
            break;
        case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
            break;
        case IDDHTLIB_ERROR_DATA_TIMEOUT:
            break;
        case IDDHTLIB_ERROR_ACQUIRING:
            break;
        case IDDHTLIB_ERROR_DELTA:
            break;
        case IDDHTLIB_ERROR_NOTSTARTED:
            break;
        default:
            break;
    }


    delay(3000);
}

@Muskie, if you are not doing so already, switch to piettech’s PIETTECH_DHT library as it has proven very reliable, unlike my IDDHT22 library which is known to hang! Give that a shot and let me know how it goes. :smile:

@peekay123 I took your advice and switched to the PietteTech alternative library. So far the unit has been functional for over 12 hours without exhibiting the same problem. Thank you for the help.

One other question though. The original driver was part of the “libraries” section of Build, but I could not seem to find the PietteTech driver there and had to download it instead and manually add it to my project. Is this expected, or did I miss something?

The PietteTech should be in the build IDE. Try searching for “piet”?

Of course, right under my nose. Thanks @Moors7

2 Likes