Modifier valeur dans setup

Bonjour,
Dans mon programme je cherche à pouvoir modifier la valeur du setup "qrcode.create("lego01012022/1");"
Qui ajoute un code barre sur un écran.
Je ne sais pas comment modifier cette valeur en requête http comme je le fais dans mon loop pour les couleurs de mon anneau.
Car si je met ma ligne dans le loop mon écran clignote.
Merci d'avance

//LED
#include <WiFi.h>
#include <FastLED.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <qrcode_st7735.h>



#define TFT_RST   25
#define TFT_CS    27
#define TFT_DC    26
#define DATA_PIN 4
#define NUM_LEDS 16
#define CLOCK_PIN 13

#define TFTMODEL INITR_18GREENTAB

Adafruit_ST7735 display = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
QRcode_ST7735 qrcode (&display);



CRGB leds[NUM_LEDS];

int reqPos,req,colorPos,EOL;
uint32_t color;
String reqString,colorString;
// Custom LED Function


void circling(int time, uint32_t color) {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = color;
    FastLED.show();
    delay(time);
  }
}

void FadeIn() {
  for (int i = 255; i >= 0; i--) {
    FastLED.setBrightness(i);
    FastLED.show();
    delay(10);
  }
}

void FadeOut() {
  for (int i = 0; i <= 255; i++) {
    FastLED.setBrightness(i);
    FastLED.show();
    delay(10);
  }
}

void DividedCircle(int tClients,int cClient,uint32_t color,int time){
int LED_START = 0;
  for (int i=0;i<tClients;i++){
    for (int j = LED_START; j < NUM_LEDS; j++) {
    leds[j] = color;
    FastLED.show();
    delay(time);
  }
  LED_START = LED_START + NUM_LEDS/tClients;
  }
}

void Fill(int time, uint32_t color) {
  for (int i = 0; i <= NUM_LEDS; i++) {
    leds[i] = color;
    FastLED.show();
    delay(time);
  }
}

void Half(int time, uint32_t color,int side){
  switch (side){
    case 1:
    for(int i = 0; i< NUM_LEDS/2;i++){
    leds[i] = color;
    FastLED.show();
    delay(time);
      }
    break;
    case 2:
  for(int i = NUM_LEDS/2;i<NUM_LEDS;i++){
    leds[i] = color;
    FastLED.show();
    delay(time);
     }
    break;
  }
}

void FillHalf(int time, uint32_t color){

}

long int ConvertStringHexToInt(String input){
  const String hexDigits = "0123456789ABCDEF";
  long int result = 0;
  input.toUpperCase();
  for (int i = 0; i < input.length(); i++) {
    result <<= 4;
    result |= hexDigits.indexOf(input[i]);
  }  
  return(result);
}

const char* ssid = "******";
const char* password = "******";

//Attribue le port 80 au serveur
WiFiServer server(80);

// Variable pour stocker les requête HTTP
String header;
//Temp actuelle
unsigned long currentTime = millis();
//Temps précédents
unsigned long previousTime = 0;
// Temps max avant Time out
const long timeoutTime = 2000;

void initWifi(const char* SSID, const char* PASSWORD) {
  WiFi.mode(WIFI_STA);         // Mode Station de l'ESP (L'ESP ce connecte a un points d'accès)
  WiFi.begin(SSID, PASSWORD);  // Initialisation du wifi
  while (WiFi.status() != WL_CONNECTED) {
    circling(50, CRGB::White);
    circling(50, CRGB::Black);
  }
  Serial.print("IP :");
  Serial.println(WiFi.localIP());
  server.begin();
}

void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  initWifi(ssid, password);
  Serial.begin(115200);
    Serial.println("");
    Serial.println("Starting...");

    // enable debug qrcode
    // qrcode.debug();
    display.initR(TFTMODEL);
    // Initialize QRcode display using library
    qrcode.init();
    // create qrcode
    // UPS01012022/1
    qrcode.create("lego01012022/1");
}

