Chart problem with humidity

Dear users
This is my second project with cayenne. I have problem with chart. One (most important for me) not working. It record humidity in one room.
I do remove this widget and install it again more time


Live chart is working OK, but all other not.

best regards
Simon

which device are you using?

I use ESP8266 for communicate with cayonne

V V pon., 21. dec. 2020 ob 16:38 je oseba Shramik salgaonkar via myDevices Cayenne Community <mydevices@discoursemail.com> napisala:

can you share the code you are using.

Yes of course.
ESP is communicate with arduino via UART. Problem is on CH2 called “h” humidity

//#define CAYENNE_DEBUG
//#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Wire.h>
#include "Adafruit_SHT31.h" 
//#include "arduino.h"
#include <HardwareSerial.h>

//#include <millisDelay.h>


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

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "2425345345345";
char password[] = "123123123354688";
char clientID[] = "123123123";


int rele_prez = 12;               // prezrači prostor
int H_nast, T_nast, H_tol, T_tol; // nastavljene in tolerančne vrednosti shranjene v eeprom
long prez_na;                     // prezračevanje na XXXX minut
int prez_on;                      // prezračevanje za XXX minut
long prez_na_1;                   // prezračevanje na XXXX minut klet 1 
int prez_on_1;                    // prezračevanje za XXX minut klet 1
float t, h;                       // temperatura in vlaga
float t_l,h_l;                    // temperatura in vlaga lokalna iz HST31
char receivedChars[16];           // an array to store the received data
boolean newData = false;          // zastavica sprejetega sporočila
bool alive = false;               // zastavica, če arduino v kleti še živi
int alive_rec, alive_old;
char ukaz=0;                      // kateri ukaz iz sprejemnega bufferja
int dataNumber = 0;               // new for this version
bool prvi=true;                   // prvi znak pri sprejemu UART
bool prez_klet_1=false;           // zastavica za prezračevanje v prvi kleti
long i=0;                         // zakasnitev za pošiljanje na cayenne
int i1=0;

Adafruit_SHT31 sht31 = Adafruit_SHT31(); 

 
void setup() { 
  Serial.begin(9600); 


  pinMode(rele_prez, OUTPUT);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  
   while (!Serial) 
     delay(100);     // will pause Zero, Leonardo, etc until serial console opens 
 
   if (! sht31.begin(0x44)) {   // Set to 0x45 for alternate i2c addr 
     Serial.print("e"); Serial.println(5);    // napaka ni senzorja lokalno
 } 
} 
 
 void loop() { 

    rx_uart();                //beremo uart
    izvedi();
//    showNewNumber();
//   poslji_UART();               // pošlje podatke po UART na ESP
/*
//debug na seriski 
   if (! isnan(t)) {  // check if 'is not a number' 
//     Serial.print("Temp *C = "); Serial.println(t); 
   } else {  
     Serial.println("e"); Serial.print(2);    // napaka branja temperature
   } 
    
   if (! isnan(h)) {  // check if 'is not a number' 
//     Serial.print("Hum. % = "); Serial.println(h); 
  } else {  
 Serial.println("e"); Serial.print(3);    // napaka branja vlage 
   } 
*/
  if (i>100000){      // delay za pošiljanje, da lahko bere podatke preko UART
    t_l = sht31.readTemperature(); 
    h_l = sht31.readHumidity(); 
    Cayenne.loop();
    i=0;
      if (i1 >3) {
        if (alive_old != alive_rec) alive = true;     // če je prejšnji znak ne enak novemu pomeni da stvar živi
        else alive=false;
        alive_old = alive_rec;
        i1=0;
      }
    i1++;
    }
 i++;
}

void izvedi()                                // izvedi izhode
{   

    if (prez_klet_1) digitalWrite(rele_prez,HIGH);      // vklop prezračevanja
    else digitalWrite(rele_prez,LOW);
}

