Anxinke ESP32-S3 module drives the camera OV2640 to realize remote photo taking and HTTP transmission to Alibaba Cloud Object Storage OSS, and display it on the WeChat applet. (Deep good article, all open source)


  • This series of blog learning is written by an unofficial staff with half a heart . It is only for personal technical exchange and sharing, not for any commercial use. If there is something wrong, please leave a message and I will change it in time.

Series 1: ESP32 Series Module Basic Learning Series Notes

1. Climbing the pit to learn a new journey, build an esp32 development environment on a virtual machine, and print "Hellow World". 2. Using the eclipes editor skillfully, the official tutorial builds an esp32 development environment under Windows and prints "Hellow World". 3. Know the GPIO interface of the basic esp32, start to light up your first LED and interrupt callback to realize the button function. 4. Experience the powerful timer function of esp32, realize timing 2s to flash an LED light. 5. Contact and practice the pwm width pulse function of esp32 to realize the breathing effect and flash an LED light. 6. The realization of smartConfig and WeChat airKiss in esp32, one-click network configuration and easy and quick connection to the router. 7. Use the GPIO interrupt to make a short press and long press callback event of a button, no longer need to worry about the trigger source. 8. Realize the role of local UDP client and server on esp32, and realize communication in LAN. 9. Realize the role of local TCP client and server on esp32, which can return data by disconnecting and reconnecting the original route. 10. Espressif esp32 SDK programming uses rmt to drive ws2812 colorful lights to achieve rainbow gradient effects. 11. Get started with the development of the Espressif esp-adf audio framework, build a Bluetooth headset with esp32, realize functions such as switching songs and obtaining song information. 12. Open source a WeChat public account airkiss distribution network esp32 and LAN discovery function project, and share an airkiss distribution network gadget. 13. esp32 has a built-in dns server, no need to access the domain name from the external network to return to the specified web page. 14. Esp32 sdk programming implements mandatory portal authentication. After connecting to esp32 hotspot, the specified login interface will pop up automatically.













15. Understand the local offline voice wake-up recognition framework esp-skainet to realize low-cost hardware voice local recognition control. 16. Learning the local voice wake-up offline recognition framework esp-skainet, how to modify the wake-up word? How to customize the command word? How to do intention action? 17. Launched on the whole network, Espressif esp32 sdk is directly connected to JD Weilian·Xiaojingyu·IoT open platform to realize intelligent voice control of Dingdong audio. 18. Get started with the H5 development of the control panel of Jingdong Weilian Xiaojingyu, understand the syntax of Vue, and make your own control page. 19. Heavy open source, how to connect esp32 and blufi with ble on the WeChat applet! 20. A good article, the esp32 firmware compiled during the development process is too large to start normally? Teach you how to customize the partition table partitions.csv. 21. The esp32 bluetooth distribution network blufi is highly packaged, easy to integrate, easy to use, easy to use, and improves development efficiency! 22. Discuss the programmer's "youth rice" and share the realization of multiple encryption algorithms md5 | AES CBC-ECB | Sha1 | Sha256 and so on in esp32! 23. Anxinke esp32-a1s audio development board transplanted the latest esp-adf audio framework, a small test how to realize online text-to-speech playback. 25. Share the package that realizes the smooth adjustment of the color temperature of cold and warm light in the esp32 SDK, and easily integrate it into your project. 26. Share how to use CMake to compile under the window, the compilation speed is improved by a level compared with traditional make compilation, and ESP32 and ESP32-C3 are supported. 27. Install the ESP8266/ESP32 environment with the built-in Linux under the windows10 platform, and there is no need to install an additional virtual machine.










Series 2: ESP32-Camera camera development board series notes

1. Anxinke ESP32-Cam camera development board secondary development C SDK programming, realize MQTT remote photo transmission to the private server. 2. Anxinke ESP32-Cam camera development board secondary development C SDK programming to realize local video stream monitoring. 3. Anxinke ESP32-Cam camera development board secondary development C SDK programming, the pictures taken are transmitted to the host computer PC through the wired serial port.

Series 3: ESP32-C3 Module Series Notes

1. [Bluetooth Mesh notes ①] The ESP32-C3 module realizes Tmall Genie Bluetooth BLE Mesh AliGenie access, and Tmall Genie voice control can also be realized without WiFi connection.

Series 4: ESP32-S3 Module Series Notes

