start:arduino:esp32:camsd
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
start:arduino:esp32:camsd [2021/10/15 12:09] – gerardadmin | start:arduino:esp32:camsd [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 356: | Ligne 356: | ||
==== Esp32 cam Serveur ==== | ==== Esp32 cam Serveur ==== | ||
+ | [[https:// | ||
<code c Esp32CamServeur001.ino> | <code c Esp32CamServeur001.ino> | ||
Ligne 623: | Ligne 624: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | |||
+ | ==== ESP32 CAm et Photos ---> sur Google Drive ==== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | <code txt script googledrive.txt> | ||
+ | // Enregistrement sur Google Drive d'une image prise par l' | ||
+ | // trouvé ici: https:// | ||
+ | |||
+ | function doPost(e) { | ||
+ | // décodage des données reçues en base64 | ||
+ | var data = Utilities.base64Decode(e.parameters.data); | ||
+ | // création d'un nom de fichier à partir de la date et de l' | ||
+ | var nomFichier = Utilities.formatDate(new Date(), " | ||
+ | // création d'un blob (binary large object) à partir des données reçues | ||
+ | var blob = Utilities.newBlob(data, | ||
+ | // Dans Google Drive, on récupère tous les répertoires nommés " | ||
+ | var folder, folders = DriveApp.getFoldersByName(" | ||
+ | if (folders.hasNext()) { // s'il y en a | ||
+ | folder = folders.next(); | ||
+ | } else { // s'il n'y en a pas | ||
+ | folder = DriveApp.createFolder(" | ||
+ | } | ||
+ | var file = folder.createFile(blob); | ||
+ | return ContentService.createTextOutput(' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code c esp32camPhotosDrive001.ino > | ||
+ | /* | ||
+ | | ||
+ | |||
+ | Basé sur le sketch de Guillermo Sampallo: | ||
+ | | ||
+ | |||
+ | Plus d' | ||
+ | |||
+ | | ||
+ | |||
+ | */ | ||
+ | |||
+ | #include " | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | const char* ssid = " | ||
+ | const char* password = " | ||
+ | // à remplacer par l'url de votre Google Apps Script: | ||
+ | String urlScript = "/ | ||
+ | |||
+ | const int delaiImage = 60000; // nombre de millisecondes entre 2 enregistrements succesifs | ||
+ | const int delaiReponse = 30000; // nombre de millisecondes max d' | ||
+ | |||
+ | const char* host = " | ||
+ | String nomFichier = " | ||
+ | String mimeType = "& | ||
+ | String monImage = "& | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | delay(10); | ||
+ | |||
+ | WiFi.mode(WIFI_STA); | ||
+ | |||
+ | Serial.println("" | ||
+ | Serial.print(" | ||
+ | Serial.println(ssid); | ||
+ | WiFi.begin(ssid, | ||
+ | |||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | Serial.print(" | ||
+ | delay(500); | ||
+ | } | ||
+ | |||
+ | Serial.println("" | ||
+ | Serial.println(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | |||
+ | Serial.println("" | ||
+ | |||
+ | camera_config_t config; | ||
+ | config.ledc_channel = LEDC_CHANNEL_0; | ||
+ | config.ledc_timer = LEDC_TIMER_0; | ||
+ | config.pin_d0 = 5; | ||
+ | config.pin_d1 = 18; | ||
+ | config.pin_d2 = 19; | ||
+ | config.pin_d3 = 21; | ||
+ | config.pin_d4 = 36; | ||
+ | config.pin_d5 = 39; | ||
+ | config.pin_d6 = 34; | ||
+ | config.pin_d7 = 35; | ||
+ | config.pin_xclk = 0; | ||
+ | config.pin_pclk = 22; | ||
+ | config.pin_vsync = 25; | ||
+ | config.pin_href = 23; | ||
+ | config.pin_sscb_sda = 26; | ||
+ | config.pin_sscb_scl = 27; | ||
+ | config.pin_pwdn = 32; | ||
+ | config.pin_reset = -1; | ||
+ | config.xclk_freq_hz = 20000000; | ||
+ | config.pixel_format = PIXFORMAT_JPEG; | ||
+ | config.frame_size = FRAMESIZE_VGA; | ||
+ | config.jpeg_quality = 10; | ||
+ | config.fb_count = 1; | ||
+ | |||
+ | esp_err_t err = esp_camera_init(& | ||
+ | if (err != ESP_OK) { | ||
+ | Serial.printf(" | ||
+ | delay(1000); | ||
+ | ESP.restart(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | enregistreImage(); | ||
+ | delay(delaiImage); | ||
+ | } | ||
+ | |||
+ | void enregistreImage() { | ||
+ | Serial.println(" | ||
+ | |||
+ | WiFiClientSecure client; | ||
+ | |||
+ | if (client.connect(host, | ||
+ | Serial.println(" | ||
+ | |||
+ | camera_fb_t * fb = NULL; | ||
+ | fb = esp_camera_fb_get(); | ||
+ | if (!fb) { | ||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | ESP.restart(); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | char *input = (char *)fb-> | ||
+ | char output[base64_enc_len(3)]; | ||
+ | String imageFile = ""; | ||
+ | for (int i = 0; i < fb->len; i++) { | ||
+ | base64_encode(output, | ||
+ | if (i % 3 == 0) imageFile += urlencode(String(output)); | ||
+ | } | ||
+ | String Data = nomFichier + mimeType + monImage; | ||
+ | |||
+ | esp_camera_fb_return(fb); | ||
+ | |||
+ | Serial.println(" | ||
+ | |||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println(); | ||
+ | client.print(Data); | ||
+ | int Index; | ||
+ | for (Index = 0; Index < imageFile.length(); | ||
+ | client.print(imageFile.substring(Index, | ||
+ | } | ||
+ | |||
+ | Serial.println(" | ||
+ | long int StartTime = millis(); | ||
+ | while (!client.available()) { | ||
+ | Serial.print(" | ||
+ | delay(100); | ||
+ | if ((StartTime + waitingTime) < millis()) { | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | Serial.println(); | ||
+ | while (client.available()) { | ||
+ | Serial.print(char(client.read())); | ||
+ | } | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | client.stop(); | ||
+ | } | ||
+ | |||
+ | / | ||
+ | |||
+ | // urlencode sert à remplacer les caractères indésirables | ||
+ | // dans une url (par exemple, remplacer un espace par %20`) | ||
+ | |||
+ | // | ||
+ | String urlencode(String str) | ||
+ | { | ||
+ | String encodedString = ""; | ||
+ | char c; | ||
+ | char code0; | ||
+ | char code1; | ||
+ | char code2; | ||
+ | for (int i = 0; i < str.length(); | ||
+ | c = str.charAt(i); | ||
+ | if (c == ' ') { | ||
+ | encodedString += ' | ||
+ | } else if (isalnum(c)) { | ||
+ | encodedString += c; | ||
+ | } else { | ||
+ | code1 = (c & 0xf) + ' | ||
+ | if ((c & 0xf) > 9) { | ||
+ | code1 = (c & 0xf) - 10 + ' | ||
+ | } | ||
+ | c = (c >> 4) & 0xf; | ||
+ | code0 = c + ' | ||
+ | if (c > 9) { | ||
+ | code0 = c - 10 + ' | ||
+ | } | ||
+ | code2 = ' | ||
+ | encodedString += ' | ||
+ | encodedString += code0; | ||
+ | encodedString += code1; | ||
+ | } | ||
+ | yield(); | ||
+ | } | ||
+ | return encodedString; | ||
+ | } | ||
+ | |||
+ | |||
+ | // *************** Encodage de l' | ||
+ | //Copyright (c) 2013 Adam Rudd. | ||
+ | // | ||
+ | |||
+ | const char PROGMEM b64_alphabet[] = " | ||
+ | " | ||
+ | " | ||
+ | |||
+ | int base64_encode(char *output, char *input, int inputLen) { | ||
+ | int i = 0, j = 0; | ||
+ | int encLen = 0; | ||
+ | unsigned char a3[3]; | ||
+ | unsigned char a4[4]; | ||
+ | |||
+ | while (inputLen--) { | ||
+ | a3[i++] = *(input++); | ||
+ | if (i == 3) { | ||
+ | a3_to_a4(a4, | ||
+ | |||
+ | for (i = 0; i < 4; i++) { | ||
+ | output[encLen++] = pgm_read_byte(& | ||
+ | } | ||
+ | i = 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (i) { | ||
+ | for (j = i; j < 3; j++) { | ||
+ | a3[j] = ' | ||
+ | } | ||
+ | |||
+ | a3_to_a4(a4, | ||
+ | |||
+ | for (j = 0; j < i + 1; j++) { | ||
+ | output[encLen++] = pgm_read_byte(& | ||
+ | } | ||
+ | |||
+ | while ((i++ < 3)) { | ||
+ | output[encLen++] = ' | ||
+ | } | ||
+ | } | ||
+ | output[encLen] = ' | ||
+ | return encLen; | ||
+ | } | ||
+ | |||
+ | int base64_enc_len(int plainLen) { | ||
+ | int n = plainLen; | ||
+ | return (n + 2 - ((n + 2) % 3)) / 3 * 4; | ||
+ | } | ||
+ | |||
+ | inline void a3_to_a4(unsigned char * a4, unsigned char * a3) { | ||
+ | a4[0] = (a3[0] & 0xfc) >> 2; | ||
+ | a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4); | ||
+ | a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6); | ||
+ | a4[3] = (a3[2] & 0x3f); | ||
+ | } | ||
+ | </ | ||
+ |
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/camsd.1634292553.txt.gz · Dernière modification : 2023/01/27 16:08 (modification externe)