void rx_uart(){
//void serialEvent() {    // prekinitev za UART
    static byte ndx = 0;
    char rc;
    bool pisi=false;
    if (Serial.available() > 0) {
        rc = Serial.read();
 //       Serial.println("notri");
        if (rc != '\n') {
          if (prvi == true){
            ukaz = rc;
            ndx--;
            prvi = false;
           }
       
            receivedChars[ndx] = rc;
            ndx++;
         }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
             ndx = 0;
            newData = true;
            prvi = true;
            
        }
    }
    if (newData == true) {
      dataNumber=0;
      dataNumber = atol(receivedChars);
      
      switch (ukaz) {
        case 'T':                               // temperatura aktualna
           t = (float)dataNumber/100;
        break;
         case 'H':                              // vlaga aktualna
           h =(float)dataNumber/100;
        break;
          case 't':                               // temperatura
           T_nast = dataNumber;
        break;
         case 'h':                              // vlaga
           H_nast = dataNumber;
        break;
         case 'n':                              // prezračevanje na
           prez_na = dataNumber;
       break;
         case 'o':                              // prezračevanje časa
           prez_on = dataNumber;
       break;
         case 'y':                              // toleranca temp
           T_tol = dataNumber;
        break;
         case 'x':                              // poleranca vlaga
           H_tol = dataNumber;
        break;
         case 'q':                              // prezračevanje na klet 1
           prez_na_1 = dataNumber;
       break;
         case 'w':                              // prezračevanje časa klet 1
           prez_on_1 = dataNumber;
         break;
       case 'P':                              // rele prezračevanja za klet 1
           prez_klet_1 = dataNumber;
         break;
       case 'A':                              // prezračevanje časa klet 1
           alive_rec = dataNumber;
         break;
       }
     newData = false;
     }
 }

// samo za debug !!!
void showNewNumber() {
    if (newData == true) {
        dataNumber = 0;             // new for this version
        dataNumber = atoi(receivedChars);   // new for this version atoi
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        Serial.print("Data as Number ... ");    // new for this version
        Serial.println(dataNumber);     // new for this version
        newData = false;
        Serial.print ("rele T "); Serial.println(T_nast);
        Serial.print ("rele H "); Serial.println(H_nast);
   }
}

void poslji_UART(){               //samo za debug. Se ne uporablja
      
       Serial.print("T"); Serial.println(t);          // temperatura
       delay(10);
       Serial.print("H"); Serial.println(h);          // vlaga
       delay(10);
       

       Serial.print("t"); Serial.println(T_nast);
       delay(10);
       Serial.print("h"); Serial.println(H_nast);
       delay(10);
       Serial.print("n"); Serial.println(prez_na);
       delay(10);
       Serial.print("o"); Serial.println(prez_on);
       delay(10);
       Serial.print("y"); Serial.println(T_tol);
       delay(10);
       Serial.print("x"); Serial.println(H_tol);
       delay(10);
       Serial.print("q"); Serial.println(prez_na_1);
       delay(10);
       Serial.print("w"); Serial.println(prez_on_1);
       delay(10);
       Serial.print("klet1 "); Serial.println(prez_klet_1);
 
}


// 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()
//CAYENNE_OUT(1)
{
  long rssi = WiFi.RSSI();                                    // moč wifi signala
  Cayenne.virtualWrite(0 , rssi, "RSSI", "dbm");
  Cayenne.celsiusWrite(1, t);
  Cayenne.virtualWrite(2, h, "rel_hum", "p");
  Cayenne.virtualWrite(3, T_nast,"temp","d");
  Cayenne.virtualWrite(4, H_nast,"rel_hum","p");
  Cayenne.virtualWrite(5, T_tol,"temp","d");
  Cayenne.virtualWrite(6, H_tol,"rel_hum","p"); 
  Cayenne.virtualWrite(7, prez_na);
  Cayenne.virtualWrite(8, prez_on);
  Cayenne.virtualWrite(9, prez_na_1);
  Cayenne.virtualWrite(10, prez_on_1);
// Cayenne.virtualWrite(11, digitalRead(rele_prez));      //stanje ventilatorja klet 1
  Cayenne.celsiusWrite(12, t_l);                    //temp v kleti 1
  Cayenne.virtualWrite(13, h_l, "rel_hum", "p");    // vlaga v kleti 1
  Cayenne.virtualWrite(14, alive, "digital_sensor", "d");                    //povemo, če se arduino klet še odziva

//  Cayenne.virtualWrite(5, digitalRead(rele_1),"digital_sensor", "d");
}

// 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()