void loop() {
  FastLED.show();
  WiFiClient client = server.available();
   if (client) {                             // If a new client connects,
    currentTime = millis();
    previousTime = currentTime;
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected() && currentTime - previousTime <= timeoutTime) {  // loop while the client's connected
      currentTime = millis();
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
            // Exemple de requêtes : ?req=2&color=0x8B0000$
            if (header.indexOf("GET /?req=") >= 0) {
              reqPos = header.indexOf("req=");
              colorPos = header.indexOf("&color=0x");
              EOL = header.indexOf('$');
              reqString = header.substring(reqPos+4,colorPos);
              colorString = header.substring(colorPos+9,EOL);
              req = reqString.toInt();
              color = ConvertStringHexToInt(colorString);
              switch (req){
              case 1:
              Fill(10,color);
              break;
              case 2:
              Half(10,color,1);
              break;
              case 3:
              Half(10,color,2);
              break;
              case 4:
              Fill(10,0x000000);
              break;
              }
            }
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/off buttons 
            // Feel free to change the background-color and font-size attributes to fit your preferences
            // Web Page Heading
            client.println("</body></html>");
            
            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
}

Je ne sais pas exactement ce que vous faites ni ce qui est cette classe QR code mais généralement quand un écran clignote C’est parce que on affiche constamment la même valeur en effaçant l’écran.

Pour résoudre ce problème, il faut tester si la valeur affichée change ou pas.

Il ne clignote pas dans le setup mais il clignote dans ma boucle comme modifier la valeur en webservice du setup ?

Il ne clignote pas dans le setup parce que vous ne passez qu’une seule fois dans le setup

je lis cela sur mon iPhone Donc je ne peux pas trop analyser le code en détail, que faites vous exactement en qu’est-ce qui clignote ?

J'affiche un qrcode et je voudrais depuis une requête http modifier la valeur et le réafficher.

Merci je viens de trouver

Vachement sympa : j'ai ma réponse, je me la garde, rien à fiche si cela pourrait servir à d'autre.

Ici c'est un site d'entre-aide et de partage.
C'est bien du partage que tu es venu cherché ?
Si tu ne veux pas partager ce n'est pas le bon endroit.

J'ai fait comme tu as dit si ma valeur ne change pas je ne la réaffiche pas.

généralement on poste le code final qui fonctionne pour aider le prochain qui aura le même souci

Ok pas de souci voici le code désolé.
Bon journée à vous

//LED
#include <WiFi.h>
#include <FastLED.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <qrcode_st7735.h>

#define display_RST   25
#define display_CS    27
#define display_DC    26
#define DATA_PIN 4
#define NUM_LEDS 16
#define CLOCK_PIN 13

#define displayMODEL INITR_18GREENTAB

Adafruit_ST7735 display = Adafruit_ST7735(display_CS, display_DC, display_RST);
QRcode_ST7735 qrcode (&display);

CRGB leds[NUM_LEDS];

int reqPos,req,colorPos,qrcodePos,EOL;
uint32_t color;
String reqString,colorString,qrcodeString,OldQRCode;

const char* ssid = "*******";
const char* password = "*********";

//Attribue le port 80 au serveur
WiFiServer server(80);

// Variable pour stocker les requête HTTP
String header;
//Temp actuelle
unsigned long currentTime = millis();
//Temps précédents
unsigned long previousTime = 0;
// Temps max avant Time out
const long timeoutTime = 2000;

void circling(int time, uint32_t color) {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = color;
    FastLED.show();
    delay(time);
  }
}

void FadeIn() {
  for (int i = 255; i >= 0; i--) {
    FastLED.setBrightness(i);
    FastLED.show();
    delay(10);
  }
}

void FadeOut() {
  for (int i = 0; i <= 255; i++) {
    FastLED.setBrightness(i);
    FastLED.show();
    delay(10);
  }
}

void Fill(int time, uint32_t color) {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = color;
    FastLED.show();
    delay(time);
  }
}

