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("");
}
}