No data available for this period - double channel

Hi

I have this Arduino code, it is sending data to cayenne, but I struggle to get the graph work.

I have one channel for Gauge and one for Graph.

The code uses “digital_sensor” in Cayenne I can only choose “Analog”

Any tip to get?

CAYENNE_OUT(VIRTUAL_CHANNEL_6) {
  Cayenne.virtualWrite(VIRTUAL_CHANNEL_6, weightKg, "digital_sensor", "d");       // kg not in cayenne definitions
}
CAYENNE_OUT(VIRTUAL_CHANNEL_7) {
  Cayenne.virtualWrite(VIRTUAL_CHANNEL_7, weightKg, "digital_sensor", "d");       // kg not in cayenne definitions
}


image image

Hi

I’m trying and trying, but struggle to store historical data more than 1 h
I hope you can help me @shramik_salgaonkar

image

What I tried was

  1. convert weight to string

CAYENNE_OUT(VIRTUAL_CHANNEL_10)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL_10, weightKgStr, “digital_sensor”, “d”); // kg not in cayenne definitions
}

  1. Use a known value temp as string sinse it is a known definition

Cayenne.virtualWrite(VIRTUAL_CHANNEL_12, tempStr, “temp”, “c”);

  1. same as 2 but as float
    Cayenne.virtualWrite(VIRTUAL_CHANNEL_12, temp, “temp”, “c”);

  2. as analog
    Cayenne.virtualWrite(VIRTUAL_CHANNEL_11, AnalogKgStr, “analog_sensor”, “d”);

My test code, also include some OLED write

//Libraries for Cayenne
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP32.h>

//OLED pins LoRa TTGO
#define OLED_SDA 21
#define OLED_SCL 22
#define OLED_RST 23
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

float weightKg;
float AnalogKg;
float temp;
char weightKgStr[10];  // create a character array to store the string for Cayenne
char AnalogKgStr[10]; // create a character array to store the string for cayenne
char tempStr[10];        // create a character array to store the string for cayenne

int pixel_x = 0;

// my devices
  char* username = "xxx";
  char* password = "yyy";
  char* clientID = "zzz";  

char SSID[] = "WiFi";
char wifipass[] = "PASS";
//Cayenne channel definitions
#define VIRTUAL_CHANNEL_10 10
#define VIRTUAL_CHANNEL_11 11
#define VIRTUAL_CHANNEL_12 12

void setup() {
  Serial.begin(57600);
  // initialize OLED screen
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (true);
  }
  // clear screen
  display.clearDisplay();

  randomSeed(analogRead(0));  // seed the random number generator with an analog input value
  Cayenne.begin(username, password, clientID, SSID, wifipass);
}

// WiFi Cayenne control
CAYENNE_CONNECTED() {
  CAYENNE_LOG("Connection established");
}
CAYENNE_DISCONNECTED() {
  CAYENNE_LOG("Connection Lost");
}

void loop() {
  float weightKg = map(random(0, 100), 0, 99, 2500, 2599) / 100.0; // generate a random number between 2500 and 2599, then map it to the range 25.00 to 25.99
  float AnalogKg = map(random(0, 100), 0, 99, 2000, 2099) / 100.0; // generate a random number between 2000 and 2099, then map it to the range 25.00 to 25.99
  float temp = map(random(0, 100), 0, 99, 1000, 1500) / 100.0; // generate a random number between 2000 and 2099, then map it to the range 25.00 to 25.99
  // convert the float to a string with two decimal places
  snprintf(weightKgStr, sizeof(weightKgStr), "%.2f", weightKg); // gjør om til string for cayenne
  snprintf(AnalogKgStr, sizeof(AnalogKgStr), "%.2f", AnalogKg);
  snprintf(tempStr, sizeof(tempStr), "%.2f", temp);
  
   Serial.print("Digitalvekt: ");
  Serial.print(weightKgStr); // print the random number to the serial monitor with 2 decimal places
  Serial.print("       Analogvekt: ");
  Serial.print(AnalogKgStr); // print the random number to the serial monitor with 2 decimal places
  Serial.print("       Temp/vekt: ");
  Serial.println(temp); // print the random number to the serial monitor with 2 decimal places

  // Send readings 
  unsigned long currentTime = millis();
  if (currentTime - previousTime >= 10000) {   // LoRa publish timer
    previousTime = currentTime;
    Cayenne.loop();
    Serial.println("###################################### Sender til Cayenne 10 sek");
  }
  //writeOLED();
  display.drawPixel(127, 59, 1); 
  int pixel_y = (weightKg - 25) * 60;       //60 pix er 1 kg. Avlest vekt 22 kg - 20 kg = 2, 2*30=60
  //move one pixel to rigth
  Serial.println(weightKg);
  Serial.print("x=" + String(pixel_x));
  Serial.println(", y=" + String(pixel_y));
  display.drawPixel(pixel_x, pixel_y, 1);
  //move one pixel to rigth next time
  pixel_x = pixel_x + 1;
  if (pixel_x == 128) {
    pixel_x = 0;
    display.clearDisplay();
  }
  // update previous point to current point
  //previousY = pixel_y;

  // display graph on screen
  display.display();

  // delay for smooth animation
  delay(300);


}

CAYENNE_OUT(VIRTUAL_CHANNEL_10)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL_10, weightKgStr, "digital_sensor", "d"); // kg not in cayenne definitions
}

CAYENNE_OUT(VIRTUAL_CHANNEL_11)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL_11, AnalogKgStr, "analog_sensor", "d"); // kg not in cayenne definitions
}

CAYENNE_OUT(VIRTUAL_CHANNEL_12)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL_12, tempStr, "temp", "c"); // test to make kg as temp
}













That is not your fault. I have the same problem, and others too. It is from Cayenne itself…