Slider problem


#1

i add a slider in cayenne android app but when i want to change its value after 2 sec it sets itself to max slider value . pls help me and sry for bad english.
i am using nodemcu but i think it doesnot matter with problem.


#2

can you share the code, screenshot of your dashboard and if possible a video of the same.


#3

i made a fresh device in cayenne app and i add a slider in it and once i connect it to a CAYENNE_IN func and also i made another one slider and i did not connect it to CAYENNE_IN and both of them worked but also both of them has a problem … when i change its value, after 2 sec its value change to max and i screenshot them as blow
ty
after 2 sec :point_down:


#4

this is my code

/*
This example shows how to connect to Cayenne using an ESP32 and send/receive sample data.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. If you have not already installed the ESP32 Board Package install it using the instructions here: https://github.com/espressif/arduino-esp32/blob/master/README.md#installation-instructions.
2. Select your ESP32 board from the Tools menu.
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
4. Set the network name and password.
5. Compile and upload the sketch.
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
    #include <SimpleTimer.h>
    #include <OneWire.h>
    #include <ESP8266Ping.h>

    // WiFi network info.
    char ssid[] = "";
    char wifiPassword[] = "";

    // Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
    char username[] = "1";
    char password[] = "";
    char clientID[] = "";
    unsigned long time1;
    int autoMode;
    int tempSlider;

    #define RelayPin 13
    #define RelayPin2 14
    #define DS18S20_Pin 12 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
    //Temperature chip i/o
    OneWire ds(DS18S20_Pin); // on digital pin 12
    SimpleTimer timer;

    const IPAddress remote_ip(8, 8, 8, 8);

    // This function sends the device's uptime to Cayenne on Virtual Channel 5.
    void sendUptime()
    {
      // Send values using the virtualWrite function. Cayenne currently accepts int and float values.
      // Please don't send more that 10 values per second.
      Cayenne.virtualWrite(0, getTemp());
      Serial.print("ping = ");
      Serial.print(remote_ip);// print as an ASCII-encoded decimal - same as "DEC"
      Serial.print(" ");
      Ping.ping(remote_ip);
      Serial.println(Ping.averageTime());
      Cayenne.virtualWrite(5, Ping.averageTime());
      Cayenne.virtualWrite(7, tempSlider);
      
      if( digitalRead(RelayPin) == LOW){
        Cayenne.virtualWrite(2,1);
      }
      else {
        Cayenne.virtualWrite(2,0);
      }
      if( autoMode == 0){
        Cayenne.virtualWrite(4,0);
      }
      else {
        Cayenne.virtualWrite(4,1);
      }
    }
    void autoCheck()
    {
      if(autoMode == 1){
        if(getTemp() >= tempSlider && getTemp() < (tempSlider+1)){//on
          CAYENNE_LOG("autoMode : KOND!");
          digitalWrite(RelayPin, HIGH);
          delay(1000);
          digitalWrite(RelayPin2, HIGH);
          delay(1000);
        }
        if(getTemp() > (tempSlider+1)){//tond
          CAYENNE_LOG("autoMode : TOND!");
          digitalWrite(RelayPin2, LOW);
          delay(3000);
          digitalWrite(RelayPin, LOW);
          delay(1000);
        }
        if(getTemp() <= (tempSlider-1)){//off
          CAYENNE_LOG("autoMode : OFF!");
          digitalWrite(RelayPin2, LOW);
          delay(3000);
          digitalWrite(RelayPin, HIGH);
          delay(1000);
        }
      }
    }
    void setup() {
      Serial.begin(9600);
      Cayenne.begin(username, password, clientID, ssid, wifiPassword);
      digitalWrite(RelayPin, HIGH);
      digitalWrite(RelayPin2, HIGH);
      time1 = millis();
      autoMode = 0;
      tempSlider = 25;

        // Set up a function to be called every 5 seconds
      timer.setInterval(1000L, sendUptime);
      timer.setInterval(5000L, autoCheck);
      pinMode(RelayPin, OUTPUT);
      pinMode(RelayPin2, OUTPUT);
    }

    void loop() {
      Cayenne.loop();
      timer.run(); // Initiates SimpleTimer
      
    }

    // Default function for sending sensor data at intervals to Cayenne.
    // You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
    CAYENNE_OUT_DEFAULT()
    {
      // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
      //Cayenne.virtualWrite(0, millis());
      // Some examples of other functions you can use to send data.
      //Cayenne.celsiusWrite(1, 22.0);
      //Cayenne.luxWrite(2, 700);
      //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
    }
    // This function is called at intervals to send sensor data to Cayenne.
    CAYENNE_OUT(0)
    {
      //Cayenne.virtualWrite(0, getTemp());
    }

    // Default function for processing actuator commands from the Cayenne Dashboard.
    // You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
    CAYENNE_IN_DEFAULT()
    {
      CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
      //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
    }
    CAYENNE_IN(1)
    {
      if(millis()-time1 > 3000){
        if (getValue.asInt() == 0) {
          CAYENNE_LOG("OFF : %u", millis());
         digitalWrite(RelayPin, HIGH);
         delay(3000);
         digitalWrite(RelayPin2, HIGH);
        }
        else {
          CAYENNE_LOG("ON! : %u", millis());
          digitalWrite(RelayPin2, LOW);
          delay(3000);
          digitalWrite(RelayPin, LOW);
        }
        time1 = millis();
      }
      else{
        CAYENNE_LOG("!!!!!!!!!!");
      }
    }
    CAYENNE_IN(3)
    {
      if(millis()-time1 > 3000){
        if (getValue.asInt() == 1) {
          autoMode = 1;
          CAYENNE_LOG("Automatic ON! : %u", millis());
        }
        else {
          autoMode = 0;
          CAYENNE_LOG("Automatic OFF : %u", millis());
        }
        time1 = millis();
      }
      else{
        CAYENNE_LOG("!!!!!!!!!!");
      }
    }
    CAYENNE_IN(6)
    {
        tempSlider = getValue.asInt();
    }

    float getTemp(){
     //returns the temperature from one DS18S20 in DEG Celsius

     byte data[12];
     byte addr[8];

     if ( !ds.search(addr)) {
       //no more sensors on chain, reset search
       ds.reset_search();
       return -1000;
     }

     if ( OneWire::crc8( addr, 7) != addr[7]) {
       Serial.println("CRC is not valid!");
       return -1000;
     }

     if ( addr[0] != 0x10 && addr[0] != 0x28) {
       Serial.print("Device is not recognized");
       return -1000;
     }

     ds.reset();
     ds.select(addr);
     ds.write(0x44,1); // start conversion, with parasite power on at the end

     byte present = ds.reset();
     ds.select(addr);
     ds.write(0xBE); // Read Scratchpad


     for (int i = 0; i < 9; i++) { // we need 9 bytes
      data[i] = ds.read();
     }

     ds.reset_search();

     byte MSB = data[1];
     byte LSB = data[0];

     float tempRead = ((MSB << 8) | LSB); //using two's compliment
     float TemperatureSum = tempRead / 16;

     return TemperatureSum;

    }

#5

Thanks for reporting this issue. We are working on it and will let you know once solved ,.