1. Anxinke ESP32-S3 module drives the camera OV2640 to realize remote photo taking and HTTP transmission to Alibaba Cloud Object Storage OSS, and display it on the WeChat applet. .



insert image description here

foreword

     The first batch of samples of the Anxinke ESP32-S3module has been obtained. Today I will share with you the specifications of this module. This module precisely focuses on the AIoT market and responds to the market's technical needs for AI algorithms. Then this article introduces the ESP32-S3driver on the module. Camera OV2640, follow-up will continue to update this series of blog posts.


insert image description here

1. ESP32-S3 Product Features

   I got the ESP32-S3 sample from Anxinke, of course I have to check its specifications.

CPU and storage

Xtensa® 32-bit LX7 dual-core processor, main frequency up to 240 MHz
• 128-bit data bus width, support SIMD instructions
• 384 KB ROM
• 512 KB SRAM
• 16 KB RTC SRAM
• SPI, Dual SPI, Quad SPI, Octal SPI , QPI, OPI interfaces are externally connected to multiple flash and off-chip RAM

Peripheral Interfaces and Sensors

• 45 × GPIO ports • Digital interface:
• 4 × SPI
• 1 × LCD interface (8-bit to 16-bit parallel RGB, I8080, MOTO6800), support conversion between RGB565, YUV422, YUV420, YUV411
• 1 × DVP 8-bit ~16-bit camera interface
• 3 × UART
• 2 × I2C
• 2 × I2S
• 1 × RMT (TX/RX)
• 1 × pulse counter
• LED PWM controller, up to 8 channels
• 1 × full-speed USB OTG
• 1 × USB Serial/JTAG controller
• 2 × MCPWM
• 1 × SDIO host interface with 2 card slots
• DMA controller, 5 receive channels and 5 transmit channels
• 1 × TWAI® controller (ISO11898-1 compliant)
• 2 × 12-bit SAR ADC, up to 20 channels
• 1 × temperature sensor – 14 × capacitive sensing GPIO • Timers:
• 4 × 54-bit general purpose timer
• 1 × 52-bit system timer
• 3 × watch watchdog timer

Power consumption characteristics

   ESP32-S3 adopts advanced power management technology, which can switch between different power consumption modes. The power modes supported by ESP32-S3 are:

Active mode : CPU and chip radio are working. Chips can receive, transmit and listen for signals.
Modem-sleep mode : CPU can run with configurable clock frequency. Wi-Fi baseband and radio are off, but Wi-Fi remains connected.
Light-sleep mode : CPU is suspended. RTC peripherals and ULP coprocessors can be periodically woken up by timers to run. Any wakeup event (MAC, host, RTC timer or external interrupt) will wake up the chip. Wi-Fi stays connected.
Deep-sleep mode : CPU and most peripherals are powered down, only RTC memory and RTC peripherals are in working state. Wi-Fi connection data is stored in the RTC. The ULP coprocessor works.
Hibernation mode : Built-in fast RC oscillator clock and ULP coprocessor are disabled. Only 1 RTC clock timer on low speed clock and some RTC GPIOs are working. RTC clock timer or RTC GPIO can wake up the chip from Hibernation mode. equipment in

Different power consumption modes have different current consumption, please refer to the following for details:

power mode describe typical value unit
Light-sleep The CPU is halted. 240 µA
Deep-sleep RTC memory and RTC peripherals are active 8 µA
Hibernation RTC memory is active, RTC peripherals are off 7 µA
Power off The CHIP_PU pin is pulled low, and the chip is turned off 1 µA

2. Preparation

hardware

  • Anxinke ESP32-S3 module.

  • TTL-USB debugging tool (recommended to use CP2102 serial port chip, to ensure sufficient voltage and current).

software

  • Environment construction: Linux environment to build the master branch
  • Toolchain settings: download toolchain, the version used by the blogger is:gcc version 5.2.0 (crosstool-NG crosstool-ng-1.22.0-97-gc752ad5)
  • Python version:Python 3.8

wiring

camera pin Module pin
pin_pwdn GPIO_NUM_35
pin_reset GPIO_NUM_36
pin_xclk GPIO_NUM_15
pin_sscb_sda GPIO_NUM_4
pin_sscb_scl GPIO_NUM_5
pin_d7 GPIO_NUM_16
pin_d6 GPIO_NUM_17
pin_d5 GPIO_NUM_18
pin_d4 GPIO_NUM_12
pin_d3 GPIO_NUM_11
pin_d2 GPIO_NUM_10
pin_d1 GPIO_NUM_9
pin_d0 GPIO_NUM_8
pin_vsync GPIO_NUM_6
pin_href GPIO_NUM_7
pin_pclk GPIO_NUM_13