// --- beremo vhode ------
CAYENNE_IN(20)
{
  Serial.print("t"); Serial.println(getValue.asInt());  //nastavimo temperaturo
}
CAYENNE_IN(21)
{
  Serial.print("h"); Serial.println(getValue.asInt());  //nastavimo vlago
}
CAYENNE_IN(22)
{
  Serial.print("y"); Serial.println(getValue.asInt());  //nastavimo toleranco temperaturo
}
CAYENNE_IN(23)
{
  Serial.print("x"); Serial.println(getValue.asInt());  //nastavimo toreranco vlage
}
CAYENNE_IN(24)
{
  Serial.print("n"); Serial.println(getValue.asInt());  //nastavimo prezračevanje na
}
CAYENNE_IN(25)
{
  Serial.print("o"); Serial.println(getValue.asInt());  //nastavimo prezračevanje čas
}
CAYENNE_IN(26)
{
  Serial.print("q"); Serial.println(getValue.asInt());  //nastavimo prezračevanje na klet 1
}
CAYENNE_IN(27)
{
  Serial.print("w"); Serial.println(getValue.asInt());  //nastavimo prezračevanje čas klet 1
}
CAYENNE_IN(28)
{
  Serial.print("k"); Serial.println(getValue.asInt());  //ročno prezračevanje kleti
}
CAYENNE_IN(29)
{
  Serial.print("K"); Serial.println(getValue.asInt());  //ročno prezračevanje kleti
}

Also I note, that I don’t got any SMS if we are offline and even not email. What do I do wrong?

if (i > 100000) {   // delay za pošiljanje, da lahko bere podatke preko UART
    t_l = sht31.readTemperature();
    h_l = sht31.readHumidity();
    Cayenne.loop();
    i = 0;
    if (i1 > 3) {
      if (alive_old != alive_rec) alive = true;     // če je prejšnji znak ne enak novemu pomeni da stvar živi
      else alive = false;
      alive_old = alive_rec;
      i1 = 0;
    }
    i1++;
  }
  i++;

in place of incrementing the value and checking, you can use the inbuilt millis to keep track of the time and read data at an interval.

  Cayenne.virtualWrite(8, prez_on);
  Cayenne.virtualWrite(9, prez_na_1);
  Cayenne.virtualWrite(10, prez_on_1);

is the line chart not working for any of these??

// --- beremo vhode ------
CAYENNE_IN(20)
{
  Serial.print("t"); Serial.println(getValue.asInt());  //nastavimo temperaturo
}
CAYENNE_IN(21)
{
  Serial.print("h"); Serial.println(getValue.asInt());  //nastavimo vlago
}
CAYENNE_IN(22)
{
  Serial.print("y"); Serial.println(getValue.asInt());  //nastavimo toleranco temperaturo
}
CAYENNE_IN(23)
{
  Serial.print("x"); Serial.println(getValue.asInt());  //nastavimo toreranco vlage
}
CAYENNE_IN(24)
{
  Serial.print("n"); Serial.println(getValue.asInt());  //nastavimo prezračevanje na
}
CAYENNE_IN(25)
{
  Serial.print("o"); Serial.println(getValue.asInt());  //nastavimo prezračevanje čas
}
CAYENNE_IN(26)
{
  Serial.print("q"); Serial.println(getValue.asInt());  //nastavimo prezračevanje na klet 1
}
CAYENNE_IN(27)
{
  Serial.print("w"); Serial.println(getValue.asInt());  //nastavimo prezračevanje čas klet 1
}
CAYENNE_IN(28)
{
  Serial.print("k"); Serial.println(getValue.asInt());  //ročno prezračevanje kleti
}
CAYENNE_IN(29)
{
  Serial.print("K"); Serial.println(getValue.asInt());  //ročno prezračevanje kleti
}

what is this for?

  1. I didn’t found how to use serial interrupt on ESP, so I all time check
    rx_uart();
    for reading temperature and send to server I do every 100000 cycles
    if (i>100000){ // delay za pošiljanje, da lahko bere podatke preko UART
    it is dummy, but it is working well!

  2. No this is only numbers and work well

  3. This read data from cayenne and send to UART. Also working well

  1. for reading temperature you can do something like:-
unsigned long lastMillis = 0;
void loop(){
   Cayenne.loop();
    if(millis() - lastMillis > 10000) {
      lastMillis = millis();
      //read temp
   }
}
  1. Which channel does not work well?
  2. Just showing on the serial monitor? for what?
  1. I won’t to leave my main loop like it is, because it work as expected.
  2. Everything work ! I have only problem with cayenne server, because don’t show me humidity “Vlaga” chart on ch 2!!!
  3. Not monitoring. It send data via UART to Arduino board.

All system work without problems

Temperature chart work OK

Humidity chart not working

try using a different channel for the humidity sensor.

change to

  Cayenne.virtualWrite(2, h, "rel_hum", "p");

Thanks for hint. This should work!
But if there is no other way? ESP in not close to my house.

merry Christmas to all

There is no other way. i guess you have tried deleting it. do you add the widget from dashboard or add it by clicking on the green widget created.
Merry Christmas to you.