I am not reading the value of the slider in my Cayenne project.
I am using Arduino IDE with a Wemos D1 mini esp8266 dev board. My device is a soil moisture sensor and I use
ESP.deepSleep (SleepTime); at the end of the loop to put the device to sleep between readings to save battery power.
Sleeptime = 100000 * sleeptimesec and sleeptimesec is defined as a Long variable.
I created a slider at V8 from 5-300 and set it at 10 (the default value of sleeptimesec is 5).
I have tried placing
CAYENNE_IN(V8){
sleeptimesec = getValue.asLong();
}
In various places, but none of them alter the value of sleeptimesec. from 5 to 10.
Everything else works nicely, but I would like to be able to change the sleep time in the field.
My full sketch is here:
//set sleep time
long sleeptimesec = 5;
long SleepTime = 1000000 * sleeptimesec;
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// Set Soil reading
#define SoilMoistureADMax 850 // Max Analog Value
#define SoilMoistureADMin 0 // Min Analog Value
// WiFi network info.
char ssid[] = "xxx";
char wifiPassword[] = "xxxx";
// Cayenne authentication info.
char username[] = "xxx";
char password[] = "xxxx";
char clientID[] = "xxx";
int moist = 0;
//Values sent/error booleans
bool CayenneSent = false;
bool ReadError = false;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
CayenneSent = false;
ReadError = true;
pinMode(12,OUTPUT);
pinMode(D0, WAKEUP_PULLUP);
}
CAYENNE_IN(V8){
sleeptimesec = getValue.asLong();
}
void loop() {
Cayenne.loop();
// Print sleeptimesec
Serial.print ("sleeptime is ");
Serial.println (sleeptimesec);
// read soil moisture after powering sensor from pin 12
for (int i=0; i <= 4; i++){
digitalWrite (12,HIGH);
delay (1000);
moist = analogRead(A0);
moist = map(moist, SoilMoistureADMin, SoilMoistureADMax, 0, 100);
//send moist to Cayenne
Cayenne.virtualWrite(1, moist, "soil_moist", "p");
Cayenne.virtualWrite(0, millis () /1000);
Serial.println (analogRead(A0));
delay (1000);
}
//turn off sensor
digitalWrite(12,LOW);
//go to sleep
ESP.deepSleep (SleepTime);
}