3. Communication protocol and principle

insert image description here

3.1 Module photo upload server

Protocol: HTTP

POST /index.php HTTP/1.1
Host: www.domain.com
Content-Type: image/jpeg
Name-Pic: name
Content-Length: 12540


"<file contents here>"

3.2 The applet sends instructions to the module to take pictures and send them to the server

Protocol: MQTT
Topic: /light/deviceIn
payload:

{
    "action" : "0" ,
    "name" : "pic-name"
}

3.3 The module calls back the upload server result to the applet

Protocol: MQTT
Topic: /light/deviceOut
payload:

{
  "url" : "base64(url)" 
}

url is the URL of the picture that can be accessed from the external network after taking the picture, encrypted with base64.


4. Server preparation

3.1 Receive image processing

This code is submitted by HTTP protocol POST, and the image is uploaded to the server in binary form. Its format is as follows:

POST /index.php HTTP/1.1
Host: www.domain.com
Content-Type: image/jpeg
Name-Pic: name
Content-Length: 12540

"<file contents here>"

Therefore, the server should receive data streams, taking the PHPlanguage as an example:

//接受数据流
$stream = file_get_contents('php://input');
//数据流转化为png格式,并保存在指定的位置
$len = file_put_contents('/www/wwwroot/static/' . time() . ".png", $stream); 

3.2 Receive image processing

    public function upload()
    {
    
    
        $getPostDataArry = apache_request_headers();

        try {
    
    
            $name = $getPostDataArry['Name-Pic'];
        } catch (Exception $e) {
    
    
            if (empty($name)) {
    
    
                $response_data['code'] = 1;
                $response_data['des'] = ' Name-Pic is not exist';
                return json($response_data);
            }
        }
        //接受数据流
        $stream = file_get_contents('php://input');
        //数据流转化为png格式,并保存在指定的位置
        $len = file_put_contents('/www/wwwroot/www.xuhongv.com/public/icon/' . $name . ".png", $stream);
        $response_data = [];
        if ($len) {
    
    
            $accessKeyId = "LTAI4Fg*********YJBLPoTo5";
            $accessKeySecret = "OT7s9vkQd*******4p8KQ31qoTIL4";
            $endpoint = "we****ong.oss-cn-hongkong.aliyuncs.com";
            $bucket = 'web****hong';
            try {
    
    
                $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, true);
                //判断存储空间是否存在
                $isExist = $ossClient->doesBucketExist($bucket);
                if (!$isExist) {
    
    
                    $response_data['code'] = 1;
                    $response_data['des'] = $endpoint . ' is not exist';
                    return json($response_data);
                }
                $options = array();
                //oss 存储文件路径
                $object = "images/" . $name . ".png";
                $ossClient->uploadFile($bucket, $object, '/www/wwwroot/www.xuhongv.com/public/icon/' . $name . ".png", $options);
            } catch (OssException $e) {
    
    
                $response_data['code'] = 1;
                $response_data['des'] = $e->getMessage();
                return json($response_data);
            }
            $response_data['code'] = 0;
            $response_data['des'] = 'uploadup ok';
            $response_data['url'] = base64_encode("https://" . $endpoint . '/' . $object);
            return json($response_data);
        }
        $response_data['code'] = 1;
        $response_data['des'] = "error , the upload file length is" . $len;
        return json($response_data);
    }
}

3.3 Server business logic

  1. Receive the pictures sent by the S3 module and store them in a folder on the local server.
  2. At the same time, send this picture to Alibaba Cloud Object Storage, and return an address that can remotely access the picture to the module.

5. Embedded development preparation