void Half(int time, uint32_t color,int side){
  switch (side){
    case 1:
    for(int i = 0; i < NUM_LEDS/2;i++){
    leds[i] = color;
    FastLED.show();
    delay(time);
      }
    break;
    case 2:
  for(int i = NUM_LEDS/2;i<NUM_LEDS;i++){
    leds[i] = color;
    FastLED.show();
    delay(time);
     }
    break;
  }
}

long int ConvertStringHexToInt(String input){
  const String hexDigits = "0123456789ABCDEF";
  long int result = 0;
  input.toUpperCase();
  for (int i = 0; i < input.length(); i++) {
    result <<= 4;
    result |= hexDigits.indexOf(input[i]);
  }  
  return(result);
}

void initWifi(const char* SSID, const char* PASSWORD) {
  WiFi.mode(WIFI_STA);         // Mode Station de l'ESP (L'ESP ce connecte a un points d'accès)
  WiFi.begin(SSID, PASSWORD);  // Initialisation du wifi
  while (WiFi.status() != WL_CONNECTED) {
    circling(50, CRGB::White);
    circling(50, CRGB::Black);
  }
  Serial.print("IP :");
  Serial.println(WiFi.localIP());
  server.begin();
}

void Get_IPAddress(WiFiEvent_t event, WiFiEventInfo_t info){

  Serial.println(WiFi.localIP());
}

void Wifi_disconnected(WiFiEvent_t event, WiFiEventInfo_t info){

  Serial.println(info.disconnected.reason);

  WiFi.begin(ssid, password);
}

void displayLibre() {
  display.setRotation(1);
  display.setTextWrap(false);
  display.fillScreen(ST7735_BLACK);
  display.setCursor(16, 20);
  display.setTextColor(ST7735_RED);
  display.setTextSize(2);
  display.println("Mode libre!");
  display.setCursor(36, 50);
  display.setTextColor(ST7735_YELLOW);
  display.setTextSize(2);
  display.println("Ajouter");
  display.setCursor(32, 80);
  display.setTextColor(ST7735_GREEN);
  display.setTextSize(2);
  display.println("Palette!");
}

void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  initWifi(ssid, password);
  display.initR(INITR_BLACKTAB);
  qrcode.init();
  WiFi.onEvent(Get_IPAddress, SYSTEM_EVENT_STA_GOT_IP);
  WiFi.onEvent(Wifi_disconnected, SYSTEM_EVENT_STA_DISCONNECTED); 
}

void loop() {
  FastLED.show();
  WiFiClient client = server.available();
   if (client) {                             // If a new client connects,
    currentTime = millis();
    previousTime = currentTime;
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected() && currentTime - previousTime <= timeoutTime) {  // loop while the client's connected
      currentTime = millis();
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        //Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
            // Exemple de requêtes : ?req=2&color=0x8B0000$
            if (header.indexOf("GET /?req=") >= 0) {
              reqPos = header.indexOf("req=");
              colorPos = header.indexOf("&color=0x");
              EOL = header.indexOf('$');
              reqString = header.substring(reqPos+4,colorPos);
              colorString = header.substring(colorPos+9,EOL);
              req = reqString.toInt();
              color = ConvertStringHexToInt(colorString);
              switch (req){
              case 1:
              Fill(10,color);
              break;
              case 2:
              Half(10,color,1);
              break;
              case 3:
              Half(10,color,2);
              break;
              case 4:
              Fill(10,0x000000);
              break;
              }
            }
            if (header.indexOf("GET /?qrcode=") >= 0){
              qrcodePos = header.indexOf("qrcode=");
              EOL = header.indexOf('$');
              qrcodeString = header.substring(qrcodePos+7,EOL);
              if (qrcodeString != OldQRCode){
                display.setCursor(0,0);
                display.setRotation(0);
                qrcode.create(qrcodeString);
                OldQRCode = qrcodeString;
              }
            }
            if (header.indexOf("GET /libre") >= 0){
              OldQRCode = "";
              displayLibre();                
            }
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/off buttons 
            // Feel free to change the background-color and font-size attributes to fit your preferences
            // Web Page Heading
            client.println("</body></html>");
            
            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
}

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