start:arduino:esp32:telegram
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:telegram [2021/10/31 13:15] – [ESP 32 Cam 002] gerardadmin | start:arduino:esp32:telegram [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 4: | Ligne 4: | ||
| {{ : | {{ : | ||
| + | |||
| + | ====== ESP32 Cam Telegram + Detection ====== | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | [[https:// | ||
| ====== ESP32 cam 001 ====== | ====== ESP32 cam 001 ====== | ||
| Ligne 11: | Ligne 17: | ||
| ==== Présentation du télégram ==== | ==== Présentation du télégram ==== | ||
| - | **Telegram Messenger** est un service de messagerie instantanée et de voix sur IP basé sur le cloud. Vous pouvez facilement l' | + | **[[https:// |
| « Les bots sont des applications tierces qui s' | « Les bots sont des applications tierces qui s' | ||
| Ligne 718: | Ligne 724: | ||
| [[https:// | [[https:// | ||
| + | ==== Télégramme ESP32-CAM : envoyer l' | ||
| + | |||
| + | |||
| + | ===Comment créer un bot Telegram=== | ||
| + | |||
| + | La première étape consiste à créer un bot Telegram. Vous pouvez télécharger l' | ||
| + | |||
| + | |||
| + | Tapez ensuite la commande /newbot et donnez un nom à votre bot : | ||
| + | |||
| + | ===Intégration d' | ||
| + | |||
| + | Une fois que nous avons créé notre bot Telegram, nous pouvons l' | ||
| + | Installation du bot Universal Arduino Telegram dans l'IDE Arduino | ||
| + | |||
| + | Ouvrez l'IDE Arduino et dans le menu Sketch, sélectionnez Inclure l' élément de bibliothèque , puis Gérer la bibliothèque. Recherchez le télégramme universel Arduino et installez-le. | ||
| + | |||
| + | Assurez-vous que la version installée est la dernière. Sinon, vous pouvez cloner le dépôt github : | ||
| + | |||
| + | puis ajoutez la bibliothèque .zip. | ||
| + | |||
| + | ===Esquisse ESP32-CAM=== | ||
| + | |||
| + | Créez une nouvelle esquisse, puis ajoutez le code suivant : | ||
| + | |||
| + | <code c esp32cam-telegramm002.ino> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include " | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | |||
| + | #define BOT_TOKEN " | ||
| + | #define _debug | ||
| + | |||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | WiFiClientSecure client; | ||
| + | UniversalTelegramBot bot(BOT_TOKEN, | ||
| + | |||
| + | long bot_last_check; | ||
| + | int bot_check_interval = 3000; | ||
| + | |||
| + | bool hasMoreData; | ||
| + | camera_fb_t * fb = NULL; | ||
| + | |||
| + | bool hasMoreDataAvailable(); | ||
| + | byte* getNextBuffer(); | ||
| + | int getBufferLen(); | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(9600); | ||
| + | Serial.setDebugOutput(true); | ||
| + | Serial.println(); | ||
| + | |||
| + | camera_config_t config; | ||
| + | config.ledc_channel = LEDC_CHANNEL_0; | ||
| + | config.ledc_timer = LEDC_TIMER_0; | ||
| + | config.pin_d0 = Y2_GPIO_NUM; | ||
| + | config.pin_d1 = Y3_GPIO_NUM; | ||
| + | config.pin_d2 = Y4_GPIO_NUM; | ||
| + | config.pin_d3 = Y5_GPIO_NUM; | ||
| + | config.pin_d4 = Y6_GPIO_NUM; | ||
| + | config.pin_d5 = Y7_GPIO_NUM; | ||
| + | config.pin_d6 = Y8_GPIO_NUM; | ||
| + | config.pin_d7 = Y9_GPIO_NUM; | ||
| + | config.pin_xclk = XCLK_GPIO_NUM; | ||
| + | config.pin_pclk = PCLK_GPIO_NUM; | ||
| + | config.pin_vsync = VSYNC_GPIO_NUM; | ||
| + | config.pin_href = HREF_GPIO_NUM; | ||
| + | config.pin_sscb_sda = SIOD_GPIO_NUM; | ||
| + | config.pin_sscb_scl = SIOC_GPIO_NUM; | ||
| + | config.pin_pwdn = PWDN_GPIO_NUM; | ||
| + | config.pin_reset = RESET_GPIO_NUM; | ||
| + | config.xclk_freq_hz = 20000000; | ||
| + | config.pixel_format = PIXFORMAT_JPEG; | ||
| + | | ||
| + | // if PSRAM IC present, init with UXGA resolution and higher JPEG quality | ||
| + | // for larger pre-allocated frame buffer. | ||
| + | if(psramFound()){ | ||
| + | config.frame_size = FRAMESIZE_QVGA; | ||
| + | config.jpeg_quality = 10; | ||
| + | config.fb_count = 2; | ||
| + | } else { | ||
| + | config.frame_size = FRAMESIZE_QVGA; | ||
| + | config.jpeg_quality = 12; | ||
| + | config.fb_count = 1; | ||
| + | } | ||
| + | |||
| + | #if defined(CAMERA_MODEL_ESP_EYE) | ||
| + | pinMode(13, INPUT_PULLUP); | ||
| + | pinMode(14, INPUT_PULLUP); | ||
| + | #endif | ||
| + | |||
| + | // camera init | ||
| + | esp_err_t err = esp_camera_init(& | ||
| + | if (err != ESP_OK) { | ||
| + | Serial.printf(" | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | sensor_t * s = esp_camera_sensor_get(); | ||
| + | // initial sensors are flipped vertically and colors are a bit saturated | ||
| + | if (s-> | ||
| + | s-> | ||
| + | s-> | ||
| + | s-> | ||
| + | } | ||
| + | // drop down frame size for higher initial frame rate | ||
| + | s-> | ||
| + | |||
| + | #if defined(CAMERA_MODEL_M5STACK_WIDE) | ||
| + | s-> | ||
| + | s-> | ||
| + | #endif | ||
| + | |||
| + | WiFi.mode(WIFI_STA); | ||
| + | WiFi.begin(ssid, | ||
| + | | ||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | delay(500); | ||
| + | Serial.print(" | ||
| + | } | ||
| + | Serial.println("" | ||
| + | Serial.println(" | ||
| + | |||
| + | bot.longPoll = 60; | ||
| + | } | ||
| + | |||
| + | |||
| + | bool hasMoreDataAvailable() { | ||
| + | Serial.println(" | ||
| + | if (hasMoreData) { | ||
| + | hasMoreData = false; | ||
| + | return true; | ||
| + | } | ||
| + | |||
| + | return false; | ||
| + | } | ||
| + | |||
| + | |||
| + | byte* getNextBuffer() { | ||
| + | Serial.println(" | ||
| + | if (fb) | ||
| + | return fb->buf; | ||
| + | |||
| + | return nullptr; | ||
| + | } | ||
| + | |||
| + | int getBufferLen() { | ||
| + | Serial.println(" | ||
| + | if (fb) | ||
| + | | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | void sendImage(String chat_id) { | ||
| + | Serial.println(" | ||
| + | fb = NULL; | ||
| + | fb = esp_camera_fb_get(); | ||
| + | hasMoreData = true; | ||
| + | |||
| + | Serial.println(fb-> | ||
| + | | ||
| + | bot.sendPhotoByBinary(chat_id, | ||
| + | | ||
| + | esp_camera_fb_return(fb); | ||
| + | |||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | if (millis() > bot_last_check + bot_check_interval) { | ||
| + | int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
| + | while (numNewMessages) { | ||
| + | for (int i = 0; i < numNewMessages; | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
| + | } | ||
| + | |||
| + | bot_last_check = millis(); | ||
| + | } | ||
| + | | ||
| + | // delay(10); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Le noyau est la sendImagefonction. Tout d' | ||
| + | |||
| + | *hasMoreDataAvailable: | ||
| + | *getNextBuffer: | ||
| + | *getBufferLen: | ||
| + | |||
| + | Comme vous pouvez le remarquer, c'est très simple grâce à la merveilleuse bibliothèque Telegram Arduino. | ||
| + | |||
| + | Si vous souhaitez avoir plus d' | ||
| + | |||
| + | ===Testez le croquis : Envoi de l' | ||
| + | |||
| + | Nous pouvons maintenant tester le croquis Arduino. Nous utiliserons le bot Telegram pour déclencher l' | ||
| + | Envoyer l' | ||
| + | |||
| + | |||
| + | ===Comment améliorer l' | ||
| + | |||
| + | Le code ci-dessus envoie simplement une image à chaque fois que nous envoyons un message à l' | ||
| + | |||
| + | <code c modif_esp32cam_telegram002.ino> | ||
| + | void loop() { | ||
| + | if (millis() > bot_last_check + bot_check_interval) { | ||
| + | int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
| + | while (numNewMessages) { | ||
| + | for (int i = 0; i < numNewMessages; | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | if (msg == "/ | ||
| + | | ||
| + | } | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | // delay(10); | ||
| + | | ||
| + | </ | ||
| + | |||
| + | ===Vérification de l'ID du télégramme=== | ||
| + | |||
| + | La prochaine amélioration consiste à vérifier l'ID du télégramme utilisé pour envoyer le message. De cette façon, nous ne pouvons accepter les messages que de notre client en évitant que d' | ||
| + | |||
| + | Première recherche du Telegram ID Bot (nommé IDBot) : | ||
| + | |||
| + | puis tapez /getid. Vous obtiendrez votre pièce d' | ||
| + | |||
| + | <code c Modif_identite_Esp32_cam_Telegram002.ino> | ||
| + | void loop() { | ||
| + | if (millis() > bot_last_check + bot_check_interval) { | ||
| + | int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
| + | while (numNewMessages) { | ||
| + | for (int i = 0; i < numNewMessages; | ||
| + | String chat_id = bot.messages[i].chat_id; | ||
| + | String msg = bot.messages[i].text; | ||
| + | Serial.println(" | ||
| + | Serial.println(" | ||
| + | if (chat_id != " | ||
| + | bot.sendMessage(chat_id, | ||
| + | continue; | ||
| + | } | ||
| + | if (msg == "/ | ||
| + | sendImage(chat_id); | ||
| + | } | ||
| + | numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
| + | } | ||
| + | bot_last_check = millis(); | ||
| + | } | ||
| + | // delay(10); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/telegram.1635682522.txt.gz · Dernière modification : (modification externe)