Configure server information, then take a photo and upload it.

    //配置服务器相关信息
    esp_http_client_config_t config = {
        .url = "http://domain.xuhongv.com/api/upload",
        .method = HTTP_METHOD_POST,
        .event_handler = _http_event_handler,
        .buffer_size = 4096,
        .user_data = local_response_buffer, 
        .buffer_size_tx = 4096 * 5,
        .timeout_ms = 10000
    };

    //开始拍照
    pic = esp_camera_fb_get();

    if (!pic)
    {
        ESP_LOGE(TAG, "Camera capture failed");
        goto end;
    }
    else
    {
        esp_camera_fb_return(pic);

        pic = esp_camera_fb_get();

        if (!pic)
        {
            ESP_LOGE(TAG, "Camera capture failed");
         }
        else
        {
            //拍照成功,获取其大小、尺寸等信息
            ESP_LOGI(TAG, "Camera capture OK , Its size was: %zu bytes", pic->len);
            ESP_LOGI(TAG, "Camera capture OK , Its width was: %d", pic->width);
            ESP_LOGI(TAG, "Camera capture OK , Its height was: %d ", pic->height);

            esp_http_client_handle_t esp_client = esp_http_client_init(&config);

            //设置HTTP请求头为image/jpg表示图片类型
            esp_http_client_set_header(esp_client, "Content-Type", "image/jpg");

            //设置图片名字
            esp_http_client_set_header(esp_client, "Name-Pic", &(test_task_param->pic_name_p));

            //把图片放在body里面
            esp_http_client_set_post_field(esp_client, (const char *)pic->buf, pic->len);

            //开始执行请求服务器
            res = esp_http_client_perform(esp_client);

            //判断是否请求成功
            if (res == ESP_OK)
            {
                ESP_LOGI(TAG, "HTTPS Status = %d", esp_http_client_get_status_code(esp_client));
            }
            else
            {
                ESP_LOGE(TAG, "perform http request %s", esp_err_to_name(res));
            }
            ESP_ERROR_CHECK(esp_http_client_cleanup(esp_client));
        }
    }

6. Preparation for WeChat Mini Program Development

Configure server information, then take a photo and upload it.

    data: {
    host: 'a0je61b5.mqtt.iot.gz.baidubce.com',
    subTopic: '/light/deviceOut',
    pubTopic: '/light/deviceIn',
    msg: 'Hello! I am from WeChat miniprogram',
    //默认显示的图片
    img_url: 'https://docs.ai-thinker.com/_media/o1cn01faxszt1ls4mym2mkb_2922621297.png',
    mqttOptions: {
      protocolVersion: 4, //MQTT连接协议版本
      clientId: 'DeviceId-jviujtntjy',
      clean: true,
      password: 'sM2hrD6kcRFlmIgR2F',
      username: 'a0je61a/wechat',
      reconnectPeriod: 1000, // 1000毫秒,两次重新连接之间的间隔
      connectTimeout: 30 * 1000, // 1000毫秒,两次重新连接之间的间隔
      resubscribe: true // 如果连接断开并重新连接,则会再次自动订阅已订阅的主题(默认true)
     }
    }
    
    let that = this

    client = mqtt.connect(`wxs://${this.data.host}/mqtt`, this.data.mqttOptions)

    client.on('reconnect', (error) => {
      console.log('Reconnecting...')
    })

    client.on('error', (error) => {
      console.log('连接失败:', error)
    })

    client.on('connect', () => {
      wx.showToast({
        title: '连接成功'
      })

      client.subscribe(this.data.subTopic, (err) => {
      })
      client.on('message', (topic, payload) => {
        let object = JSON.parse(payload)
        //base64解码url地址
        let url = that.base64_decode(object.url)
        console.log(url)
        that.setData({
          img_url: url
        })
        wx.showModal({
          content: `收到 Topic: ${topic}, Payload:  ${url}`,
          showCancel: false,
        });
      })
    })

Source code download

Module code: https://github.com/xuhongv/StudyInEsp32/tree/master/24_esp32s2_s3_camera_wechat_mini

WeChat applet code: https://github.com/xuhongv/RemoteWeChatForESP

Server code: See the server code introduction section of this article.

In addition, don't take my blog as a learning standard, mine are just notes, and it's hard to be negligent. If there are any, please point them out, and welcome to leave a message!

  • Play esp8266with you, QQjoin the group, friends who don’t like it, don’t spray or add: 434878850
  • Personal E-mail: [email protected] 24 hours online, all emails will be replied!
  • esp8266 source code learning summary (continuously updated, welcome to star): https://github.com/xuhongv/StudyInEsp8266
  • esp32 source code learning summary (continuously updated, welcome to star): https://github.com/xuhongv/StudyInEsp32
  • Pay attention to the QR code of the WeChat public account below, there are a lot of dry goods, and we will push them as soon as possible!

insert image description here

Guess you like

Origin blog.csdn.net/xh870189248/article/details/120481155