Les cards n'apparaissent pas sur le DASH

Bonjour, je suis sur un projet de thermostat connecté, mon code n'est pas fini mais je souhaitais déjà avoir un visu de l'agencement des cards sur le dash-board ; Pour le moment rien n'apparait est le cash reste vide...

#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <Wire.h>
#include <espnow.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <Arduino.h>
#include <ESPDash.h>


//Espnow Datas receiver
typedef struct { 
  float h=0;
  float temp=0;
} struct_message;

struct_message myData;


void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
  memcpy(&myData, incomingData, sizeof(myData));
  //Serial.print("Bytes received: ");
  Serial.println(len);
  Serial.print("Float: ");
  Serial.println(myData.h);
  Serial.println(myData.temp);
}

// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "";
const char* password = "";

AsyncWebServer server(80);
ESPDash dashboard(&server); 

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

//variables températures
int tempConfort=15;
int tempEco=15;

float temperature=myData.temp;
float humidite=myData.h;


bool etatRelais=0;

//activation jour
bool lundi=0;
bool mardi=0;
bool mercredi=0;
bool jeudi=0;
bool vendredi=0;
bool samedi=0;
bool dimanche=0;

//reglage heure chauffage

int lunEcoStart=0;
int lunEcoEnd=0;
int marConf;
int marEco;
int merConf;
int merEco;
int jeuConf;
int jeuEco;
int venConf;
int venEco;
int samConf;
int samEco;
int dimConf;
int dimEco;

// GPIO where the output is connected to
const int output = 2;


void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}



//Dashboard

Card temp(&dashboard, TEMPERATURE_CARD, "Temperature", "°C");
Card h(&dashboard, HUMIDITY_CARD, "Humidity", "%");

Card card1(&dashboard, BUTTON_CARD, "Lundi");
Card card2(&dashboard, SLIDER_CARD, "Eco-Start", "", 0, 24);
Card card3(&dashboard, SLIDER_CARD, "Eco-End", "", 0, 24);

Card card4(&dashboard, BUTTON_CARD, "Mardi");
Card card5(&dashboard, SLIDER_CARD, "Eco-Start", "", 0, 24);
Card card6(&dashboard, SLIDER_CARD, "Eco-End", "", 0, 24);

Card card7(&dashboard, BUTTON_CARD, "Mercredi");
Card card8(&dashboard, SLIDER_CARD, "Eco-Start", "", 0, 24);
Card card9(&dashboard, SLIDER_CARD, "Eco-End", "", 0, 24);

Card card10(&dashboard, BUTTON_CARD, "Jeudi");
Card card11(&dashboard, SLIDER_CARD, "Eco-Start", "", 0, 24);
Card card12(&dashboard, SLIDER_CARD, "Eco-End", "", 0, 24);

Card card13(&dashboard, BUTTON_CARD, "Vendredi");
Card card14(&dashboard, SLIDER_CARD, "Eco-Start", "", 0, 24);
Card card15(&dashboard, SLIDER_CARD, "Eco-End", "", 0, 24);

Card card16(&dashboard, BUTTON_CARD, "Samedi");
Card card17(&dashboard, SLIDER_CARD, "Eco-Start", "", 0, 24);
Card card18(&dashboard, SLIDER_CARD, "Eco-End", "", 0, 24);

Card card19(&dashboard, BUTTON_CARD, "Dimanche");
Card card20(&dashboard, SLIDER_CARD, "Eco-Start", "", 0, 24);
Card card21(&dashboard, SLIDER_CARD, "Eco-End", "", 0, 24);

Card card22(&dashboard, STATUS_CARD, "Confort", "success");
Card card23(&dashboard, STATUS_CARD, "Eco", "success");






void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("WiFi Failed!");
    return;
  }
  Serial.println();
  Serial.print("ESP IP Address: http://");
  Serial.println(WiFi.localIP());

 /* Start AsyncWebServer */
  server.begin();

  
  pinMode(output, OUTPUT);
  digitalWrite(output, LOW);

  // Initialize a NTPClient to get time
  timeClient.begin();
  // Set offset time in seconds to adjust for your timezone, for example:
  //GMT +1 = 3600
  // GMT +8 = 28800
  // GMT -1 = -3600
  // GMT 0 = 0
  timeClient.setTimeOffset(3600);


if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  
  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(OnDataRecv);
}






void loop() {

  timeClient.update();
   

    /*float temp = myData.temp;
    float humidite= myData.h;
    Serial.print(temp);
    Serial.println(" *C");
    Serial.print(h);
    Serial.println(" %H");*/

 /* Update Card Values */
  temp.update(temperature);
  h.update(humidite);
  dashboard.sendUpdates();
  delay(100);

  card1.attachCallback([&](int value){
    lundi=value;
  Serial.println("[Card1] Button Callback Triggered: "+String((value == 1)?"true":"false"));
  card1.update(lundi);
   dashboard.sendUpdates();
   delay(100);
});
card2.attachCallback([&](int value){
  lunEcoStart=value;
  Serial.println("[Card1] Slider Callback Triggered: "+String(value));
  card1.update(lunEcoStart);
  dashboard.sendUpdates();
  delay(100);
});
card2.attachCallback([&](int value){
  lunEcoEnd=value;
  Serial.println("[Card1] Slider Callback Triggered: "+String(value));
  card1.update(lunEcoEnd);
  dashboard.sendUpdates();
  delay(100);
});
}


merci pour votre aide!

Salut,

  • tous les "card1.attachCallback()" doivent etre dans le setup()
  • étant donné ton code, tu peux enlever tous les "dashboard.sendUpdates();" qui sont dans les callback et en laisser juste 1 seul dans la loop
  • enlever tous les delay dans les callback (qui doivent s'exécuter le plus vite possible)
  • il faut faire des temporisations car la loop execute trop de choses qui n'ont pas besoin d'être exécuter si vite

exemple:

unint32_t lastWebsiteUpdate = 0;
unint32_t lastTempUpdate = 0;

void loop() {
    if(millis() - lastWebsiteUpdate > 1000) {
        dashboard.sendUpdates();
        lastWebsiteUpdate = millis();
    }
    if(millis() - lastTempUpdate > 5000) {
        temp.update(temperature);
        h.update(humidite);
        lastTempUpdate = millis();
    }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.