IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Impossible de se connecter


Sujet :

Arduino

  1. #1
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut Impossible de se connecter
    Bonjour à tous
    je possède un module d'affichage connecté à Google Photos à base de ESP32 ( FireBeetle ESP32 )
    ce module tourne maintenant depuis 2023 sans problème
    mais hier il a refusé de se connecter
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    https://photos.app.goo.gl/xxxxxxxxx
    [HTTPS] begin...
    [HTTPS] GET...
    [HTTPS] return code: -1
    [HTTPS] GET... a échoué, erreur: connection refused
    si par contre je me connecte avec l'url sur Google , celui-ci fonctionne sans problème
    je n'ai pas changé de logiciel
    j'ai pourtant essayé de regarder à la console les erreurs
    je n'ai pas pu recompiler le programme suite à la nouvelle mise à jour d'ESP32 ( version 3.20) , j'ai du revenir à la version 2.0.17
    https://github.com/espressif/arduino-esp32/issues/9989

    je ne m'explique pas ce problème , Google aurait-il renforcé les sécurités mais dans ce cas je n'aurai pas un accès direct avec l'url ?
    je suis un peu déboussolé , si vous avez des conseils je suis preneur car je ne peux plus regarder les photos de mes petits-enfants ....


    merci bien
    pascal
    Fichiers attachés Fichiers attachés

  2. #2
    Membre chevronné
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2022
    Messages
    399
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 21
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2022
    Messages : 399
    Par défaut
    Bonjour,
    Navré si je me plante :
    https://support.google.com/accounts/.../6010255?hl=fr
    Mais tu parles pas de quand tu l'as lance etc ... Donc si ca se trouve c'est cela.
    Depuis janvier 2025, ca remonte certes
    Tu dois configurer dans ton compte google une key que tu rajoutes lors de la connexion.

    Cdt

  3. #3
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    Salut gabi7756

    en fait , je me suis peut-être mal exprimé
    le programme tourne depuis 2023 sans problème , il y a bien sûr un code généré par google pour accéder à l'album
    ce code fait partie intrinsèque de l'URL
    comme je l'ai mis dans le post : https://photos.app.goo.gl/xxxxxxxxx ( xxxxxxxxx étant le code )

    tout ceci fonctionnait parfaitement depuis 2023
    hier , cela s'est bloqué et au reboot, il plante désormais sur le GET
    pourtant si je mets sur Google l'URL je vais sur l'album directement

    pascal

  4. #4
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 938
    Par défaut
    Citation Envoyé par cobra38 Voir le message
    pourtant si je mets sur Google l'URL je vais sur l'album directement
    Avez vous moyen (mode développeur ou autre outil analyse réseau) de voir si l’URL nest pas transformée (passage en https, re-routage vers un autre site etc) - ce que votre navigateur sait faire mais qu’il faut coder sinon.

    Vérifiez aussi les headers passés par le navigateur, certains sont peut être attendus

  5. #5
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    Salut
    Jay M

    (mode développeur ou autre outil analyse réseau)
    pardon pour la question candide mais
    comment fait-on çà stp ?
    le mode développeur , il s'agit de celui de windows ?

  6. #6
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    En regardant de plus près j'ai :

    - Re-téléverser le programme
    - Re-téléverser le fichier Config.txt

    j'aboutis au même constat ce n'est donc pas interne au µC

    il semblerait que Google ait cassé le lien dynamique URL en lien peut-être avec le futur arrêt de Firebase en Aout 2025 (?)
    le lien tel qu'il était n'est donc plus compatible et l'ennui et que je ne sais quoi mettre à la place
    si quelqu'un a rencontré un problème similaire , son aide serait précieuse

    pascal

    EDIT : j'ai vérifié le certificat ( HTTPS ) et il est valable jusqu'en 2036 donc ce n'est pas encore çà ....

  7. #7
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    selon le site initial
    https://www.instructables.com/Google-Photo-Clock/
    il y aurait un souci avec ESP32 mais je n'ai pas tout compris

    j'ai donc essayé de mettre dans le setup () ceci
    "client->setInsecure(); " en lieu et place de
    "client->setCACert(rootCACertificate);"

    mais visiblement sans succès
    erreur 302

  8. #8
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 938
    Par défaut
    Citation Envoyé par cobra38 Voir le message
    comment fait-on çà stp ?
    le mode développeur , il s'agit de celui de windows ?
    Sous Safari ou Chrome au moins (mais je pense que les autres ont cela aussi), vous avez un mode développeur qui permet d'inspecter plus précisément ce qu'il se passe.

  9. #9
    Membre chevronné
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2022
    Messages
    399
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 21
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2022
    Messages : 399
    Par défaut
    Clique droit => inspecter => onglet réseau
    Ou F12 => onglet réseau
    Et tu compares les deux méthodes :
    - Accès direct via url
    - Accès depuis l'Arduino

    Le code de statut de réponse de redirection 302 Found indique que la ressource est temporairement déplacée vers l'URL contenue dans l'en-tête Location
    Quelque chose de disable quelque part ?

    Je reste quand même sur ma proposition de base , certes en accès direct ca fonctionne mais il n'y a pas une histoire de cache (navré je connais pas bien le sujet) ?

  10. #10
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    bonjour à tous

    J'ai bien expérimenté F12 sous Google comme le suggère gabi7756
    ce qui démontre que l'URL change à partir de celui émis dans la barre de recherche
    par contre je ne sais pas comment faire la même manip avec l'arduino qui appelle la même adresse

    Google aurait-il changé son API ?

  11. #11
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 938
    Par défaut
    Citation Envoyé par cobra38 Voir le message
    Google aurait-il changé son API ?
    Ça semble être le cas…(enfin pas l’API car ça fonctionne grâce aux redirections qui font partie de la norme, mais juste le point d’entree effectif )

    Soit vous interprétez la réponse du serveur et suivez le lien comme le fait votre navigateur, soit vous essayez le nouveau lien s’il semble constant

  12. #12
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    Salut Jay M

    Comme je ne trouve pas le problème j'ai attaqué directement Google avec l'URL transformé
    il me trouve mes photos
    mais il se comporte de façon bizarre
    j'ai fait une recopie de la console où l'on peut s'apercevoir que de temps en temps j'ai un code 200 puis ensuite code= -1
    serait-ce la cause de la longueur du buffer car l'URL est maintenant beaucoup plus conséquent
    ton avis ?
    Images attachées Images attachées  

  13. #13
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    Je poursuis mes investigations mais je n'arrive pas comprendre le défaut :

    Si je résume :

    Création sur Google Photos d'un album partagé permettent d'avoir les photos via ESP32 dans un cadre photo dasn lequel les photos sont affichées toutes les minutes
    durant + 2 ans çà a fonctionné puis brusquement code = -1 plus d'accès

    Pour m'affranchir d'un quelconque piratage , j'ai créé un autre album partagé avec 3 photos
    J'ai essayé de me reconnecter sans résultat code : -1
    j'ai essayé de me connecter avec le lien direct donné par Google et là j'ai bien un code : 200 puis le chargement et l'affichage de la 1ere photo
    mais après, je retrouve mon code : -1 ( alors que lien https fonctionne lorsque je l'inscris via le moteur de recherche )

    je remets le code à toute fin utile
    si vous avez quelques conseils , je suis preneur
    merci encore
    pascal

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
     
    *******************************************************************************
     * Google Photo Clock
     * Il s'agit d'un simple exemple de cadre photo IoT
     * https://www.instructables.com/id/Google-Photo-Clock/
     *
     * Charger => Config.txt avec ESP2 Sketch Data Upload
     *
     * DOIT ESP32 DEVKIT V1
     * Upload Speed = 921600
     * Flash Frequency = 80MHz
     * Core debug = Rien
     ******************************************************************************/
     
     
    /* Google Photo settings */
     
    #define PHOTO_URL_PREFIX "https://lh3.googleusercontent.com/"
    #define SEEK_PATTERN "id=\"_ij\""
    #define SEARCH_PATTERN "\",[\"" PHOTO_URL_PREFIX
     
     
    #define PHOTO_LIMIT 200                                    // lire les 200 premières photos de la liste, ESP32 peut en ajouter d'autres.
    #define PHOTO_ID_SIZE 159                                  //la photo d'identité doit comporter 158 caractères, puis ajouter une queue de zéro.
     
    #define HTTP_TIMEOUT 60000                                 // en ms, attendre un moment pour le traitement du serveur
     
     
    #define HTTP_WAIT_COUNT 10                                 // nombre de fois où l'on attend le prochain tronc du paquet HTTP
    #define PHOTO_URL_TEMPLATE PHOTO_URL_PREFIX "%s=w%d-h%d-c" // identifiant de la photo, largeur et hauteur d'affichage
     
    /* NTP settings */
    #define NTP_SERVER "pool.ntp.org"
    #define DAYLIGHT_OFFSET_SEC 0L // no daylight saving
     
    /* display settings */
    #include <Arduino_GFX_Library.h>
    //#define TFT_BL 22
    Arduino_DataBus *bus = new Arduino_ESP32SPI(27 /* DC */, 5 /* CS */,18 /* SCK */, 23 /* MOSI */, GFX_NOT_DEFINED /* MISO */);
    Arduino_GFX *gfx = new Arduino_ILI9488_18bit(bus,33 /* RST */, 1 /* rotation */);
     
     
    /* WiFi and HTTPS */
    #include "esp_jpg_decode.h"
    #include <esp_task_wdt.h>
    #include <WiFi.h>
    #include <WiFiMulti.h>
    #include <HTTPClient.h>
    #include <WiFiClientSecure.h>
    #include "SPIFFS.h" 
    // HTTPS howto: https://techtutorialsx.com/2017/11/18/esp32-arduino-https-get-request/
    const char* rootCACertificate = \
    
    "-----BEGIN CERTIFICATE-----\n" \
    "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\n" \
    "-----END CERTIFICATE-----\n";
     
     
    WiFiMulti WiFiMulti;
    WiFiClientSecure *client = new WiFiClientSecure;
     
    /* file system */
    #include <FFat.h>
    #include <LittleFS.h>
     
    /* time library */
    #include <time.h>
    static time_t now;
     
    /* HTTP */
    const char *headerkeys[] = {"Location"};
     
    /* Google photo */
    char photoIdList[PHOTO_LIMIT][PHOTO_ID_SIZE];
    uint8_t *photoBuf;
     
    /* variables */
    static int w, h, timeX, timeY, len, offset, photoCount;
    static uint8_t textSize;
    static unsigned long next_show_millis = 0;
    static bool shownPhoto = false;
    signed char TIMEZONE = 0;
    String photo = String("");
    String lat   = String("");
    String lon   = String("");
    String user  = String("");
    String pass  = String("");
    String appid = String("");
     
    //*************************************************************
    void ntpGetTime()
    {
      // Initialize NTP settings
      configTime(TIMEZONE*3600L, DAYLIGHT_OFFSET_SEC, NTP_SERVER); // <== TIMEZONE de Config.txt
     
      gfx->setTextColor(GREEN);
      gfx->print(F("Waiting for NTP time sync: "));
      Serial.print(F("Waiting for NTP time sync: "));
      time_t nowSecs = time(nullptr);
      while (nowSecs < 8 * 3600 * 2)
      {
        delay(500);
        Serial.print('.');
        gfx->print('.');
        yield();
        nowSecs = time(nullptr);
      }
      gfx->println(F(" done."));
      Serial.println(F(" done."));
      gfx->setTextColor(BLUE);
      gfx->println(asctime(localtime(&nowSecs)));
      Serial.println(asctime(localtime(&nowSecs)));
    }
     
    //****************************************************************
    void printTime()
    {
      now = time(nullptr);
      const tm *tm = localtime(&now);
      int hour = tm->tm_hour;
      int min = tm->tm_min;
      // set text size with pixel margin
      gfx->setTextSize(textSize, textSize, 3); // <==
      if (!shownPhoto)
      {
        // imprimer l'heure sur fond noir
        gfx->setCursor(timeX, timeY);
        gfx->setTextColor(WHITE, BLACK);
     
    	if (hour<10){     // suppression du 0 
    		gfx->setCursor(timeX+60, timeY);	
    	    gfx->printf("%01d:%02d", hour, min);
    	} else {
    		gfx->printf("%02d:%02d", hour, min);
    	}	
     
      } else {
     
    	if (hour<10){  
    		gfx->setCursor(timeX+60 - 1, timeY - 1);
    		gfx->setTextColor(DARKGREY);
    		gfx->printf("%01d:%02d", hour, min);
    		gfx->setCursor(timeX+60 + 2, timeY + 2);
    		gfx->setTextColor(BLACK);
    		gfx->printf("%01d:%02d", hour, min);
    		gfx->setCursor(timeX+60, timeY);
    		gfx->setTextColor(WHITE);
    		gfx->printf("%01d:%02d", hour, min);  
    	} else {  
    		// imprimer l'heure avec une bordure
    		gfx->setCursor(timeX - 1, timeY - 1);
    		gfx->setTextColor(DARKGREY);
    		gfx->printf("%02d:%02d", hour, min);
    		gfx->setCursor(timeX + 2, timeY + 2);
    		gfx->setTextColor(BLACK);
    		gfx->printf("%02d:%02d", hour, min);
    		gfx->setCursor(timeX, timeY);
    		gfx->setTextColor(WHITE);
    		gfx->printf("%02d:%02d", hour, min);
    	}   
      }
    }
     
    //*****************************************************
    // SETUP
    //*****************************************************
     
    void setup()
    {
      Serial.begin(115200);
      SPIFFS.begin();
     
      // init display
      gfx->begin();
      gfx->fillScreen(BLACK);
    	#ifdef TFT_BL
    	  // turn on display backlight
    	  pinMode(TFT_BL, OUTPUT);
    	  digitalWrite(TFT_BL, HIGH);
    	#endif
     
      w = gfx->width();
      h = gfx->height();
      textSize = w / 6 / 5;
      timeX = (w - (textSize * 5 * 6)) / 2;
      timeY = h - (textSize * 8) - 10;
     
      gfx->setTextSize(1);
      gfx->setCursor(0, 0);
      gfx->setTextColor(RED);
      gfx->println(F("Google Photo Clock"));
      Serial.println(F("Google Photo Clock"));
      gfx->setTextColor(ORANGE);
      gfx->print(F("Screen: "));
      Serial.print(F("Screen: "));
      gfx->print(w);
      Serial.print(w);
      gfx->print('x');
      Serial.print('x');
      gfx->println(h);
      Serial.println(h);
      gfx->setTextColor(YELLOW);
      gfx->print(F("Clock text size: "));
      Serial.print(F("Clock text size: "));
      gfx->println(textSize);
      Serial.println(textSize);
     
    	if (do_read_config_txt()){
    	gfx->println(F("Config.txt => Ok "));
        Serial.println(F("Config.txt => Ok "));
    	}else {
    	  gfx->setTextColor(RED);
        gfx->println(F("Config.txt => Erreur "));
        Serial.println(F("Config.txt => Erreur"));
    	  delay(1000);
    	}
     
       // init WiFi
      gfx->setTextColor(GREENYELLOW);
      gfx->print(F("Connecting to WiFi: "));
      Serial.print(F("Connecting to WiFi: "));
      WiFi.mode(WIFI_STA);
      //WiFiMulti.addAP(SSID_NAME, SSID_PASSWORD);
      WiFiMulti.addAP(user.c_str(),pass.c_str());
      while ((WiFiMulti.run() != WL_CONNECTED))
      {
        delay(500);
        gfx->print('.');
        Serial.print('.');
      }
      gfx->println(F(" done."));
      Serial.println(F(" done."));
     
      // init time
      ntpGetTime();
     
     
     client->setCACert(rootCACertificate);
     
      // set WDT timeout a little bit longer than HTTP timeout
      esp_task_wdt_init((HTTP_TIMEOUT / 1000) + 1, true);
      enableLoopWDT();
     
      // allocate photo file buffer
      photoBuf = (uint8_t *)malloc(w * h * 3 / 5);
      if (!photoBuf)
      {
        Serial.println(F("L'allocation de photoBuf a échoué!"));
      }
     
     // imprimer le temps sur l'écran noir avant le téléchargement de l'image
      printTime();
    }
     
    //*****************************************************
    // LOOP
    //*****************************************************
    void loop()
    {
      if (WiFiMulti.run() != WL_CONNECTED)
      {
        // wait for WiFi connection
        delay(500);
      }
      else if (millis() < next_show_millis)
      {
        delay(1000);
      } else {
        HTTPClient https;
     
        if (!photoCount)
        {
    	    https.collectHeaders(headerkeys, sizeof(headerkeys) / sizeof(char *));
        	gfx->setTextSize(1);
    		  gfx->setCursor(0, 64);
    		  gfx->setTextColor(RED);
    		  gfx->println(photo);    // <== photo de Config.txt
    	    Serial.println(photo);
    		  gfx->setTextColor(ORANGE);
    		  gfx->println(F("[HTTPS] begin..."));
    		  Serial.println(F("[HTTPS] begin..."));
    		  https.begin(*client,photo.c_str());   // <== photo de Config.txt
       	  https.setTimeout(HTTP_TIMEOUT);
          gfx->setTextColor(YELLOW);
    		  gfx->println(F("[HTTPS] GET..."));
    		  Serial.println(F("[HTTPS] GET..."));
    		  int httpCode = https.GET();
            gfx->setTextColor(GREENYELLOW);
    		gfx->print(F("[HTTPS] return code: "));
    		Serial.print(F("[HTTPS] return code: "));
    		gfx->println(httpCode);
    		Serial.println(httpCode);
     
    		  // redirect
    		  if (httpCode == HTTP_CODE_FOUND)
    		  {
    			char redirectUrl[256];
    			strcpy(redirectUrl, https.header((size_t)0).c_str());
    			https.end();
    			gfx->setTextColor(GREEN);
    			gfx->print(F("redirectUrl: "));
    			Serial.print(F("redirectUrl: "));
    			gfx->println(redirectUrl);
    			Serial.println(redirectUrl);
     
    			gfx->setTextColor(BLUE);
    			gfx->println(F("[HTTPS] begin..."));
    			Serial.println(F("[HTTPS] begin..."));
    			https.begin(*client, redirectUrl);
    			https.setTimeout(HTTP_TIMEOUT);
     
    			gfx->setTextColor(MAGENTA);
    			gfx->println(F("[HTTPS] GET..."));
    			Serial.println(F("[HTTPS] GET..."));
    			httpCode = https.GET();
     
    			gfx->setTextColor(RED);
    			gfx->print(F("[HTTPS] GET... code: "));
    			Serial.print(F("[HTTPS] GET... code: "));
    			gfx->println(httpCode);
    			Serial.println(httpCode);
    		  }
     
          if (httpCode != HTTP_CODE_OK)
          {
            gfx->setTextColor(ORANGE);
            gfx->print(F("[HTTPS] GET... a echoue, erreur: "));
            Serial.print(F("[HTTPS] GET... a echoue, erreur: "));
            gfx->println(https.errorToString(httpCode));
            Serial.println(https.errorToString(httpCode));
            delay(9000); // don't repeat the wrong thing too fast
            // return;
          }
          else
          {
            // L'en-tête HTTP a été envoyé et l'en-tête de réponse du serveur a été traité.
     
            //find photo ID leading pattern: ",["https://lh3.googleusercontent.com/
            photoCount = 0;
            int wait_count = 0;
            bool foundStartingPoint = false;
            WiFiClient *stream = https.getStreamPtr();
            stream->setTimeout(10);
            while ((photoCount < PHOTO_LIMIT) && (wait_count < HTTP_WAIT_COUNT))
            {
              if (!stream->available())
              {
                gfx->print('.');
                Serial.println(F("Flux d'attente->available()"));
                ++wait_count;
                delay(200);
              }
              else
              {
                if (!foundStartingPoint)
                {
                  gfx->setTextColor(ORANGE);
                  gfx->println(F("chercher un modele: " SEEK_PATTERN));
                  Serial.println(F("chercher un modele: " SEEK_PATTERN));
                  if (stream->find(SEEK_PATTERN))
                  {
                    gfx->setTextColor(YELLOW);
                    gfx->println(F("modele: " SEEK_PATTERN));
                    Serial.println(F("modele: " SEEK_PATTERN));
                    foundStartingPoint = true;
                  }
                } else {
                   if (stream->find(SEARCH_PATTERN))
                   {
    					int i = -1;
    					char c = stream->read();
    					while (c != '\"')
    					{
    					  photoIdList[photoCount][++i] = c;
    					  c = stream->read();
    					}
    					photoIdList[photoCount][++i] = 0; // zero tail
    					gfx->setTextColor(GREENYELLOW);
    					gfx->print('*');
    					Serial.println(photoIdList[photoCount]);
    					++photoCount;
                   }
                }
              }
              // notify WDT still working
              feedLoopWDT();
            }
            gfx->setTextColor(GREEN);
            gfx->print(photoCount);
            gfx->println(F(" photo ID added."));
            Serial.print(photoCount);
            Serial.println(F(" photo ID added."));
     
          }
          https.end();
        } else {// photoCount > 0
     
    		  //char photoUrl[256];
          char photoUrl[512];
     
    		  // UNCOMMENT FOR DEBUG PHOTO LIST
    		  // for (int i = 0; i < photoCount; i++)
    		  // {
    		  //   sprintf(photoUrl, PHOTO_URL_TEMPLATE, photoIdList[i], w, h);
    		  //   Serial.printf("%d: %s\n", i, photoUrl);
    		  // }
     
    		  // configurer la valeur de la requête url avec la dimension LCD
    		  int randomIdx = random(photoCount);
    		  File cachePhoto;
    		  char filename[16];
    		  sprintf(filename, "/%d.jpg", randomIdx);
     
    		  if (!(cachePhoto = FFat.open(filename, "r"))) // if (!(cachePhoto = LittleFS.open(filename, "r")))
    		  {
    			sprintf(photoUrl, PHOTO_URL_TEMPLATE, photoIdList[randomIdx], w, h);
    			Serial.print(F("Random selected photo #"));
    			Serial.print(randomIdx);
    			Serial.print(':');
    			Serial.println(photoUrl);
     
    			Serial.println(F("[HTTP] begin..."));
    			https.begin(*client, photoUrl);
    			https.setTimeout(HTTP_TIMEOUT);
    			Serial.println(F("[HTTP] GET..."));
    			int httpCode = https.GET();
     
    			Serial.print(F("[HTTP] GET... code: "));
    			Serial.println(httpCode);
    			// HTTP header has been send and Server response header has been handled
    			if (httpCode != HTTP_CODE_OK)
    			{
    			  Serial.print(F("[HTTP] GET... failed, error: "));
    			  Serial.println(https.errorToString(httpCode));
    			  delay(9000); // don't repeat the wrong thing too fast
    			} else {
     
    			   // obtenir la longueur du document (-1 si le serveur n'envoie pas d'en-tête Content-Length).
    			  len = https.getSize();
    			  Serial.print(F("[HTTP] size: "));
    			  Serial.println(len);
     
    			  if (len <= 0)
    			  {
    				Serial.print(F("[HTTP] Unknow content size: "));
    				Serial.println(len);
    			  }
    			  else
    			  {
    				// récupérer le flux tcp
    				WiFiClient *photoHttpsStream = https.getStreamPtr();
     
    				if (photoBuf)
    				{
    				  // Décodage JPG option 1 : buffer_reader, utilise beaucoup plus de mémoire mais est plus rapide.
    				  size_t reads = 0;
    				  while (reads < len)
    				  {
    					size_t r = photoHttpsStream->readBytes(photoBuf + reads, (len - reads));
    					reads += r;
    					Serial.print(F("Photo buffer read: "));
    					Serial.print(reads);
    					Serial.print('/');
    					Serial.println(len);
    				  }
    				  esp_jpg_decode(len, JPG_SCALE_NONE, buffer_reader, tft_writer, NULL /* arg */);
    				}
    				else
    				{
    				  // Option de décodage JPG 2 : téléchargement dans un fichier cache
    				  Serial.print(F("Cache photo: "));
    				  Serial.println(filename);
    				  cachePhoto = FFat.open(filename, "w");
    				  // cachePhoto = LittleFS.open(filename, "w");
     
    				  if (cachePhoto)
    				  {
    					uint8_t buf[512];
    					size_t reads = 0;
    					while (reads < len)
    					{
    					  size_t r = photoHttpsStream->readBytes(buf, min(sizeof(buf), len - reads));
    					  reads += r;
    					  cachePhoto.write(buf, r);
    					  // Serial.print(F("Photo file write: "));
    					  // Serial.print(reads);
    					  // Serial.print('/');
    					  // Serial.println(len);
    					}
    					cachePhoto.close();
    					cachePhoto = FFat.open(filename, "r");
    					// cachePhoto = LittleFS.open(filename, "r");
     
    				  }
    				  else
    				  {
    					// Décodage JPG option 3 : stream_reader, décodage à la volée mais plus lent
    					esp_jpg_decode(len, JPG_SCALE_NONE, stream_reader, tft_writer, &photoHttpsStream /* arg */);
    				  }
    				}
    			  }
    			}
            https.end();
          }
          if (cachePhoto)
          {
            Serial.print(F("Chargement du cache photo: "));
            Serial.println(filename);
            esp_jpg_decode(cachePhoto.size(), JPG_SCALE_NONE, stream_reader, tft_writer, &cachePhoto /* arg */);
            cachePhoto.close();
          }
          shownPhoto = true;
          next_show_millis = ((millis() / 60000L) + 1) * 60000L; // minute +1
        }
     
        // superposer l'heure actuelle sur la photo
        // printTime();
      }
      // notify WDT still working
      feedLoopWDT();
    }
     
    //*************************************************************
    static size_t stream_reader(void *arg, size_t index, uint8_t *buf, size_t len)
    {
      Stream *s = (Stream *)arg;
      if (buf)
      {
        // Serial.printf("[HTTP] read: %d\n", len);
        size_t a = s->available();
        size_t r = 0;
        while (r < len)
        {
          r += s->readBytes(buf + r, min((len - r), a));
          delay(50);
        }
        return r;
      } else {
    		// Serial.printf("[HTTP] skip: %d\n", len);
    		int l = len;
    		while (l--)
    		{
    		  s->read();
    		}
    		return len;
      }
    }
     
    //*************************************************************
    static size_t buffer_reader(void *arg, size_t index, uint8_t *buf, size_t len)
    {
      if (buf)
      {
        memcpy(buf, photoBuf + index, len);
      }
      return len;
    }
     
    //*************************************************************
    static bool tft_writer(void *arg, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t *data)
    {
      if (data)
      {
        // Serial.printf("%d, %d, %d, %d\n", x, y, w, h);
        gfx->draw24bitRGBBitmap(x, y, data, w, h);
      }
      // notify WDT still working
      feedLoopWDT();
     
      return true; // Continue to decompression
    }
    Images attachées Images attachées  

Discussions similaires

  1. Impossible de me connecter à PhpPgAdmin
    Par BRAUKRIS dans le forum PostgreSQL
    Réponses: 12
    Dernier message: 06/11/2007, 20h19
  2. [ postgresql] impossible de se connecter
    Par hocinema dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 11/07/2005, 12h10
  3. [Debutant]Impossible de se connecter au serveur local
    Par Kenji dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 24/04/2005, 20h55
  4. Impossible de se connecter avec aMSN
    Par Blowih dans le forum Applications et environnements graphiques
    Réponses: 5
    Dernier message: 29/07/2004, 15h51
  5. [Connexion] impossible de se connecter autrement qu'en local
    Par sekiryou dans le forum Installation
    Réponses: 4
    Dernier message: 29/03/2004, 17h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo