├── examples ├── SD │ ├── test.jpg │ └── SD.ino ├── Ethernet │ ├── ESP32 │ │ ├── modified_LAN8720_board_images │ │ │ ├── lan8720_modified_board.png │ │ │ └── lan8720_modified_schematic.png │ │ └── ESP32.ino │ └── ESP8266 │ │ └── ESP8266.ino ├── Camera │ ├── cam │ │ ├── ov7725.h │ │ ├── ov264_drive.h │ │ ├── sccb.h │ │ ├── OV2640.h │ │ ├── twi.h │ │ ├── camera_common.h │ │ ├── sccb.c │ │ ├── OV2640.cpp │ │ ├── sensor.h │ │ ├── camera.h │ │ ├── ov2640_regs.h │ │ ├── twi.c │ │ └── ov7725.c │ └── Camera.ino ├── Google_Map │ └── Google_Map.ino ├── ExternalClient │ └── ExternalClient.ino └── Basic │ └── Basic.ino ├── media └── images │ ├── ESP8266_VM.png │ └── ESP32-PSRAM.png ├── library.properties ├── .github ├── FUNDING.yml └── stale.yml ├── library.json ├── src ├── mbfs │ ├── MB_MCU.h │ └── MB_FS_Interfaces.h ├── wcs │ ├── ESP_Line_Notify_Clients.h │ ├── esp8266 │ │ ├── ESP_Line_Notify_TCP_Client.h │ │ └── ESP_Line_Notify_TCP_Client.cpp │ ├── esp32 │ │ ├── ESP_Line_Notify_TCP_Client.h │ │ └── ESP_Line_Notify_TCP_Client.cpp │ ├── custom │ │ └── ESP_Line_Notify_Custom_TCP_Client.h │ └── base │ │ └── ESP_Line_Notify_TCP_Client_Base.h ├── FS_Config.h ├── SDHelper.h ├── ESP_Line_Notify_Net.h ├── ESP_Line_Notify_Error.h ├── ESP_Line_Notify.h ├── json │ ├── extras │ │ └── print │ │ │ └── fb_json_print.h │ ├── MB_List.h │ └── MB_JSON │ │ └── MB_JSON.h └── ESP_Line_Notify_Const.h ├── keywords.txt ├── LICENSE └── README.md /examples/SD/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobizt/ESP-Line-Notify/main/examples/SD/test.jpg -------------------------------------------------------------------------------- /media/images/ESP8266_VM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobizt/ESP-Line-Notify/main/media/images/ESP8266_VM.png -------------------------------------------------------------------------------- /media/images/ESP32-PSRAM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobizt/ESP-Line-Notify/main/media/images/ESP32-PSRAM.png -------------------------------------------------------------------------------- /examples/Ethernet/ESP32/modified_LAN8720_board_images/lan8720_modified_board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobizt/ESP-Line-Notify/main/examples/Ethernet/ESP32/modified_LAN8720_board_images/lan8720_modified_board.png -------------------------------------------------------------------------------- /examples/Ethernet/ESP32/modified_LAN8720_board_images/lan8720_modified_schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobizt/ESP-Line-Notify/main/examples/Ethernet/ESP32/modified_LAN8720_board_images/lan8720_modified_schematic.png -------------------------------------------------------------------------------- /examples/Camera/cam/ov7725.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * OV7725 driver. 7 | * 8 | */ 9 | #ifndef __OV7725_H__ 10 | #define __OV7725_H__ 11 | #include "sensor.h" 12 | 13 | int ov7725_init(sensor_t *sensor); 14 | #endif // __OV7725_H__ 15 | -------------------------------------------------------------------------------- /examples/Camera/cam/ov264_drive.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * OV2640 driver. 7 | * 8 | */ 9 | #ifndef __OV2640_DRIVE_H__ 10 | #define __OV2640_DRIVE_H__ 11 | #include "sensor.h" 12 | int ov2640_init(sensor_t *sensor); 13 | #endif // __OV2640_DRIVE_H__ 14 | -------------------------------------------------------------------------------- /examples/Camera/cam/sccb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * SCCB (I2C like) driver. 7 | * 8 | */ 9 | #ifndef __SCCB_H__ 10 | #define __SCCB_H__ 11 | #include 12 | int SCCB_Init(int pin_sda, int pin_scl); 13 | uint8_t SCCB_Probe(); 14 | uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg); 15 | uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data); 16 | #endif // __SCCB_H__ 17 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ESP Line Notify 2 | 3 | version=2.1.1 4 | 5 | author=Mobizt 6 | 7 | maintainer=Mobizt 8 | 9 | sentence=Line Notify Library for ESP8266 and ESP32. 10 | 11 | paragraph=Send the Line notification message, sticker, map and images. The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient. 12 | 13 | category=Communication 14 | 15 | url=https://github.com/mobizt/ESP-Line-Notify 16 | 17 | architectures=esp8266,esp32,sam,samd,stm32,STM32F1,STM32F4,teensy,avr,megaavr,mbed_nano,mbed_rp2040 18 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: 13 | - https://www.paypal.me/mobizt 14 | - https://www.buymeacoffee.com/Mobizt -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ESP Line Notify", 3 | "version": "2.1.1", 4 | "keywords": "communication, REST, esp32, esp8266, arduino", 5 | "description": "Line Notify Library for ESP8266 and ESP32. Send the Line notification message, sticker, map and images. The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/mobizt/ESP-Line-Notify.git" 9 | }, 10 | "authors": [{ 11 | "name": "Mobizt", 12 | "email": "k_suwatchai@hotmail.com" 13 | }], 14 | "frameworks": "arduino", 15 | "platforms": "espressif32, espressif8266, atmelsam, raspberrypi, atmelavr, atmelmegaavr, ststm32, teensy" 16 | } 17 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 20 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 5 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: wontfix 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when closing a stale issue. Set to `false` to disable 17 | closeComment: false 18 | -------------------------------------------------------------------------------- /examples/Camera/cam/OV2640.h: -------------------------------------------------------------------------------- 1 | #ifndef OV2640_H_ 2 | #define OV2640_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "esp_log.h" 8 | #include "esp_attr.h" 9 | #include "camera.h" 10 | 11 | class OV2640 12 | { 13 | public: 14 | OV2640(){}; 15 | ~OV2640(){}; 16 | esp_err_t init(camera_config_t config); 17 | void run(void); 18 | size_t getSize(void); 19 | uint8_t *getfb(void); 20 | int getWidth(void); 21 | int getHeight(void); 22 | camera_framesize_t getFrameSize(void); 23 | camera_pixelformat_t getPixelFormat(void); 24 | 25 | void setFrameSize(camera_framesize_t size); 26 | void setPixelFormat(camera_pixelformat_t format); 27 | void setVflip(bool enable); 28 | 29 | private: 30 | // camera_framesize_t _frame_size; 31 | // camera_pixelformat_t _pixel_format; 32 | camera_config_t _cam_config; 33 | }; 34 | 35 | #endif //OV2640_H_ -------------------------------------------------------------------------------- /src/mbfs/MB_MCU.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef MB_MCU_H 4 | #define MB_MCU_H 5 | 6 | 7 | #if defined(ESP8266) || defined(ESP32) 8 | #ifndef MB_ARDUINO_ESP 9 | #define MB_ARDUINO_ESP 10 | #endif 11 | #endif 12 | 13 | #if defined(__arm__) 14 | #ifndef MB_ARDUINO_ARM 15 | #define MB_ARDUINO_ARM 16 | #endif 17 | #endif 18 | 19 | #if defined(ARDUINO_ARCH_SAMD) 20 | #ifndef MB_ARDUINO_ARCH_SAMD 21 | #define MB_ARDUINO_ARCH_SAMD 22 | #endif 23 | #endif 24 | 25 | #if defined(ARDUINO_ARCH_RP2040) 26 | 27 | #if defined(ARDUINO_NANO_RP2040_CONNECT) 28 | #ifndef MB_ARDUINO_NANO_RP2040_CONNECT 29 | #define MB_ARDUINO_NANO_RP2040_CONNECT 30 | #endif 31 | #else 32 | #ifndef MB_ARDUINO_PICO 33 | #define MB_ARDUINO_PICO 34 | #endif 35 | #endif 36 | 37 | #endif 38 | 39 | 40 | #if defined(TEENSYDUINO) 41 | #ifndef MB_ARDUINO_TEENSY 42 | #define MB_ARDUINO_TEENSY 43 | #endif 44 | #endif 45 | 46 | 47 | #endif -------------------------------------------------------------------------------- /src/wcs/ESP_Line_Notify_Clients.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP_Line_Notify_ClientS_H 2 | #define ESP_Line_Notify_ClientS_H 3 | 4 | #include "./mbfs/MB_FS.h" 5 | #include "ESP_Line_Notify_Net.h" 6 | 7 | 8 | #if defined(ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT) 9 | #include "./wcs/custom/ESP_Line_Notify_Custom_TCP_Client.h" 10 | #define ESP_LINE_NOTIFY_TCP_CLIENT ESP_Line_Notify_Custom_TCP_Client 11 | #elif defined(ESP32) 12 | #include 13 | #include "./wcs/esp32/ESP_Line_Notify_TCP_Client.h" 14 | #define ESP_LINE_NOTIFY_TCP_CLIENT ESP_Line_Notify_TCP_Client 15 | #elif defined(ESP8266) 16 | #include 17 | #include 18 | #include 19 | #include "./wcs/esp8266/ESP_Line_Notify_TCP_Client.h" 20 | #define ESP_LINE_NOTIFY_TCP_CLIENT ESP_Line_Notify_TCP_Client 21 | #define FS_NO_GLOBALS 22 | #else 23 | #include "./wcs/custom/ESP_Line_Notify_Custom_TCP_Client.h" 24 | #define ESP_LINE_NOTIFY_TCP_CLIENT ESP_Line_Notify_Custom_TCP_Client 25 | #endif 26 | 27 | #endif -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ###################################### 2 | # Syntax Coloring Map ESP Line Notify 3 | ###################################### 4 | 5 | ####################################### 6 | # Classes and Structured Type (KEYWORD1) 7 | ####################################### 8 | 9 | LineNotify KEYWORD1 10 | LineNotiFyClient KEYWORD1 11 | 12 | ############################################### 13 | # Methods and Functions (KEYWORD2) 14 | ############################################### 15 | 16 | send KEYWORD2 17 | sdBegin KEYWORD2 18 | 19 | ####################################### 20 | # Struct (KEYWORD3) 21 | ####################################### 22 | 23 | LineNotifySendingResult KEYWORD3 24 | LineNotify_Sending_None KEYWORD3 25 | LineNotify_Sending_Begin KEYWORD3 26 | LineNotify_Sending_In_Progress KEYWORD3 27 | LineNotify_Sending_Upload KEYWORD3 28 | LineNotify_Sending_Error KEYWORD3 29 | LineNotify_Sending_Success KEYWORD3 30 | LineNotify_Storage_Type_Flash KEYWORD3 31 | LineNotify_Storage_Type_SD KEYWORD3 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 mobizt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/Camera/cam/twi.h: -------------------------------------------------------------------------------- 1 | /* 2 | twi.h - Software I2C library for ESP31B 3 | 4 | Copyright (c) 2015 Hristo Gochkov. All rights reserved. 5 | This file is part of the ESP31B core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #ifndef SI2C_h 22 | #define SI2C_h 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #define systick_sleep(t) delay(t) 29 | #define __disable_irq() 30 | #define __enable_irq() 31 | 32 | void twi_init(unsigned char sda, unsigned char scl); 33 | void twi_stop(void); 34 | void twi_setClock(unsigned int freq); 35 | uint8_t twi_writeTo(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop); 36 | uint8_t twi_readFrom(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif -------------------------------------------------------------------------------- /src/FS_Config.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * To use other flash file systems 4 | * 5 | * LittleFS File system 6 | * 7 | * #include 8 | * #define DEFAULT_FLASH_FS LittleFS //For LitteFS 9 | * 10 | * 11 | * FFat File system 12 | * 13 | * #include 14 | * #define DEFAULT_FLASH_FS FFat //For ESP32 FFat 15 | * 16 | */ 17 | #if defined(ESP32) 18 | #include 19 | #endif 20 | #if defined(ESP32) || defined(ESP8266) 21 | #define DEFAULT_FLASH_FS SPIFFS 22 | #endif 23 | 24 | /** 25 | * To use SD card file systems with different hardware interface 26 | * e.g. SDMMC hardware bus on the ESP32 27 | * https://github.com/espressif/arduino-esp32/tree/master/libraries/SD#faq 28 | * 29 | #include 30 | #define DEFAULT_SD_FS SD_MMC //For ESP32 SDMMC 31 | #define CARD_TYPE_SD_MMC 1 //For ESP32 SDMMC 32 | 33 | * 34 | */ 35 | 36 | /** 37 | * To use SdFat on ESP32 38 | 39 | #if defined(ESP32) 40 | #include //https://github.com/greiman/SdFat 41 | static SdFat sd_fat_fs; //should declare as static here 42 | #define DEFAULT_SD_FS sd_fat_fs 43 | #define CARD_TYPE_SD 1 44 | #define SD_FS_FILE SdFile 45 | #endif 46 | 47 | * The SdFat (https://github.com/greiman/SdFat) is already implemented as wrapper class in ESP8266 core library. 48 | * Do not include SdFat.h library in ESP8266 target code which it conflicts with the wrapper one. 49 | 50 | */ 51 | #if defined(ESP32) || defined(ESP8266) 52 | #include 53 | #define DEFAULT_SD_FS SD 54 | #define CARD_TYPE_SD 1 55 | #endif 56 | 57 | //For ESP32, format SPIFFS or FFat if mounting failed 58 | #define FORMAT_FLASH_IF_MOUNT_FAILED 1 59 | 60 | #if defined(ESP32) || defined(ESP8266) 61 | #define ESP_LINE_NOTIFY_USE_PSRAM 62 | #endif 63 | 64 | // To enable external Client for ESP8266 and ESP32. 65 | // This will enable automatically for other devices. 66 | //#define ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT -------------------------------------------------------------------------------- /examples/Camera/cam/camera_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "rom/lldesc.h" 7 | #include "esp_err.h" 8 | #include "esp_intr_alloc.h" 9 | #include "freertos/FreeRTOS.h" 10 | #include "freertos/semphr.h" 11 | #include "freertos/task.h" 12 | #include "camera.h" 13 | #include "sensor.h" 14 | 15 | typedef union { 16 | struct { 17 | uint8_t sample2; 18 | uint8_t unused2; 19 | uint8_t sample1; 20 | uint8_t unused1; 21 | }; 22 | uint32_t val; 23 | } dma_elem_t; 24 | 25 | typedef enum { 26 | /* camera sends byte sequence: s1, s2, s3, s4, ... 27 | * fifo receives: 00 s1 00 s2, 00 s2 00 s3, 00 s3 00 s4, ... 28 | */ 29 | SM_0A0B_0B0C = 0, 30 | /* camera sends byte sequence: s1, s2, s3, s4, ... 31 | * fifo receives: 00 s1 00 s2, 00 s3 00 s4, ... 32 | */ 33 | SM_0A0B_0C0D = 1, 34 | /* camera sends byte sequence: s1, s2, s3, s4, ... 35 | * fifo receives: 00 s1 00 00, 00 s2 00 00, 00 s3 00 00, ... 36 | */ 37 | SM_0A00_0B00 = 3, 38 | } i2s_sampling_mode_t; 39 | 40 | typedef void (*dma_filter_t)(const dma_elem_t* src, lldesc_t* dma_desc, uint8_t* dst); 41 | 42 | typedef struct { 43 | camera_config_t config; 44 | sensor_t sensor; 45 | uint8_t *fb; 46 | size_t fb_size; 47 | size_t data_size; 48 | size_t width; 49 | size_t height; 50 | size_t in_bytes_per_pixel; 51 | size_t fb_bytes_per_pixel; 52 | size_t stride; 53 | size_t frame_count; 54 | 55 | lldesc_t *dma_desc; 56 | dma_elem_t **dma_buf; 57 | bool dma_done; 58 | size_t dma_desc_count; 59 | size_t dma_desc_cur; 60 | size_t dma_received_count; 61 | size_t dma_filtered_count; 62 | size_t dma_per_line; 63 | size_t dma_buf_width; 64 | size_t dma_sample_count; 65 | i2s_sampling_mode_t sampling_mode; 66 | dma_filter_t dma_filter; 67 | intr_handle_t i2s_intr_handle; 68 | QueueHandle_t data_ready; 69 | SemaphoreHandle_t frame_ready; 70 | TaskHandle_t dma_filter_task; 71 | } camera_state_t; 72 | 73 | -------------------------------------------------------------------------------- /examples/Camera/cam/sccb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * SCCB (I2C like) driver. 7 | * 8 | */ 9 | #include 10 | #include "sccb.h" 11 | #include "twi.h" 12 | #include 13 | 14 | #define SCCB_FREQ (100000) // We don't need fast I2C. 100KHz is fine here. 15 | #define TIMEOUT (1000) /* Can't be sure when I2C routines return. Interrupts 16 | while polling hardware may result in unknown delays. */ 17 | 18 | 19 | int SCCB_Init(int pin_sda, int pin_scl) 20 | { 21 | twi_init(pin_sda, pin_scl); 22 | return 0; 23 | } 24 | 25 | uint8_t SCCB_Probe() 26 | { 27 | 28 | uint8_t reg = 0x00; 29 | uint8_t slv_addr = 0x00; 30 | 31 | for (uint8_t i=0; i<127; i++) { 32 | if (twi_writeTo(i, ®, 1, true) == 0) { 33 | slv_addr = i; 34 | break; 35 | } 36 | 37 | if (i!=126) { 38 | systick_sleep(1); // Necessary for OV7725 camera (not for OV2640). 39 | } 40 | } 41 | return slv_addr; 42 | } 43 | 44 | uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg) 45 | { 46 | uint8_t data=0; 47 | 48 | __disable_irq(); 49 | int rc = twi_writeTo(slv_addr, ®, 1, true); 50 | if (rc != 0) { 51 | data = 0xff; 52 | } 53 | else { 54 | rc = twi_readFrom(slv_addr, &data, 1, true); 55 | if (rc != 0) { 56 | data=0xFF; 57 | } 58 | } 59 | __enable_irq(); 60 | if (rc != 0) { 61 | printf("SCCB_Read [%02x] failed rc=%d\n", reg, rc); 62 | } 63 | return data; 64 | } 65 | 66 | uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data) 67 | { 68 | uint8_t ret=0; 69 | uint8_t buf[] = {reg, data}; 70 | 71 | __disable_irq(); 72 | if(twi_writeTo(slv_addr, buf, 2, true) != 0) { 73 | ret=0xFF; 74 | } 75 | __enable_irq(); 76 | if (ret != 0) { 77 | printf("SCCB_Write [%02x]=%02x failed\n", reg, data); 78 | } 79 | return ret; 80 | } 81 | -------------------------------------------------------------------------------- /src/mbfs/MB_FS_Interfaces.h: -------------------------------------------------------------------------------- 1 | 2 | /* Convert specific definitions to MB_FS definitions */ 3 | #ifndef MB_FS_INTERFACES_H 4 | #define MB_FS_INTERFACES_H 5 | 6 | #include 7 | 8 | #pragma GCC diagnostic push 9 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 10 | 11 | // include definitions file 12 | #include "./FS_Config.h" 13 | 14 | // 15 | #if defined(DEFAULT_FLASH_FS) 16 | #define MBFS_FLASH_FS DEFAULT_FLASH_FS 17 | #endif 18 | 19 | // 20 | #if defined(DEFAULT_SD_FS) 21 | #define MBFS_SD_FS DEFAULT_SD_FS 22 | #endif 23 | 24 | // 25 | #if defined(CARD_TYPE_SD) 26 | #define MBFS_CARD_TYPE_SD /* */ CARD_TYPE_SD 27 | #endif 28 | 29 | // 30 | #if defined(CARD_TYPE_SD_MMC) 31 | #define MBFS_CARD_TYPE_SD_MMC /* */ CARD_TYPE_SD_MMC 32 | #endif 33 | 34 | // 35 | #if defined(FORMAT_FLASH_IF_MOUNT_FAILED) 36 | #define MBFS_FORMAT_FLASH /* */ FORMAT_FLASH_IF_MOUNT_FAILED 37 | #endif 38 | 39 | #if defined(MBFS_SD_FS) || defined(MBFS_FLASH_FS) 40 | #define MBFS_USE_FILE_STORAGE 41 | #endif 42 | 43 | #if defined(ESP32) && defined(SD_FAT_VERSION) && defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) 44 | 45 | #ifndef MBFS_ESP32_SDFAT_ENABLED 46 | #define MBFS_ESP32_SDFAT_ENABLED 47 | #endif 48 | 49 | #ifndef USE_SD_FAT_ESP32 50 | #define USE_SD_FAT_ESP32 51 | #endif 52 | 53 | #endif 54 | 55 | #if !defined(ESP32) && !defined(ESP8266) && defined(SD_FAT_VERSION) && defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) 56 | #ifndef MBFS_SDFAT_ENABLED 57 | #define MBFS_SDFAT_ENABLED 58 | #endif 59 | #endif 60 | 61 | // For MB_String 62 | #if defined(ESP_LINE_NOTIFY_USE_PSRAM) 63 | #define MB_STRING_USE_PSRAM 64 | #endif 65 | 66 | // 67 | #if defined(MBFS_SD_FS) 68 | 69 | #if !defined(SD_FS_FILE) 70 | 71 | #if defined(MBFS_ESP32_SDFAT_ENABLED) 72 | #define MBFS_SD_FILE SdFile 73 | #else 74 | #define MBFS_SD_FILE fs::File 75 | #endif 76 | 77 | #else 78 | 79 | #define MBFS_SD_FILE SD_FS_FILE 80 | 81 | #endif 82 | 83 | #endif 84 | 85 | #ifndef MB_STRING_INCLUDE_CLASS 86 | #define MB_STRING_INCLUDE_CLASS "json/FirebaseJson.h" 87 | #endif 88 | 89 | #include MB_STRING_INCLUDE_CLASS 90 | 91 | #endif /* MB_FS_INTERFACES_H */ 92 | -------------------------------------------------------------------------------- /src/SDHelper.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SD_HELPER_H_ 3 | #define SD_HELPER_H_ 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "ESP_Line_Notify.h" 9 | 10 | // If SD Card used for storage, assign SD card type and FS used in src/FirebaseFS.h and 11 | // change the config for that card interfaces in this file (src/addons/SDHelper.h) 12 | 13 | #if defined(DEFAULT_SD_FS) && defined(CARD_TYPE_SD) 14 | 15 | #if defined(ESP32) 16 | #define SPI_CS_PIN 13 17 | #define SPI_SCK_PIN 14 18 | #define SPI_MISO_PIN 2 19 | #define SPI_MOSI_PIN 15 20 | #define SPI_CLOCK_IN_MHz 16 21 | #elif defined(ESP8266) 22 | #define SPI_CS_PIN 15 23 | #endif 24 | 25 | // if SdFat library installed and FirebaseFS.h was set to use it (for ESP32 only) 26 | #if defined(USE_SD_FAT_ESP32) 27 | 28 | // https://github.com/greiman/SdFat 29 | SdSpiConfig sdFatSPIConfig(SPI_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(SPI_CLOCK_IN_MHz)); 30 | 31 | #elif defined(ESP32) // if ESP32 and no SdFat library installed 32 | 33 | SPIClass spi; 34 | 35 | #elif defined(ESP8266) 36 | 37 | // SDFSConfig sdFSConfig(SPI_CS_PIN, SPI_HALF_SPEED); 38 | 39 | #endif 40 | 41 | #endif 42 | 43 | bool SD_Card_Mounting() 44 | { 45 | 46 | #if defined(DEFAULT_SD_FS) && defined(CARD_TYPE_SD) 47 | 48 | Serial.print("\nMounting SD Card... "); 49 | 50 | #if defined(USE_SD_FAT_ESP32) 51 | 52 | if (!LineNotify.sdBegin(&sdFatSPIConfig, SPI_CS_PIN, SPI_SCK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN)) // pointer to SdSpiConfig, SS, SCK,MISO, MOSI 53 | 54 | #elif defined(ESP32) // if ESP32 and no SdFat library installed 55 | 56 | spi.begin(SPI_SCK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN, SPI_CS_PIN); // SPI pins config -> SCK,MISO, MOSI, SS 57 | if (!LineNotify.sdBegin(SPI_CS_PIN, &spi)) // SS, pointer to SPIClass <- SPIClass object should defined as static or global 58 | 59 | #elif defined(ESP8266) 60 | 61 | if (!LineNotify.sdBegin(SPI_CS_PIN)) // or Firebase.sdBegin(&sdFSConfig) 62 | 63 | #endif 64 | { 65 | Serial.println("failed\n"); 66 | return false; 67 | } 68 | else 69 | { 70 | Serial.println("success\n"); 71 | return true; 72 | } 73 | #endif 74 | 75 | #if defined(DEFAULT_SD_FS) && defined(CARD_TYPE_SD_MMC) 76 | 77 | Serial.print("\nMounting SD_MMC Card... "); 78 | 79 | if (!LineNotify.sdMMCBegin("/sdcard", false, true)) 80 | { 81 | Serial.println("failed\n"); 82 | return false; 83 | } 84 | else 85 | { 86 | Serial.println("success\n"); 87 | return true; 88 | } 89 | #endif 90 | 91 | return false; 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /src/ESP_Line_Notify_Net.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Created May 5, 2022 3 | */ 4 | 5 | #ifndef ESP_Line_Notify_Net_H 6 | #define ESP_Line_Notify_Net_H 7 | 8 | #pragma once 9 | 10 | #include "FS_Config.h" 11 | 12 | #if !defined(ESP32) && !defined(ESP8266) 13 | #ifndef ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT 14 | #define ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT 15 | #endif 16 | #endif 17 | 18 | #if defined(ESP32) 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #if __has_include() 25 | #include 26 | #endif 27 | static const char esp_idf_branch_str[] PROGMEM = "release/v"; 28 | #endif 29 | 30 | 31 | 32 | #if defined(ESP8266) 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #define ESP_LINE_NOTIFY_SSL_CLIENT BearSSL::WiFiClientSecure 40 | 41 | //__GNUC__ 42 | //__GNUC_MINOR__ 43 | //__GNUC_PATCHLEVEL__ 44 | 45 | #ifdef __GNUC__ 46 | #if __GNUC__ > 4 || __GNUC__ == 10 47 | #include 48 | #define ESP8266_CORE_SDK_V3_X_X 49 | #endif 50 | #endif 51 | 52 | #ifndef ARDUINO_ESP8266_GIT_VER 53 | #error Your ESP8266 Arduino Core SDK is outdated, please update. From Arduino IDE go to Boards Manager and search 'esp8266' then select the latest version. 54 | #endif 55 | 56 | //2.6.1 BearSSL bug 57 | #if ARDUINO_ESP8266_GIT_VER == 0x482516e3 58 | #error Due to bugs in BearSSL in ESP8266 Arduino Core SDK version 2.6.1, please update ESP8266 Arduino Core SDK to newer version. The issue was found here https:\/\/github.com/esp8266/Arduino/issues/6811. 59 | #endif 60 | 61 | 62 | #if defined __has_include 63 | 64 | #if __has_include() 65 | #include 66 | #endif 67 | 68 | #if __has_include() 69 | #define INC_ENC28J60_LWIP 70 | #include 71 | #endif 72 | 73 | #if __has_include() 74 | #define INC_W5100_LWIP 75 | #include 76 | #endif 77 | 78 | #if __has_include() 79 | #define INC_W5500_LWIP 80 | #include 81 | #endif 82 | 83 | #endif 84 | 85 | 86 | #endif 87 | 88 | typedef struct esp_line_notify_spi_ethernet_module_t 89 | { 90 | #if defined(ESP8266) && defined(ESP8266_CORE_SDK_V3_X_X) 91 | #ifdef INC_ENC28J60_LWIP 92 | ENC28J60lwIP *enc28j60; 93 | #endif 94 | #ifdef INC_W5100_LWIP 95 | Wiznet5100lwIP *w5100; 96 | #endif 97 | #ifdef INC_W5500_LWIP 98 | Wiznet5500lwIP *w5500; 99 | #endif 100 | #endif 101 | } SPI_ETH_Module; 102 | 103 | #endif -------------------------------------------------------------------------------- /examples/Camera/cam/OV2640.cpp: -------------------------------------------------------------------------------- 1 | #include "OV2640.h" 2 | 3 | #define TAG "OV2640" 4 | 5 | void OV2640::run(void) 6 | { 7 | camera_run(); 8 | } 9 | 10 | int OV2640::getWidth(void) 11 | { 12 | return camera_get_fb_width(); 13 | } 14 | 15 | int OV2640::getHeight(void) 16 | { 17 | return camera_get_fb_height(); 18 | } 19 | 20 | size_t OV2640::getSize(void) 21 | { 22 | return camera_get_data_size(); 23 | } 24 | 25 | uint8_t *OV2640::getfb(void) 26 | { 27 | return camera_get_fb(); 28 | } 29 | 30 | camera_framesize_t OV2640::getFrameSize(void) 31 | { 32 | return _cam_config.frame_size; 33 | } 34 | 35 | void OV2640::setFrameSize(camera_framesize_t size) 36 | { 37 | switch (size) 38 | { 39 | case CAMERA_FS_QQVGA: 40 | case CAMERA_FS_QVGA: 41 | case CAMERA_FS_VGA: 42 | case CAMERA_FS_SVGA: 43 | _cam_config.frame_size = size; 44 | break; 45 | default: 46 | _cam_config.frame_size = CAMERA_FS_SVGA; 47 | break; 48 | } 49 | } 50 | 51 | camera_pixelformat_t OV2640::getPixelFormat(void) 52 | { 53 | return _cam_config.pixel_format; 54 | } 55 | 56 | void OV2640::setPixelFormat(camera_pixelformat_t format) 57 | { 58 | switch (format) 59 | { 60 | case CAMERA_PF_RGB565: 61 | case CAMERA_PF_YUV422: 62 | case CAMERA_PF_GRAYSCALE: 63 | case CAMERA_PF_JPEG: 64 | _cam_config.pixel_format = format; 65 | break; 66 | default: 67 | _cam_config.pixel_format = CAMERA_PF_GRAYSCALE; 68 | break; 69 | } 70 | } 71 | 72 | void OV2640::setVflip(bool enable) 73 | { 74 | camera_set_vflip(enable); 75 | } 76 | 77 | 78 | esp_err_t OV2640::init(camera_config_t config) 79 | { 80 | camera_model_t camera_model; 81 | memset(&_cam_config, 0, sizeof(_cam_config)); 82 | memcpy(&_cam_config, &config, sizeof(config)); 83 | 84 | esp_err_t err = camera_probe(&_cam_config, &camera_model); 85 | if (err != ESP_OK) 86 | { 87 | ESP_LOGD(TAG, "Camera probe failed with error 0x%x", err); 88 | return err; 89 | } 90 | if (camera_model == CAMERA_OV7725) 91 | { 92 | ESP_LOGD(TAG, "Detected OV7725 camera"); 93 | } 94 | else if (camera_model == CAMERA_OV2640) 95 | { 96 | ESP_LOGD(TAG,"Detected OV2640 camera"); 97 | _cam_config.jpeg_quality = 15; 98 | } 99 | else 100 | { 101 | ESP_LOGD(TAG,"Camera not supported"); 102 | return ESP_ERR_CAMERA_NOT_SUPPORTED; 103 | } 104 | ESP_ERROR_CHECK(gpio_install_isr_service(0)); 105 | 106 | err = camera_init(&_cam_config); 107 | if (err != ESP_OK) 108 | { 109 | ESP_LOGE(TAG, "Camera init failed with error 0x%x", err); 110 | return err; 111 | } 112 | 113 | return ESP_OK; 114 | } 115 | -------------------------------------------------------------------------------- /src/wcs/esp8266/ESP_Line_Notify_TCP_Client.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ESP Line Notify TCP Client v1.0.0 3 | * 4 | * Created May 6, 2022 5 | * 6 | * The MIT License (MIT) 7 | * Copyright (c) 2022 K. Suwatchai (Mobizt) 8 | * 9 | * 10 | * Permission is hereby granted, free of charge, to any person returning a copy of 11 | * this software and associated documentation files (the "Software"), to deal in 12 | * the Software without restriction, including without limitation the rights to 13 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 14 | * the Software, and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in all 18 | * copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 22 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 23 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 24 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef ESP_Line_Notify_TCP_Client_H 29 | #define ESP_Line_Notify_TCP_Client_H 30 | 31 | #if defined(ESP8266) && !defined(ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT) 32 | 33 | #include 34 | #include 35 | #include "ESP_Line_Notify_Net.h" 36 | #include "ESP_Line_Notify_Error.h" 37 | #include "mbfs/MB_FS.h" 38 | #include "./wcs/base/ESP_Line_Notify_TCP_Client_Base.h" 39 | 40 | class ESP_Line_Notify_TCP_Client : public ESP_Line_Notify_TCP_Client_Base 41 | { 42 | 43 | public: 44 | ESP_Line_Notify_TCP_Client(); 45 | ~ESP_Line_Notify_TCP_Client(); 46 | 47 | void setCACert(const char *caCert); 48 | 49 | bool setCertFile(const char *certFile, mb_fs_mem_storage_type storageType); 50 | 51 | void setBufferSizes(int recv, int xmit); 52 | 53 | bool networkReady(); 54 | 55 | void networkReconnect(); 56 | 57 | void networkDisconnect(); 58 | 59 | esp_line_notify_tcp_client_type type(); 60 | 61 | bool isInitialized(); 62 | 63 | int hostByName(const char *name, IPAddress &ip); 64 | 65 | void setTimeout(uint32_t timeoutmSec); 66 | 67 | bool begin(const char *host, uint16_t port, int *response_code); 68 | 69 | int beginUpdate(int len, bool verify = true); 70 | 71 | bool ethLinkUp(); 72 | 73 | void ethDNSWorkAround(); 74 | 75 | private: 76 | std::unique_ptr wcs = std::unique_ptr(new ESP_LINE_NOTIFY_SSL_CLIENT()); 77 | uint16_t bsslRxSize = 2048; 78 | uint16_t bsslTxSize = 512; 79 | X509List *x509 = nullptr; 80 | void release(); 81 | }; 82 | 83 | #endif /* ESP8266 */ 84 | 85 | #endif /* ESP_Line_Notify_TCP_Client_H */ -------------------------------------------------------------------------------- /src/ESP_Line_Notify_Error.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Created May 5, 2022 3 | */ 4 | 5 | #ifndef ESP_Line_Notify_Error_H 6 | #define ESP_Line_Notify_Error_H 7 | 8 | #pragma once 9 | 10 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_UNDEFINED -1000 11 | #define ESP_LINE_NOTIFY_ERROR_RANGE -100 12 | 13 | /// TCP client errors 14 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED (-1) 15 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_SEND_REQUEST_FAILED (-2) 16 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_NOT_CONNECTED (-3) 17 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_LOST (-4) 18 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_NO_STREAM (-5) 19 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_NO_HTTP_SERVER (-6) 20 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_TOO_LESS_RAM (-7) 21 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_ENCODING (-8) 22 | #define ESP_LINE_NOTIFY_ERROR_TCP_ERROR_STREAM_WRITE (-9) 23 | #define ESP_LINE_NOTIFY_ERROR_TCP_RESPONSE_PAYLOAD_READ_TIMED_OUT (-10) 24 | #define ESP_LINE_NOTIFY_ERROR_TCP_RESPONSE_READ_FAILED (-11) 25 | #define ESP_LINE_NOTIFY_ERROR_EXTERNAL_CLIENT_DISABLED (-12) 26 | #define ESP_LINE_NOTIFY_ERROR_EXTERNAL_CLIENT_NOT_INITIALIZED (-13) 27 | 28 | /// HTTP codes see RFC7231 29 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_OK 200 30 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_NON_AUTHORITATIVE_INFORMATION 203 31 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_NO_CONTENT 204 32 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_MOVED_PERMANENTLY 301 33 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_FOUND 302 34 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_USE_PROXY 305 35 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_TEMPORARY_REDIRECT 307 36 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_PERMANENT_REDIRECT 308 37 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_BAD_REQUEST 400 38 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_UNAUTHORIZED 401 39 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_FORBIDDEN 403 40 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_NOT_FOUND 404 41 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_METHOD_NOT_ALLOWED 405 42 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_NOT_ACCEPTABLE 406 43 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_PROXY_AUTHENTICATION_REQUIRED 407 44 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_REQUEST_TIMEOUT 408 45 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_LENGTH_REQUIRED 411 46 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_PRECONDITION_FAILED 412 47 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_PAYLOAD_TOO_LARGE 413 48 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_URI_TOO_LONG 414 49 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_MISDIRECTED_REQUEST 421 50 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_UNPROCESSABLE_ENTITY 422 51 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_TOO_MANY_REQUESTS 429 52 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE 431 53 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_INTERNAL_SERVER_ERROR 500 54 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_NOT_IMPLEMENTED 501 55 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_BAD_GATEWAY 502 56 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_SERVICE_UNAVAILABLE 503 57 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_GATEWAY_TIMEOUT 504 58 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_HTTP_VERSION_NOT_SUPPORTED 505 59 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_LOOP_DETECTED 508 60 | #define ESP_LINE_NOTIFY_ERROR_HTTP_CODE_NETWORK_AUTHENTICATION_REQUIRED 511 61 | 62 | #endif -------------------------------------------------------------------------------- /src/wcs/esp32/ESP_Line_Notify_TCP_Client.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ESP Line Notify TCP Client v1.0.0 3 | * 4 | * Created May 6, 2022 5 | * 6 | * The MIT License (MIT) 7 | * Copyright (c) 2022 K. Suwatchai (Mobizt) 8 | * 9 | * 10 | * Copyright (c) 2015 Markus Sattler. All rights reserved. 11 | * This file is part of the HTTPClient for Arduino. 12 | * Port to ESP32 by Evandro Luis Copercini (2017), 13 | * changed fingerprints to CA verification. 14 | * 15 | * This library is free software; you can redistribute it and/or 16 | * modify it under the terms of the GNU Lesser General Public 17 | * License as published by the Free Software Foundation; either 18 | * version 2.1 of the License, or (at your option) any later version. 19 | * 20 | * This library is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * Lesser General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public 26 | * License along with this library; if not, write to the Free Software 27 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 | * 29 | */ 30 | 31 | #ifndef ESP_Line_Notify_TCP_Client_H 32 | #define ESP_Line_Notify_TCP_Client_H 33 | 34 | #if defined(ESP32) && !defined(ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT) 35 | 36 | #include "ESP_Line_Notify_Net.h" 37 | #include "ESP_Line_Notify_Error.h" 38 | #include "mbfs/MB_FS.h" 39 | #include "./wcs/base/ESP_Line_Notify_TCP_Client_Base.h" 40 | 41 | extern "C" 42 | { 43 | #include 44 | #include 45 | } 46 | 47 | // The derived class to fix the memory leaks issue 48 | // https://github.com/espressif/arduino-esp32/issues/5480 49 | class ESP_Line_Notify_WCS : public WiFiClientSecure 50 | { 51 | public: 52 | ESP_Line_Notify_WCS(){}; 53 | ~ESP_Line_Notify_WCS(){}; 54 | 55 | int _connect(const char *host, uint16_t port, unsigned long timeout) 56 | { 57 | _timeout = timeout; 58 | if (connect(host, port) == 0) 59 | { 60 | if (_CA_cert != NULL) 61 | mbedtls_x509_crt_free(&sslclient->ca_cert); 62 | return 0; 63 | } 64 | _connected = true; 65 | return 1; 66 | } 67 | }; 68 | 69 | class ESP_Line_Notify_TCP_Client : public ESP_Line_Notify_TCP_Client_Base 70 | { 71 | 72 | public: 73 | ESP_Line_Notify_TCP_Client(); 74 | ~ESP_Line_Notify_TCP_Client(); 75 | 76 | void setCACert(const char *caCert); 77 | 78 | bool setCertFile(const char *certFile, mb_fs_mem_storage_type storageType); 79 | 80 | void setInsecure(); 81 | 82 | bool networkReady(); 83 | 84 | void networkReconnect(); 85 | 86 | void networkDisconnect(); 87 | 88 | esp_line_notify_tcp_client_type type(); 89 | 90 | bool isInitialized(); 91 | 92 | int hostByName(const char *name, IPAddress &ip); 93 | 94 | void setTimeout(uint32_t timeoutmSec); 95 | 96 | bool begin(const char *host, uint16_t port, int *response_code); 97 | 98 | bool connect(); 99 | 100 | private: 101 | std::unique_ptr wcs = std::unique_ptr(new ESP_Line_Notify_WCS()); 102 | char *cert = NULL; 103 | 104 | bool ethLinkUp(); 105 | 106 | void release(); 107 | }; 108 | 109 | #endif /* ESP32 */ 110 | 111 | #endif /* ESP_Line_Notify_TCP_Client_H */ 112 | -------------------------------------------------------------------------------- /examples/SD/SD.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by K. Suwatchai (Mobizt) 3 | * 4 | * Email: k_suwatchai@hotmail.com 5 | * 6 | * Github: https://github.com/ESP-Line-Notify 7 | * 8 | * Copyright (c) 2022 mobizt 9 | * 10 | */ 11 | 12 | /** 13 | * This example showed how to send the notified message via the Line Notify agent. 14 | * The callback function and sending result can be assigned 15 | * 16 | */ 17 | 18 | #if defined(ESP32) 19 | #include 20 | #elif defined(ESP8266) 21 | #include 22 | #endif 23 | #include 24 | 25 | // For SD card configuration and mounting 26 | #include // See src/SDHelper.h 27 | 28 | /* Set your WiFI AP credential */ 29 | #define WIFI_SSID "WIFI_AP" 30 | #define WIFI_PASSWORD "WIFI_PASSWORD" 31 | 32 | /* Define the LineNotifyClient object */ 33 | LineNotifyClient line; 34 | 35 | /* Function to print the sending result via Serial (optional) */ 36 | void printRessult(LineNotifySendingResult result); 37 | 38 | /* The sending callback function (optional) */ 39 | void sendingCallback(LineNotifySendingResult result); 40 | 41 | void setup() 42 | { 43 | 44 | Serial.begin(115200); 45 | 46 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 47 | while (WiFi.status() != WL_CONNECTED) 48 | { 49 | Serial.print("."); 50 | delay(200); 51 | } 52 | Serial.println(""); 53 | Serial.println("WiFi connected."); 54 | Serial.println("IP address: "); 55 | Serial.println(WiFi.localIP()); 56 | 57 | line.reconnect_wifi = true; 58 | 59 | Serial.println("Sending Line Notify message..."); 60 | 61 | line.token = "Your Line Notify Access Token"; 62 | line.message = "Hello world"; 63 | 64 | 65 | line.image.file.path = "/test.jpg"; 66 | line.image.file.storage_type = LineNotify_Storage_Type_SD; // LineNotify_Storage_Type_Flash or LineNotify_Storage_Type_SD 67 | line.image.file.name = "test.jpg"; 68 | 69 | line.sending_callback = sendingCallback; 70 | 71 | // Mount SD card. 72 | SD_Card_Mounting(); // See src/SDHelper.h 73 | 74 | LineNotifySendingResult result = LineNotify.send(line); 75 | 76 | // Print the sending result 77 | printRessult(result); 78 | } 79 | 80 | void loop() 81 | { 82 | } 83 | 84 | /* Function to print the sending result via Serial */ 85 | void printRessult(LineNotifySendingResult result) 86 | { 87 | if (result.status == LineNotify_Sending_Success) 88 | { 89 | Serial.printf("Status: %s\n", "success"); 90 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 91 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 92 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 93 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 94 | Serial.printf("Reset: %d\n", result.quota.reset); 95 | } 96 | else if (result.status == LineNotify_Sending_Error) 97 | { 98 | Serial.printf("Status: %s\n", "error"); 99 | Serial.printf("error code: %d\n", result.error.code); 100 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 101 | } 102 | } 103 | 104 | /* The sending callback function (optional) */ 105 | void sendingCallback(LineNotifySendingResult result) 106 | { 107 | if (result.status == LineNotify_Sending_Begin) 108 | { 109 | Serial.println("Sending begin"); 110 | } 111 | else if (result.status == LineNotify_Sending_Upload) 112 | { 113 | Serial.printf("Uploaded %s, %d%s\n", result.file_name.c_str(), (int)result.progress, "%"); 114 | } 115 | else if (result.status == LineNotify_Sending_Success) 116 | { 117 | Serial.println("Sending success\n\n"); 118 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 119 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 120 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 121 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 122 | Serial.printf("Reset: %d\n", result.quota.reset); 123 | } 124 | else if (result.status == LineNotify_Sending_Error) 125 | { 126 | Serial.println("Sending failed\n\n"); 127 | Serial.printf("error code: %d\n", result.error.code); 128 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 129 | } 130 | } -------------------------------------------------------------------------------- /src/wcs/custom/ESP_Line_Notify_Custom_TCP_Client.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ESP Line Notify TCP Client v1.0.0 3 | * 4 | * Created May 6, 2022 5 | * 6 | * The MIT License (MIT) 7 | * Copyright (c) 2022 K. Suwatchai (Mobizt) 8 | * 9 | * TCPClient Arduino library for ESP32 10 | * 11 | * Copyright (c) 2015 Markus Sattler. All rights reserved. 12 | * This file is part of the TCPClient for Arduino. 13 | * Port to ESP32 by Evandro Luis Copercini (2017), 14 | * changed fingerprints to CA verification. 15 | * 16 | * This library is free software; you can redistribute it and/or 17 | * modify it under the terms of the GNU Lesser General Public 18 | * License as published by the Free Software Foundation; either 19 | * version 2.1 of the License, or (at your option) any later version. 20 | * 21 | * This library is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | * Lesser General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU Lesser General Public 27 | * License along with this library; if not, write to the Free Software 28 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | * 30 | */ 31 | 32 | #ifndef ESP_Line_Notify_CUSTOM_TCP_Client_H 33 | #define ESP_Line_Notify_CUSTOM_TCP_Client_H 34 | 35 | // This file was included in wcs/clients.h 36 | 37 | #include 38 | #include 39 | #include "./wcs/base/ESP_Line_Notify_TCP_Client_Base.h" 40 | 41 | class ESP_Line_Notify_Custom_TCP_Client : public ESP_Line_Notify_TCP_Client_Base 42 | { 43 | friend class ESP_Line_Notify; 44 | 45 | public: 46 | ESP_Line_Notify_Custom_TCP_Client(){}; 47 | ~ESP_Line_Notify_Custom_TCP_Client(){}; 48 | 49 | void setCACert(const char *caCert) {} 50 | 51 | bool setCertFile(const char *certFile, mb_fs_mem_storage_type storageType) { return false; } 52 | 53 | void setTimeout(uint32_t timeoutmSec) 54 | { 55 | baseSetTimeout(timeoutmSec); 56 | } 57 | 58 | void ethDNSWorkAround() 59 | { 60 | } 61 | 62 | bool networkReady() 63 | { 64 | if (network_status_cb) 65 | network_status_cb(); 66 | 67 | return networkStatus; 68 | } 69 | 70 | void networkReconnect() 71 | { 72 | if (network_connection_cb) 73 | network_connection_cb(); 74 | } 75 | 76 | void networkDisconnect() 77 | { 78 | } 79 | 80 | esp_line_notify_tcp_client_type type() 81 | { 82 | return esp_line_notify_tcp_client_type_external; 83 | } 84 | 85 | bool isInitialized() 86 | { 87 | return this->client != nullptr && tcp_connection_cb != NULL && network_connection_cb != NULL; 88 | } 89 | 90 | int hostByName(const char *name, IPAddress &ip) 91 | { 92 | // return WiFi.hostByName(name, ip); 93 | return 1; 94 | } 95 | 96 | bool connect() 97 | { 98 | 99 | if (!client) 100 | return false; 101 | 102 | if (connected()) 103 | { 104 | flush(); 105 | return true; 106 | } 107 | 108 | #if !defined(ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT) 109 | return setError(ESP_LINE_NOTIFY_ERROR_EXTERNAL_CLIENT_DISABLED); 110 | #endif 111 | if (!isInitialized()) 112 | return setError(ESP_LINE_NOTIFY_ERROR_EXTERNAL_CLIENT_NOT_INITIALIZED); 113 | 114 | networkReady(); 115 | 116 | if (this->tcp_connection_cb) 117 | this->tcp_connection_cb(host.c_str(), port); 118 | 119 | return connected(); 120 | } 121 | 122 | void setClient(Client *client) 123 | { 124 | this->client = client; 125 | } 126 | 127 | void tcpConnectionRequestCallback(ESP_Line_Notify_TCPConnectionRequestCallback tcpConnectionCB) 128 | { 129 | this->tcp_connection_cb = tcpConnectionCB; 130 | } 131 | 132 | void networkConnectionRequestCallback(ESP_Line_Notify_NetworkConnectionRequestCallback networkConnectionCB) 133 | { 134 | this->network_connection_cb = networkConnectionCB; 135 | } 136 | 137 | void networkStatusRequestCallback(ESP_Line_Notify_NetworkStatusRequestCallback networkStatusCB) 138 | { 139 | this->network_status_cb = networkStatusCB; 140 | } 141 | 142 | void setNetworkStatus(bool status) 143 | { 144 | networkStatus = status; 145 | } 146 | 147 | private: 148 | ESP_Line_Notify_TCPConnectionRequestCallback tcp_connection_cb = NULL; 149 | ESP_Line_Notify_NetworkConnectionRequestCallback network_connection_cb = NULL; 150 | ESP_Line_Notify_NetworkStatusRequestCallback network_status_cb = NULL; 151 | volatile bool networkStatus = false; 152 | }; 153 | 154 | #endif -------------------------------------------------------------------------------- /examples/Google_Map/Google_Map.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by K. Suwatchai (Mobizt) 3 | * 4 | * Email: k_suwatchai@hotmail.com 5 | * 6 | * Github: https://github.com/ESP-Line-Notify 7 | * 8 | * Copyright (c) 2022 mobizt 9 | * 10 | */ 11 | 12 | /** 13 | * This example showed how to send the location and google map image message via the Line Notify agent. 14 | * The callback function and sending result can be assigned 15 | * 16 | */ 17 | 18 | #if defined(ESP32) 19 | #include 20 | #elif defined(ESP8266) 21 | #include 22 | #endif 23 | #include 24 | 25 | //Demo image data 26 | #include "image.h" 27 | 28 | /* Set your WiFI AP credential */ 29 | #define WIFI_SSID "WIFI_AP" 30 | #define WIFI_PASSWORD "WIFI_PASSWORD" 31 | 32 | /* Define the LineNotifyClient object */ 33 | LineNotifyClient client; 34 | 35 | /* Function to print the sending result via Serial (optional) */ 36 | void printRessult(LineNotifySendingResult result); 37 | 38 | /* The sending callback function (optional) */ 39 | void sendingCallback(LineNotifySendingResult result); 40 | 41 | void setup() 42 | { 43 | 44 | Serial.begin(115200); 45 | 46 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 47 | while (WiFi.status() != WL_CONNECTED) 48 | { 49 | Serial.print("."); 50 | delay(200); 51 | } 52 | Serial.println(""); 53 | Serial.println("WiFi connected."); 54 | Serial.println("IP address: "); 55 | Serial.println(WiFi.localIP()); 56 | 57 | client.reconnect_wifi = true; 58 | 59 | Serial.println("Sending Line Notify message..."); 60 | 61 | client.token = "Your Line Notify Access Token"; 62 | client.message = "Hello world"; 63 | 64 | /** To send message without user notification 65 | * 66 | client.notification_disabled = true; 67 | 68 | */ 69 | 70 | client.message = "Location"; 71 | 72 | client.gmap.zoom = 18; 73 | client.gmap.map_type = "satellite"; //roadmap or satellite 74 | client.gmap.center = "40.718217,-73.998284"; //Places or Latitude, Longitude 75 | 76 | /** To send the map image, Google Map Static API must be enable 77 | * 78 | * To enable Map Static API 79 | * https://console.cloud.google.com/apis/library/static-maps-backend.googleapis.com 80 | * 81 | * To create the API key 82 | * https://developers.google.com/maps/documentation/javascript/get-api-key 83 | 84 | 85 | client.gmap.google_api_key = "Your API Key"; 86 | client.gmap.size = "640x6400";//size of map image in pixels (widthxheight), 640x640 is maximum 87 | client.gmap.markers = "color:green|label:P|40.718217,-73.998284"; //the marker in static map image: color, label, //Latitude, Longitude 88 | 89 | */ 90 | 91 | /** To assiggn the callback function 92 | * 93 | client.sending_callback = sendingCallback; 94 | 95 | */ 96 | 97 | LineNotifySendingResult result = LineNotify.send(client); 98 | 99 | //Print the sending result 100 | printRessult(result); 101 | } 102 | 103 | void loop() 104 | { 105 | } 106 | 107 | /* Function to print the sending result via Serial */ 108 | void printRessult(LineNotifySendingResult result) 109 | { 110 | if (result.status == LineNotify_Sending_Success) 111 | { 112 | Serial.printf("Status: %s\n", "success"); 113 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 114 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 115 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 116 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 117 | Serial.printf("Reset: %d\n", result.quota.reset); 118 | } 119 | else if (result.status == LineNotify_Sending_Error) 120 | { 121 | Serial.printf("Status: %s\n", "error"); 122 | Serial.printf("error code: %d\n", result.error.code); 123 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 124 | } 125 | } 126 | 127 | /* The sending callback function (optional) */ 128 | void sendingCallback(LineNotifySendingResult result) 129 | { 130 | if (result.status == LineNotify_Sending_Begin) 131 | { 132 | Serial.println("Sending begin"); 133 | } 134 | else if (result.status == LineNotify_Sending_Upload) 135 | { 136 | Serial.printf("Uploaded %s, %d%s\n", result.file_name.c_str(), (int)result.progress, "%"); 137 | } 138 | else if (result.status == LineNotify_Sending_Success) 139 | { 140 | Serial.println("Sending success\n\n"); 141 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 142 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 143 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 144 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 145 | Serial.printf("Reset: %d\n", result.quota.reset); 146 | } 147 | else if (result.status == LineNotify_Sending_Error) 148 | { 149 | Serial.println("Sending failed\n\n"); 150 | Serial.printf("error code: %d\n", result.error.code); 151 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 152 | } 153 | } -------------------------------------------------------------------------------- /examples/Camera/Camera.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by K. Suwatchai (Mobizt) 3 | * 4 | * Email: k_suwatchai@hotmail.com 5 | * 6 | * Github: https://github.com/ESP-Line-Notify 7 | * 8 | * Copyright (c) 2022 mobizt 9 | * 10 | */ 11 | 12 | /** 13 | * This example showed how to send image from camera as a message via the Line Notify agent. 14 | * The callback function and sending result can be assigned 15 | * 16 | */ 17 | 18 | #if defined(ESP32) 19 | #include 20 | #elif defined(ESP8266) 21 | #include 22 | #endif 23 | #include 24 | 25 | //The OV2640 library 26 | #include "cam/OV2640.h" 27 | 28 | /* Set your WiFI AP credential */ 29 | #define WIFI_SSID "WIFI_AP" 30 | #define WIFI_PASSWORD "WIFI_PASSWORD" 31 | 32 | /* Define the OV2640 object */ 33 | OV2640 cam; 34 | 35 | /* Define the LineNotifyClient object */ 36 | LineNotifyClient client; 37 | 38 | /* Function to print the sending result via Serial (optional) */ 39 | void printRessult(LineNotifySendingResult result); 40 | 41 | /* The sending callback function (optional) */ 42 | void sendingCallback(LineNotifySendingResult result); 43 | 44 | void setup() 45 | { 46 | 47 | Serial.begin(115200); 48 | 49 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 50 | while (WiFi.status() != WL_CONNECTED) 51 | { 52 | Serial.print("."); 53 | delay(200); 54 | } 55 | Serial.println(""); 56 | Serial.println("WiFi connected."); 57 | Serial.println("IP address: "); 58 | Serial.println(WiFi.localIP()); 59 | 60 | camera_config_t camera_config; 61 | 62 | /** For M5Stack M5Cam - ESP32 Camera (OV2640) 63 | * Change to match your pin configuration between OV2640 Camera and ESP32 connection 64 | */ 65 | camera_config.ledc_channel = LEDC_CHANNEL_0; 66 | camera_config.ledc_timer = LEDC_TIMER_0; 67 | camera_config.pin_d0 = 17; 68 | camera_config.pin_d1 = 35; 69 | camera_config.pin_d2 = 34; 70 | camera_config.pin_d3 = 5; 71 | camera_config.pin_d4 = 39; 72 | camera_config.pin_d5 = 18; 73 | camera_config.pin_d6 = 36; 74 | camera_config.pin_d7 = 19; 75 | camera_config.pin_xclk = 27; 76 | camera_config.pin_pclk = 21; 77 | camera_config.pin_vsync = 22; 78 | camera_config.pin_href = 26; 79 | camera_config.pin_sscb_sda = 25; 80 | camera_config.pin_sscb_scl = 23; 81 | camera_config.pin_reset = 15; 82 | camera_config.xclk_freq_hz = 20000000; 83 | 84 | camera_config.pixel_format = CAMERA_PF_JPEG; 85 | camera_config.frame_size = CAMERA_FS_SVGA; 86 | 87 | cam.init(camera_config); 88 | 89 | delay(100); 90 | 91 | cam.run(); 92 | 93 | client.reconnect_wifi = true; 94 | 95 | Serial.println("Sending Line Notify message..."); 96 | 97 | client.token = "Your Line Notify Access Token"; 98 | client.message = "This is camera image"; 99 | 100 | client.image.data.blob = cam.getfb(); 101 | client.image.data.size = cam.getSize(); 102 | client.image.data.file_name = "camera.jpg"; 103 | 104 | /** To assiggn the callback function 105 | 106 | client.sending_callback = sendingCallback; 107 | 108 | */ 109 | 110 | LineNotifySendingResult result = LineNotify.send(client); 111 | 112 | //Print the sending result 113 | printRessult(result); 114 | } 115 | 116 | void loop() 117 | { 118 | } 119 | 120 | /* Function to print the sending result via Serial */ 121 | void printRessult(LineNotifySendingResult result) 122 | { 123 | if (result.status == LineNotify_Sending_Success) 124 | { 125 | Serial.printf("Status: %s\n", "success"); 126 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 127 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 128 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 129 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 130 | Serial.printf("Reset: %d\n", result.quota.reset); 131 | } 132 | else if (result.status == LineNotify_Sending_Error) 133 | { 134 | Serial.printf("Status: %s\n", "error"); 135 | Serial.printf("error code: %d\n", result.error.code); 136 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 137 | } 138 | } 139 | 140 | /* The sending callback function (optional) */ 141 | void sendingCallback(LineNotifySendingResult result) 142 | { 143 | if (result.status == LineNotify_Sending_Begin) 144 | { 145 | Serial.println("Sending begin"); 146 | } 147 | else if (result.status == LineNotify_Sending_Upload) 148 | { 149 | Serial.printf("Uploaded %s, %d%s\n", result.file_name.c_str(), (int)result.progress, "%"); 150 | } 151 | else if (result.status == LineNotify_Sending_Success) 152 | { 153 | Serial.println("Sending success\n\n"); 154 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 155 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 156 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 157 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 158 | Serial.printf("Reset: %d\n", result.quota.reset); 159 | } 160 | else if (result.status == LineNotify_Sending_Error) 161 | { 162 | Serial.println("Sending failed\n\n"); 163 | Serial.printf("error code: %d\n", result.error.code); 164 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /examples/Ethernet/ESP8266/ESP8266.ino: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Created by K. Suwatchai (Mobizt) 4 | * 5 | * Email: k_suwatchai@hotmail.com 6 | * 7 | * Github: https://github.com/mobizt/Firebase-ESP-Client 8 | * 9 | * Copyright (c) 2022 mobizt 10 | * 11 | */ 12 | 13 | /** 14 | * This example showed how to send the Line notify message via Ethernet. 15 | * This example is for ESP8266 and ENC28J60 Ethernet module. 16 | */ 17 | 18 | /** 19 | * 20 | * The ENC28J60 Ethernet module and ESP8266 board, SPI port wiring connection. 21 | * 22 | * ESP8266 (Wemos D1 Mini or NodeMCU) ENC28J60 23 | * 24 | * GPIO12 (D6) - MISO SO 25 | * GPIO13 (D7) - MOSI SI 26 | * GPIO14 (D5) - SCK SCK 27 | * GPIO16 (D0) - CS CS 28 | * GND GND 29 | * 3V3 VCC 30 | * 31 | */ 32 | 33 | #include 34 | //#include 35 | //#include 36 | 37 | #include 38 | 39 | /* Define the LineNotifyClient object */ 40 | LineNotifyClient line; 41 | 42 | /* Function to print the sending result via Serial (optional) */ 43 | void printRessult(LineNotifySendingResult result); 44 | 45 | /* The sending callback function (optional) */ 46 | void sendingCallback(LineNotifySendingResult result); 47 | 48 | #define ETH_CS_PIN 16 // D0 49 | 50 | ENC28J60lwIP eth(ETH_CS_PIN); 51 | // Wiznet5100lwIP eth(ETH_CS_PIN); 52 | // Wiznet5500lwIP eth(ETH_CS_PIN); 53 | 54 | unsigned long sendMessagePrevMillis = 0; 55 | 56 | void sendMessage() 57 | { 58 | LineNotify.spi_ethernet_module.enc28j60 = ð 59 | 60 | line.reconnect_wifi = true; 61 | 62 | Serial.println("Sending Line Notify message..."); 63 | 64 | line.token = "Your Line Notify Access Token"; 65 | line.message = "Hello world"; 66 | 67 | LineNotifySendingResult result = LineNotify.send(line); 68 | 69 | // Print the sending result 70 | printRessult(result); 71 | } 72 | 73 | void setup() 74 | { 75 | 76 | Serial.begin(115200); 77 | Serial.println(); 78 | 79 | #if defined(ESP8266) 80 | SPI.begin(); 81 | SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz? 82 | SPI.setBitOrder(MSBFIRST); 83 | SPI.setDataMode(SPI_MODE0); 84 | eth.setDefault(); // use ethernet for default route 85 | if (!eth.begin()) 86 | { 87 | Serial.println("ethernet hardware not found ... sleeping"); 88 | while (1) 89 | { 90 | delay(1000); 91 | } 92 | } 93 | else 94 | { 95 | Serial.print("connecting ethernet"); 96 | while (!eth.connected()) 97 | { 98 | Serial.print("."); 99 | delay(1000); 100 | } 101 | } 102 | Serial.println(); 103 | Serial.print("ethernet IP address: "); 104 | Serial.println(eth.localIP()); 105 | #endif 106 | } 107 | 108 | void loop() 109 | { 110 | #if defined(ESP8266) 111 | if (millis() - sendMessagePrevMillis > 30000 || sendMessagePrevMillis == 0) 112 | { 113 | sendMessagePrevMillis = millis(); 114 | sendMessage(); 115 | } 116 | #endif 117 | } 118 | 119 | /* Function to print the sending result via Serial */ 120 | void printRessult(LineNotifySendingResult result) 121 | { 122 | if (result.status == LineNotify_Sending_Success) 123 | { 124 | Serial.printf("Status: %s\n", "success"); 125 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 126 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 127 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 128 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 129 | Serial.printf("Reset: %d\n", result.quota.reset); 130 | } 131 | else if (result.status == LineNotify_Sending_Error) 132 | { 133 | Serial.printf("Status: %s\n", "error"); 134 | Serial.printf("error code: %d\n", result.error.code); 135 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 136 | } 137 | } 138 | 139 | /* The sending callback function (optional) */ 140 | void sendingCallback(LineNotifySendingResult result) 141 | { 142 | if (result.status == LineNotify_Sending_Begin) 143 | { 144 | Serial.println("Sending begin"); 145 | } 146 | else if (result.status == LineNotify_Sending_Upload) 147 | { 148 | Serial.printf("Uploaded %s, %d%s\n", result.file_name.c_str(), (int)result.progress, "%"); 149 | } 150 | else if (result.status == LineNotify_Sending_Success) 151 | { 152 | Serial.println("Sending success\n\n"); 153 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 154 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 155 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 156 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 157 | Serial.printf("Reset: %d\n", result.quota.reset); 158 | } 159 | else if (result.status == LineNotify_Sending_Error) 160 | { 161 | Serial.println("Sending failed\n\n"); 162 | Serial.printf("error code: %d\n", result.error.code); 163 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /examples/ExternalClient/ExternalClient.ino: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Created by K. Suwatchai (Mobizt) 4 | * 5 | * Email: k_suwatchai@hotmail.com 6 | * 7 | * Github: https://github.com/ESP-Line-Notify 8 | * 9 | * Copyright (c) 2022 mobizt 10 | * 11 | */ 12 | 13 | /** 14 | * This example showed how to send the notified message via the Line Notify agent 15 | * with external Client. 16 | * This example used SAMD21 device and WiFiNINA as the client. 17 | * 18 | */ 19 | 20 | #if defined(ARDUINO_ARCH_SAMD) 21 | #include 22 | #endif 23 | 24 | #include 25 | 26 | /* Set your WiFI AP credential */ 27 | #define WIFI_SSID "WIFI_AP" 28 | #define WIFI_PASSWORD "WIFI_PASSWORD" 29 | 30 | /* Define the LineNotifyClient object */ 31 | LineNotifyClient line; 32 | 33 | /* Function to print the sending result via Serial (optional) */ 34 | void printRessult(LineNotifySendingResult result); 35 | 36 | /* The sending callback function (optional) */ 37 | void sendingCallback(LineNotifySendingResult result); 38 | 39 | WiFiSSLClient client; 40 | 41 | void networkConnection() 42 | { 43 | // Reset the network connection 44 | WiFi.disconnect(); 45 | 46 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 47 | Serial.print("Connecting to Wi-Fi"); 48 | unsigned long ms = millis(); 49 | while (WiFi.status() != WL_CONNECTED) 50 | { 51 | Serial.print("."); 52 | delay(300); 53 | if (millis() - ms >= 5000) 54 | { 55 | Serial.println(" failed!"); 56 | return; 57 | } 58 | } 59 | Serial.println(); 60 | Serial_Printf("Connected with IP: "); 61 | Serial.println(WiFi.localIP()); 62 | Serial.println(); 63 | } 64 | 65 | // Define the callback function to handle server status acknowledgement 66 | void networkStatusRequestCallback() 67 | { 68 | // Set the network status 69 | line.setNetworkStatus(WiFi.status() == WL_CONNECTED); 70 | } 71 | 72 | // Define the callback function to handle server connection 73 | void tcpConnectionRequestCallback(const char *host, int port) 74 | { 75 | Serial.print("Connecting to server via external Client... "); 76 | if (!client.connect(host, port)) 77 | { 78 | Serial.println("failed."); 79 | return; 80 | } 81 | Serial.println("success."); 82 | } 83 | 84 | void setup() 85 | { 86 | 87 | Serial.begin(115200); 88 | 89 | #if defined(ARDUINO_ARCH_SAMD) 90 | while (!Serial) 91 | ; 92 | #endif 93 | 94 | networkConnection(); 95 | 96 | /* line.setExternalClient and line.setExternalClientCallbacks must be called before Firebase.begin */ 97 | 98 | /* Assign the pointer to global defined WiFiClient object */ 99 | line.setExternalClient(&client); 100 | 101 | /* Assign the required callback functions */ 102 | line.setExternalClientCallbacks(tcpConnectionRequestCallback, networkConnection, networkStatusRequestCallback); 103 | 104 | Serial.println("Sending Line Notify message..."); 105 | 106 | line.token = "Your Line Notify Access Token"; 107 | line.message = "Hello world"; 108 | 109 | LineNotifySendingResult result = LineNotify.send(line); 110 | 111 | // Print the sending result 112 | printRessult(result); 113 | } 114 | 115 | void loop() 116 | { 117 | 118 | } 119 | 120 | /* Function to print the sending result via Serial */ 121 | void printRessult(LineNotifySendingResult result) 122 | { 123 | if (result.status == LineNotify_Sending_Success) 124 | { 125 | Serial.printf("Status: %s\n", "success"); 126 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 127 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 128 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 129 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 130 | Serial.printf("Reset: %d\n", result.quota.reset); 131 | } 132 | else if (result.status == LineNotify_Sending_Error) 133 | { 134 | Serial.printf("Status: %s\n", "error"); 135 | Serial.printf("error code: %d\n", result.error.code); 136 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 137 | } 138 | } 139 | 140 | /* The sending callback function (optional) */ 141 | void sendingCallback(LineNotifySendingResult result) 142 | { 143 | if (result.status == LineNotify_Sending_Begin) 144 | { 145 | Serial.println("Sending begin"); 146 | } 147 | else if (result.status == LineNotify_Sending_Upload) 148 | { 149 | Serial.printf("Uploaded %s, %d%s\n", result.file_name.c_str(), (int)result.progress, "%"); 150 | } 151 | else if (result.status == LineNotify_Sending_Success) 152 | { 153 | Serial.println("Sending success\n\n"); 154 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 155 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 156 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 157 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 158 | Serial.printf("Reset: %d\n", result.quota.reset); 159 | } 160 | else if (result.status == LineNotify_Sending_Error) 161 | { 162 | Serial.println("Sending failed\n\n"); 163 | Serial.printf("error code: %d\n", result.error.code); 164 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 165 | } 166 | } -------------------------------------------------------------------------------- /src/ESP_Line_Notify.h: -------------------------------------------------------------------------------- 1 | /** 2 | * LINE Notify Arduino Library for Arduino version 2.1.1 3 | * 4 | * Created May 30, 2023 5 | * 6 | * 7 | * The MIT License (MIT) 8 | * Copyright (c) 2022 K. Suwatchai (Mobizt) 9 | * 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 12 | * this software and associated documentation files (the "Software"), to deal in 13 | * the Software without restriction, including without limitation the rights to 14 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 15 | * the Software, and to permit persons to whom the Software is furnished to do so, 16 | * subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 23 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 24 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 25 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 26 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #ifndef ESP_LINE_NOTIFY_H 30 | #define ESP_LINE_NOTIFY_H 31 | 32 | #include "ESP_Line_Notify_Const.h" 33 | #include "ESP_Line_Notify_Utils.h" 34 | 35 | 36 | class ESP_Line_Notify 37 | { 38 | 39 | public: 40 | ESP_Line_Notify(); 41 | ~ESP_Line_Notify(); 42 | 43 | /** Send the Line Notify message. 44 | * 45 | * @param client The LineNotifyClient data which contains TCP client with message data. 46 | * @return LineNotifySendingResult type data to get the sending result. 47 | */ 48 | LineNotifySendingResult send(LineNotifyClient &client); 49 | 50 | #if defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD) 51 | 52 | /** SD card config with GPIO pins. 53 | * 54 | * @param ss SPI Chip/Slave Select pin. 55 | * @param sck SPI Clock pin. 56 | * @param miso SPI MISO pin. 57 | * @param mosi SPI MOSI pin. 58 | * @return Boolean type status indicates the success of the operation. 59 | */ 60 | bool sdBegin(int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1); 61 | 62 | #if defined(ESP8266) 63 | 64 | /** SD card config with SD FS configurations (ESP8266 only). 65 | * 66 | * @param ss SPI Chip/Slave Select pin. 67 | * @param sdFSConfig The pointer to SDFSConfig object (ESP8266 only). 68 | * @return Boolean type status indicates the success of the operation. 69 | */ 70 | bool sdBegin(SDFSConfig *sdFSConfig); 71 | 72 | #endif 73 | 74 | #if defined(ESP32) 75 | /** SD card config with chip select and SPI configuration (ESP32 only). 76 | * 77 | * @param ss SPI Chip/Slave Select pin. 78 | * @param spiConfig The pointer to SPIClass object for SPI configuartion (ESP32 only). 79 | * @return Boolean type status indicates the success of the operation. 80 | */ 81 | bool sdBegin(int8_t ss, SPIClass *spiConfig = nullptr); 82 | #endif 83 | 84 | #if defined(MBFS_ESP32_SDFAT_ENABLED) || defined(MBFS_SDFAT_ENABLED) 85 | /** SD card config with SdFat SPI and pins configurations (ESP32 with SdFat included only). 86 | * 87 | * @param sdFatSPIConfig The pointer to SdSpiConfig object for SdFat SPI configuration. 88 | * @param ss SPI Chip/Slave Select pin. 89 | * @param sck SPI Clock pin. 90 | * @param miso SPI MISO pin. 91 | * @param mosi SPI MOSI pin. 92 | * @return Boolean type status indicates the success of the operation. 93 | */ 94 | bool sdBegin(SdSpiConfig *sdFatSPIConfig, int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1); 95 | #endif 96 | 97 | #endif 98 | 99 | #if defined(ESP32) && defined(MBFS_SD_FS) && defined(MBFS_CARD_TYPE_SD_MMC) 100 | /** Initialize the SD_MMC card (ESP32 only). 101 | * 102 | * @param mountpoint The mounting point. 103 | * @param mode1bit Allow 1 bit data line (SPI mode). 104 | * @param format_if_mount_failed Format SD_MMC card if mount failed. 105 | * @return The boolean value indicates the success of operation. 106 | */ 107 | bool sdMMCBegin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false); 108 | #endif 109 | 110 | SPI_ETH_Module spi_ethernet_module; 111 | 112 | private: 113 | ESP_Line_Notify_Utils *ut = nullptr; 114 | MB_FS *mbfs = nullptr; 115 | LineNotifySendingResult result; 116 | void setMultipartHeader(MB_String &buf, MB_String &boundary, esp_line_notify_multipart_header_type type, const char *imgFile); 117 | void getContentType(const MB_String &filename, MB_String &buf); 118 | void setMultipartBoundary(MB_String &buf, MB_String &boundary); 119 | void setHeader(LineNotifyClient &client, MB_String &buf, MB_String &boundary, size_t contentLength); 120 | bool handleResponse(LineNotifyClient &client, int &responseCode); 121 | bool reconnect(LineNotifyClient &client, unsigned long dataTime); 122 | void closeSession(LineNotifyClient &client); 123 | void reportUpploadProgress(LineNotifyClient &client, size_t total, size_t read); 124 | void errorToString(int httpCode, MB_String &buff); 125 | }; 126 | 127 | extern ESP_Line_Notify LineNotify; 128 | 129 | #endif -------------------------------------------------------------------------------- /examples/Basic/Basic.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by K. Suwatchai (Mobizt) 3 | * 4 | * Email: k_suwatchai@hotmail.com 5 | * 6 | * Github: https://github.com/ESP-Line-Notify 7 | * 8 | * Copyright (c) 2022 mobizt 9 | * 10 | */ 11 | 12 | /** 13 | * This example showed how to send the notified message via the Line Notify agent. 14 | * The callback function and sending result can be assigned 15 | * 16 | */ 17 | 18 | #if defined(ESP32) 19 | #include 20 | #elif defined(ESP8266) 21 | #include 22 | #endif 23 | #include 24 | 25 | // For SD card configuration and mounting 26 | // #include // See src/SDHelper.h 27 | 28 | // Demo image data 29 | #include "image.h" 30 | 31 | /* Set your WiFI AP credential */ 32 | #define WIFI_SSID "WIFI_AP" 33 | #define WIFI_PASSWORD "WIFI_PASSWORD" 34 | 35 | /* Define the LineNotifyClient object */ 36 | LineNotifyClient line; 37 | 38 | /* Function to print the sending result via Serial (optional) */ 39 | void printRessult(LineNotifySendingResult result); 40 | 41 | /* The sending callback function (optional) */ 42 | void sendingCallback(LineNotifySendingResult result); 43 | 44 | void setup() 45 | { 46 | 47 | Serial.begin(115200); 48 | 49 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 50 | while (WiFi.status() != WL_CONNECTED) 51 | { 52 | Serial.print("."); 53 | delay(200); 54 | } 55 | Serial.println(""); 56 | Serial.println("WiFi connected."); 57 | Serial.println("IP address: "); 58 | Serial.println(WiFi.localIP()); 59 | 60 | line.reconnect_wifi = true; 61 | 62 | Serial.println("Sending Line Notify message..."); 63 | 64 | line.token = "Your Line Notify Access Token"; 65 | line.message = "Hello world"; 66 | 67 | /** To send message without user notification 68 | 69 | line.notification_disabled = true; 70 | 71 | */ 72 | 73 | /** To send sticker 74 | * See https://devdocs.line.me/files/sticker_list.pdf for STKPKGID (Sticker Package ID). 75 | * See https://devdocs.line.me/files/sticker_list.pdf for STKID (Sticker ID). 76 | 77 | line.sticker.package_id = 2; 78 | line.sticker.id = 157; 79 | 80 | */ 81 | 82 | /** To send image from URL 83 | 84 | line.image.url = "https://cdn.pixabay.com/photo/2017/05/17/18/35/sewing-2321532_640.jpg"; 85 | 86 | */ 87 | 88 | /** To send image from flash or memory 89 | 90 | line.image.data.blob = (uint8_t *)dummyImageData; 91 | line.image.data.size = sizeof(dummyImageData); 92 | line.image.data.file_name = "image.jpg"; 93 | 94 | */ 95 | 96 | /** To send image from file systems (flash or SD) 97 | * 98 | * The SPIFFS and SD file systems are enabled by default. 99 | * To use other File systems, edit the FS_Config.h to include the header files 100 | * of File systems and defined the machro DEFAULT_FLASH_FS and DEFAULT_SD_FS with the class of File systems. 101 | 102 | 103 | line.image.file.path = "/test.jpg"; 104 | line.image.file.storage_type = LineNotify_Storage_Type_Flash; // LineNotify_Storage_Type_Flash or LineNotify_Storage_Type_SD 105 | line.image.file.name = "test.jpg"; 106 | 107 | * Mount SD card. 108 | SD_Card_Mounting(); // See src/SDHelper.h 109 | 110 | */ 111 | 112 | /** To assiggn the callback function 113 | 114 | line.sending_callback = sendingCallback; 115 | 116 | */ 117 | 118 | LineNotifySendingResult result = LineNotify.send(line); 119 | 120 | // Print the sending result 121 | printRessult(result); 122 | } 123 | 124 | void loop() 125 | { 126 | } 127 | 128 | /* Function to print the sending result via Serial */ 129 | void printRessult(LineNotifySendingResult result) 130 | { 131 | if (result.status == LineNotify_Sending_Success) 132 | { 133 | Serial.printf("Status: %s\n", "success"); 134 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 135 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 136 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 137 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 138 | Serial.printf("Reset: %d\n", result.quota.reset); 139 | } 140 | else if (result.status == LineNotify_Sending_Error) 141 | { 142 | Serial.printf("Status: %s\n", "error"); 143 | Serial.printf("error code: %d\n", result.error.code); 144 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 145 | } 146 | } 147 | 148 | /* The sending callback function (optional) */ 149 | void sendingCallback(LineNotifySendingResult result) 150 | { 151 | if (result.status == LineNotify_Sending_Begin) 152 | { 153 | Serial.println("Sending begin"); 154 | } 155 | else if (result.status == LineNotify_Sending_Upload) 156 | { 157 | Serial.printf("Uploaded %s, %d%s\n", result.file_name.c_str(), (int)result.progress, "%"); 158 | } 159 | else if (result.status == LineNotify_Sending_Success) 160 | { 161 | Serial.println("Sending success\n\n"); 162 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 163 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 164 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 165 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 166 | Serial.printf("Reset: %d\n", result.quota.reset); 167 | } 168 | else if (result.status == LineNotify_Sending_Error) 169 | { 170 | Serial.println("Sending failed\n\n"); 171 | Serial.printf("error code: %d\n", result.error.code); 172 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 173 | } 174 | } -------------------------------------------------------------------------------- /src/json/extras/print/fb_json_print.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // \author (c) Marco Paland (info@paland.com) 3 | // 2014-2019, PALANDesign Hannover, Germany 4 | // 5 | // \license The MIT License (MIT) 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on 26 | // embedded systems with a very limited resources. 27 | // Use this instead of bloated standard/newlib printf. 28 | // These routines are thread safe and reentrant. 29 | // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | #pragma once 33 | 34 | #ifndef FB_JSON_PRINT_H 35 | #define FB_JSON_PRINT_H 36 | 37 | #include 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" 42 | { 43 | #endif 44 | 45 | /** 46 | * Output a character to a custom device like UART, used by the printf() function 47 | * This function is declared here only. You have to write your custom implementation somewhere 48 | * \param character Character to output 49 | */ 50 | void fb_json_putchar(char character) __attribute__((used)); 51 | 52 | /** 53 | * Tiny printf implementation 54 | * You have to implement _putchar if you use printf() 55 | * To avoid conflicts with the regular printf() API it is overridden by macro defines 56 | * and internal underscore-appended functions like printf_() are used 57 | * \param format A string that specifies the format of the output 58 | * \return The number of characters that are written into the array, not counting the terminating null character 59 | */ 60 | int fb_json_printf(const char *format, ...) __attribute__((used)); 61 | 62 | /** 63 | * Tiny sprintf implementation 64 | * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD! 65 | * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! 66 | * \param format A string that specifies the format of the output 67 | * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character 68 | */ 69 | int fb_json_sprintf(char *buffer, const char *format, ...) __attribute__((used)); 70 | 71 | /** 72 | * Tiny snprintf/vsnprintf implementation 73 | * \param buffer A pointer to the buffer where to store the formatted string 74 | * \param count The maximum number of characters to store in the buffer, including a terminating null character 75 | * \param format A string that specifies the format of the output 76 | * \param va A value identifying a variable arguments list 77 | * \return The number of characters that COULD have been written into the buffer, not counting the terminating 78 | * null character. A value equal or larger than count indicates truncation. Only when the returned value 79 | * is non-negative and less than count, the string has been completely written. 80 | */ 81 | #define fb_json_snprintf fb_json_snprintf_ 82 | #define fb_json_vsnprintf fb_json_vsnprintf_ 83 | int fb_json_snprintf_(char *buffer, size_t count, const char *format, ...) __attribute__((used)); 84 | int fb_json_vsnprintf_(char *buffer, size_t count, const char *format, va_list va) __attribute__((used)); 85 | 86 | /** 87 | * Tiny vprintf implementation 88 | * \param format A string that specifies the format of the output 89 | * \param va A value identifying a variable arguments list 90 | * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character 91 | */ 92 | int fb_json_vprintf(const char *format, va_list va) __attribute__((used)); 93 | 94 | /** 95 | * printf with output function 96 | * You may use this as dynamic alternative to printf() with its fixed _putchar() output 97 | * \param out An output function which takes one character and an argument pointer 98 | * \param arg An argument pointer for user data passed to output function 99 | * \param format A string that specifies the format of the output 100 | * \return The number of characters that are sent to the output function, not counting the terminating null character 101 | */ 102 | int fb_json_fnprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...) __attribute__((used)); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif // _PRINTF_H_ -------------------------------------------------------------------------------- /src/wcs/esp32/ESP_Line_Notify_TCP_Client.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ESP Line Notify TCP Client v1.0.0 3 | * 4 | * Created May 6, 2022 5 | * 6 | * The MIT License (MIT) 7 | * Copyright (c) 2022 K. Suwatchai (Mobizt) 8 | * 9 | * 10 | * Copyright (c) 2015 Markus Sattler. All rights reserved. 11 | * This file is part of the HTTPClient for Arduino. 12 | * Port to ESP32 by Evandro Luis Copercini (2017), 13 | * changed fingerprints to CA verification. 14 | * 15 | * This library is free software; you can redistribute it and/or 16 | * modify it under the terms of the GNU Lesser General Public 17 | * License as published by the Free Software Foundation; either 18 | * version 2.1 of the License, or (at your option) any later version. 19 | * 20 | * This library is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * Lesser General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public 26 | * License along with this library; if not, write to the Free Software 27 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 | * 29 | */ 30 | 31 | #ifndef ESP_Line_Notify_TCP_Client_CPP 32 | #define ESP_Line_Notify_TCP_Client_CPP 33 | 34 | #if defined(ESP32) && !defined(ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT) 35 | 36 | #include "ESP_Line_Notify_TCP_Client.h" 37 | 38 | ESP_Line_Notify_TCP_Client::ESP_Line_Notify_TCP_Client() 39 | { 40 | client = wcs.get(); 41 | } 42 | 43 | ESP_Line_Notify_TCP_Client::~ESP_Line_Notify_TCP_Client() 44 | { 45 | release(); 46 | } 47 | 48 | void ESP_Line_Notify_TCP_Client::setInsecure() 49 | { 50 | #if __has_include() 51 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(3, 3, 0) 52 | wcs->setInsecure(); 53 | #endif 54 | #endif 55 | } 56 | 57 | void ESP_Line_Notify_TCP_Client::setCACert(const char *caCert) 58 | { 59 | release(); 60 | 61 | wcs = std::unique_ptr(new ESP_Line_Notify_WCS()); 62 | client = wcs.get(); 63 | 64 | if (caCert != NULL) 65 | { 66 | baseSetCertType(esp_line_notify_cert_type_data); 67 | wcs->setCACert(caCert); 68 | } 69 | else 70 | { 71 | wcs->stop(); 72 | wcs->setCACert(NULL); 73 | setInsecure(); 74 | baseSetCertType(esp_line_notify_cert_type_none); 75 | } 76 | } 77 | 78 | bool ESP_Line_Notify_TCP_Client::setCertFile(const char *caCertFile, mb_fs_mem_storage_type storageType) 79 | { 80 | if (!mbfs) 81 | return false; 82 | 83 | if (strlen(caCertFile) > 0) 84 | { 85 | MB_String filename = caCertFile; 86 | if (filename.length() > 0) 87 | { 88 | if (filename[0] != '/') 89 | filename.prepend('/'); 90 | } 91 | 92 | int len = mbfs->open(filename, storageType, mb_fs_open_mode_read); 93 | if (len > -1) 94 | { 95 | 96 | if (storageType == mb_fs_mem_storage_type_flash) 97 | { 98 | fs::File file = mbfs->getFlashFile(); 99 | wcs->loadCACert(file, len); 100 | mbfs->close(storageType); 101 | baseSetCertType(esp_line_notify_cert_type_file); 102 | } 103 | else if (storageType == mb_fs_mem_storage_type_sd) 104 | { 105 | 106 | #if defined(MBFS_ESP32_SDFAT_ENABLED) 107 | 108 | if (cert) 109 | mbfs->delP(&cert); 110 | 111 | cert = (char *)mbfs->newP(len); 112 | if (mbfs->available(storageType)) 113 | mbfs->read(storageType, (uint8_t *)cert, len); 114 | 115 | mbfs->close(storageType); 116 | wcs->setCACert((const char *)cert); 117 | baseSetCertType(esp_line_notify_cert_type_file); 118 | 119 | #elif defined(MBFS_SD_FS) 120 | fs::File file = mbfs->getSDFile(); 121 | wcs->loadCACert(file, len); 122 | mbfs->close(storageType); 123 | baseSetCertType(esp_line_notify_cert_type_file); 124 | 125 | #endif 126 | } 127 | } 128 | } 129 | 130 | return getCertType() == esp_line_notify_cert_type_file; 131 | } 132 | 133 | bool ESP_Line_Notify_TCP_Client::networkReady() 134 | { 135 | return WiFi.status() == WL_CONNECTED || ethLinkUp(); 136 | } 137 | 138 | void ESP_Line_Notify_TCP_Client::networkReconnect() 139 | { 140 | esp_wifi_connect(); 141 | } 142 | 143 | void ESP_Line_Notify_TCP_Client::networkDisconnect() 144 | { 145 | WiFi.disconnect(); 146 | } 147 | 148 | esp_line_notify_tcp_client_type ESP_Line_Notify_TCP_Client::type() 149 | { 150 | return esp_line_notify_tcp_client_type_internal; 151 | } 152 | 153 | bool ESP_Line_Notify_TCP_Client::isInitialized() { return true; } 154 | 155 | int ESP_Line_Notify_TCP_Client::hostByName(const char *name, IPAddress &ip) 156 | { 157 | return WiFi.hostByName(name, ip); 158 | } 159 | 160 | void ESP_Line_Notify_TCP_Client::setTimeout(uint32_t timeoutmSec) 161 | { 162 | if (wcs) 163 | wcs->setTimeout(timeoutmSec / 1000); 164 | 165 | baseSetTimeout(timeoutmSec); 166 | } 167 | 168 | bool ESP_Line_Notify_TCP_Client::begin(const char *host, uint16_t port, int *response_code) 169 | { 170 | this->host = host; 171 | this->port = port; 172 | this->response_code = response_code; 173 | return true; 174 | } 175 | 176 | // override the base connect 177 | bool ESP_Line_Notify_TCP_Client::connect() 178 | { 179 | if (connected()) 180 | { 181 | flush(); 182 | return true; 183 | } 184 | 185 | wcs->setTimeout(timeoutMs); 186 | 187 | if (!wcs->_connect(host.c_str(), port, timeoutMs)) 188 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 189 | 190 | return connected(); 191 | } 192 | 193 | bool ESP_Line_Notify_TCP_Client::ethLinkUp() 194 | { 195 | if (strcmp(ETH.localIP().toString().c_str(), (const char *)MBSTRING_FLASH_MCR("0.0.0.0")) != 0) 196 | { 197 | ETH.linkUp(); 198 | return true; 199 | } 200 | return false; 201 | } 202 | 203 | void ESP_Line_Notify_TCP_Client::release() 204 | { 205 | if (wcs) 206 | { 207 | wcs->stop(); 208 | wcs.reset(nullptr); 209 | wcs.release(); 210 | 211 | if (cert) 212 | mbfs->delP(&cert); 213 | 214 | baseSetCertType(esp_line_notify_cert_type_undefined); 215 | } 216 | } 217 | 218 | #endif /* ESP32 */ 219 | 220 | #endif /* ESP_Line_Notify_TCP_Client_CPP */ 221 | -------------------------------------------------------------------------------- /examples/Camera/cam/sensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * Sensor abstraction layer. 7 | * 8 | */ 9 | #ifndef __SENSOR_H__ 10 | #define __SENSOR_H__ 11 | #include 12 | 13 | #define OV9650_PID (0x96) 14 | #define OV2640_PID (0x26) 15 | #define OV7725_PID (0x77) 16 | 17 | 18 | typedef struct { 19 | uint8_t MIDH; 20 | uint8_t MIDL; 21 | uint8_t PID; 22 | uint8_t VER; 23 | } sensor_id_t; 24 | 25 | typedef enum { 26 | PIXFORMAT_RGB565, // 2BPP/RGB565 27 | PIXFORMAT_YUV422, // 2BPP/YUV422 28 | PIXFORMAT_GRAYSCALE, // 1BPP/GRAYSCALE 29 | PIXFORMAT_JPEG, // JPEG/COMPRESSED 30 | } pixformat_t; 31 | 32 | typedef enum { 33 | FRAMESIZE_40x30, // 40x30 34 | FRAMESIZE_64x32, // 64x32 35 | FRAMESIZE_64x64, // 64x64 36 | FRAMESIZE_QQCIF, // 88x72 37 | FRAMESIZE_QQVGA, // 160x120 38 | FRAMESIZE_QQVGA2, // 128x160 39 | FRAMESIZE_QCIF, // 176x144 40 | FRAMESIZE_HQVGA, // 220x160 41 | FRAMESIZE_QVGA, // 320x240 42 | FRAMESIZE_CIF, // 352x288 43 | FRAMESIZE_VGA, // 640x480 44 | FRAMESIZE_SVGA, // 800x600 45 | FRAMESIZE_SXGA, // 1280x1024 46 | FRAMESIZE_UXGA, // 1600x1200 47 | } framesize_t; 48 | 49 | typedef enum { 50 | FRAMERATE_2FPS =0x9F, 51 | FRAMERATE_8FPS =0x87, 52 | FRAMERATE_15FPS=0x83, 53 | FRAMERATE_30FPS=0x81, 54 | FRAMERATE_60FPS=0x80, 55 | } framerate_t; 56 | 57 | typedef enum { 58 | GAINCEILING_2X, 59 | GAINCEILING_4X, 60 | GAINCEILING_8X, 61 | GAINCEILING_16X, 62 | GAINCEILING_32X, 63 | GAINCEILING_64X, 64 | GAINCEILING_128X, 65 | } gainceiling_t; 66 | 67 | typedef enum { 68 | SDE_NORMAL, 69 | SDE_NEGATIVE, 70 | } sde_t; 71 | 72 | typedef enum { 73 | ATTR_CONTRAST=0, 74 | ATTR_BRIGHTNESS, 75 | ATTR_SATURATION, 76 | ATTR_GAINCEILING, 77 | } sensor_attr_t; 78 | 79 | typedef enum { 80 | ACTIVE_LOW, 81 | ACTIVE_HIGH 82 | } reset_polarity_t; 83 | 84 | typedef void (*line_filter_t) (uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, void *args); 85 | 86 | #define SENSOR_HW_FLAGS_VSYNC (0) // vertical sync polarity. 87 | #define SENSOR_HW_FLAGS_HSYNC (1) // horizontal sync polarity. 88 | #define SENSOR_HW_FLAGS_PIXCK (2) // pixel clock edge. 89 | #define SENSOR_HW_FLAGS_FSYNC (3) // hardware frame sync. 90 | #define SENSOR_HW_FLAGS_JPEGE (4) // hardware JPEG encoder. 91 | #define SENSOR_HW_FLAGS_GET(s, x) ((s)->hw_flags & (1<hw_flags |= (v<hw_flags &= ~(1<(new ESP_LINE_NOTIFY_SSL_CLIENT()); 51 | 52 | client = wcs.get(); 53 | 54 | if (caCert) 55 | { 56 | x509 = new X509List(caCert); 57 | wcs->setTrustAnchors(x509); 58 | baseSetCertType(esp_line_notify_cert_type_data); 59 | } 60 | else 61 | { 62 | wcs->setInsecure(); 63 | baseSetCertType(esp_line_notify_cert_type_none); 64 | } 65 | 66 | wcs->setBufferSizes(bsslRxSize, bsslTxSize); 67 | } 68 | 69 | bool ESP_Line_Notify_TCP_Client::setCertFile(const char *caCertFile, mb_fs_mem_storage_type storageType) 70 | { 71 | 72 | if (!mbfs) 73 | return false; 74 | 75 | if (clockReady && strlen(caCertFile) > 0) 76 | { 77 | MB_String filename = caCertFile; 78 | if (filename.length() > 0) 79 | { 80 | if (filename[0] != '/') 81 | filename.prepend('/'); 82 | } 83 | 84 | int len = mbfs->open(filename, storageType, mb_fs_open_mode_read); 85 | if (len > -1) 86 | { 87 | 88 | uint8_t *der = (uint8_t *)mbfs->newP(len); 89 | if (mbfs->available(storageType)) 90 | mbfs->read(storageType, der, len); 91 | mbfs->close(storageType); 92 | wcs->setTrustAnchors(new X509List(der, len)); 93 | mbfs->delP(&der); 94 | baseSetCertType(esp_line_notify_cert_type_file); 95 | } 96 | } 97 | 98 | wcs->setBufferSizes(bsslRxSize, bsslTxSize); 99 | 100 | return getCertType() == esp_line_notify_cert_type_file; 101 | } 102 | 103 | void ESP_Line_Notify_TCP_Client::setBufferSizes(int recv, int xmit) 104 | { 105 | bsslRxSize = recv; 106 | bsslTxSize = xmit; 107 | } 108 | 109 | bool ESP_Line_Notify_TCP_Client::networkReady() 110 | { 111 | return WiFi.status() == WL_CONNECTED || ethLinkUp(); 112 | } 113 | 114 | void ESP_Line_Notify_TCP_Client::networkReconnect() 115 | { 116 | WiFi.reconnect(); 117 | } 118 | 119 | void ESP_Line_Notify_TCP_Client::networkDisconnect() 120 | { 121 | WiFi.disconnect(); 122 | } 123 | 124 | esp_line_notify_tcp_client_type ESP_Line_Notify_TCP_Client::type() 125 | { 126 | return esp_line_notify_tcp_client_type_internal; 127 | } 128 | 129 | bool ESP_Line_Notify_TCP_Client::isInitialized() { return true; } 130 | 131 | int ESP_Line_Notify_TCP_Client::hostByName(const char *name, IPAddress &ip) 132 | { 133 | return WiFi.hostByName(name, ip); 134 | } 135 | 136 | void ESP_Line_Notify_TCP_Client::setTimeout(uint32_t timeoutmSec) 137 | { 138 | if (wcs) 139 | wcs->setTimeout(timeoutmSec); 140 | 141 | baseSetTimeout(timeoutmSec); 142 | } 143 | 144 | bool ESP_Line_Notify_TCP_Client::begin(const char *host, uint16_t port, int *response_code) 145 | { 146 | 147 | this->host = host; 148 | this->port = port; 149 | this->response_code = response_code; 150 | 151 | ethDNSWorkAround(); 152 | 153 | wcs->setBufferSizes(bsslRxSize, bsslTxSize); 154 | 155 | return true; 156 | } 157 | 158 | bool ESP_Line_Notify_TCP_Client::ethLinkUp() 159 | { 160 | 161 | if (!eth) 162 | return false; 163 | 164 | bool ret = false; 165 | #if defined(ESP8266) && defined(ESP8266_CORE_SDK_V3_X_X) 166 | 167 | #if defined(INC_ENC28J60_LWIP) 168 | if (eth->enc28j60) 169 | { 170 | ret = eth->enc28j60->status() == WL_CONNECTED; 171 | goto ex; 172 | } 173 | #endif 174 | #if defined(INC_W5100_LWIP) 175 | if (eth->w5100) 176 | { 177 | ret = eth->w5100->status() == WL_CONNECTED; 178 | goto ex; 179 | } 180 | #endif 181 | #if defined(INC_W5100_LWIP) 182 | if (eth->w5500) 183 | { 184 | ret = eth->w5500->status() == WL_CONNECTED; 185 | goto ex; 186 | } 187 | #endif 188 | 189 | return ret; 190 | 191 | ex: 192 | // workaround for ESP8266 Ethernet 193 | delayMicroseconds(0); 194 | #endif 195 | 196 | return ret; 197 | } 198 | 199 | void ESP_Line_Notify_TCP_Client::ethDNSWorkAround() 200 | { 201 | if (!eth) 202 | return; 203 | 204 | #if defined(ESP8266_CORE_SDK_V3_X_X) 205 | 206 | #if defined(INC_ENC28J60_LWIP) 207 | if (eth->enc28j60) 208 | goto ex; 209 | #endif 210 | #if defined(INC_W5100_LWIP) 211 | if (eth->w5100) 212 | goto ex; 213 | #endif 214 | #if defined(INC_W5100_LWIP) 215 | if (eth->w5500) 216 | goto ex; 217 | #endif 218 | 219 | return; 220 | 221 | ex: 222 | WiFiClient _client; 223 | _client.connect(host.c_str(), port); 224 | _client.stop(); 225 | #endif 226 | } 227 | 228 | void ESP_Line_Notify_TCP_Client::release() 229 | { 230 | if (wcs) 231 | { 232 | wcs->stop(); 233 | wcs.reset(nullptr); 234 | wcs.release(); 235 | 236 | if (x509) 237 | delete x509; 238 | 239 | baseSetCertType(esp_line_notify_cert_type_undefined); 240 | } 241 | } 242 | 243 | #endif /* ESP8266 */ 244 | 245 | #endif /* ESP_Line_Notify_TCP_Client_CPP */ -------------------------------------------------------------------------------- /src/json/MB_List.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Just a simple dynamic array implementation, MB_List v1.0.4 3 | * 4 | * Created November 1, 2022 5 | * 6 | * The MIT License (MIT) 7 | * Copyright (c) 2023 K. Suwatchai (Mobizt) 8 | * 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 11 | * this software and associated documentation files (the "Software"), to deal in 12 | * the Software without restriction, including without limitation the rights to 13 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 14 | * the Software, and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in all 18 | * copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 22 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 23 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 24 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef MB_LIST_H 29 | #define MB_LIST_H 30 | 31 | #if !defined(__AVR__) // #if __cplusplus >= 201103 32 | #define MB_VECTOR std::vector 33 | #define MB_USE_STD_VECTOR 34 | #else 35 | #define MB_VECTOR MB_List 36 | #endif 37 | 38 | template 39 | class MB_List 40 | { 41 | public: 42 | MB_List() 43 | { 44 | clear(); 45 | } 46 | 47 | ~MB_List() 48 | { 49 | clear(); 50 | } 51 | 52 | void push_back(T &data) 53 | { 54 | add(&data, current, 1); 55 | } 56 | 57 | void insert(int position, T &data) 58 | { 59 | add(&data, position, 1); 60 | } 61 | 62 | void insert(int position, int size, T &data) 63 | { 64 | add(&data, position, size); 65 | } 66 | 67 | void pop_back() 68 | { 69 | current--; 70 | if (current < 0) 71 | current = 0; 72 | } 73 | 74 | void erase(int beginIndex, int endIndex) 75 | { 76 | 77 | if (beginIndex > endIndex || beginIndex < 0) 78 | return; 79 | 80 | remove(beginIndex, endIndex - beginIndex + 1); 81 | } 82 | 83 | void erase(int beginIndex) 84 | { 85 | remove(beginIndex, 1); 86 | } 87 | 88 | int begin() 89 | { 90 | return 0; 91 | } 92 | 93 | int end() 94 | { 95 | if (current > 0) 96 | return current - 1; 97 | return 0; 98 | } 99 | 100 | void clear() 101 | { 102 | if (arr) 103 | delete[] arr; 104 | arr = NULL; 105 | current = 0; 106 | } 107 | 108 | size_t size() 109 | { 110 | return current; 111 | } 112 | 113 | T &operator[](int index) 114 | { 115 | if (index < current && index >= 0) 116 | return arr[index]; 117 | return arr[0]; 118 | } 119 | 120 | void swap(MB_List &item) 121 | { 122 | MB_List temp; 123 | temp.arr = this->arr; 124 | temp.current = this->current; 125 | temp.capacity = this->capacity; 126 | clear(); 127 | this->arr = item.arr; 128 | this->current = item.current; 129 | this->capacity = item.capacity; 130 | item.clear(); 131 | item.arr = temp.arr; 132 | item.current = temp.current; 133 | item.capacity = temp.capacity; 134 | } 135 | 136 | private: 137 | T *arr = NULL; 138 | int current = 0; 139 | int capacity = 0; 140 | 141 | void add(T *data, int index, int size) 142 | { 143 | 144 | if (index > current) 145 | return; 146 | 147 | if (current == 0) 148 | { 149 | arr = new T[1]; 150 | if (arr) 151 | { 152 | current = 1; 153 | arr[0] = *data; 154 | capacity = 1; 155 | } 156 | } 157 | else 158 | { 159 | if (current + size >= capacity) 160 | { 161 | T *temp = new T[current]; 162 | 163 | if (temp) 164 | { 165 | for (int i = 0; i < current; i++) 166 | temp[i] = arr[i]; 167 | 168 | delete[] arr; 169 | arr = NULL; 170 | 171 | capacity = current + size; 172 | capacity *= 2; 173 | 174 | arr = new T[capacity]; 175 | if (arr) 176 | { 177 | for (int i = 0; i < index; i++) 178 | arr[i] = temp[i]; 179 | 180 | for (int i = index; i < index + size; i++) 181 | arr[i] = *data; 182 | 183 | for (int i = index; i < current; i++) 184 | arr[i + size] = temp[i]; 185 | 186 | current += size; 187 | } 188 | 189 | delete[] temp; 190 | temp = NULL; 191 | } 192 | } 193 | else 194 | { 195 | for (int i = index; i < index + size; i++) 196 | arr[i] = *data; 197 | current += size; 198 | } 199 | } 200 | } 201 | 202 | void remove(int index, int size) 203 | { 204 | 205 | if (current == 0 || index < 0) 206 | return; 207 | 208 | if (index + size > current) 209 | size = current - index; 210 | 211 | T *temp = new T[current]; 212 | 213 | if (temp) 214 | { 215 | 216 | for (int i = 0; i < current; i++) 217 | temp[i] = arr[i]; 218 | 219 | delete[] arr; 220 | arr = NULL; 221 | 222 | capacity = current - size; 223 | capacity *= 2; 224 | 225 | arr = new T[capacity]; 226 | if (arr) 227 | { 228 | for (int i = 0; i < index; i++) 229 | arr[i] = temp[i]; 230 | 231 | for (int i = index; i < current - size; i++) 232 | arr[i] = temp[i + size]; 233 | 234 | current -= size; 235 | } 236 | 237 | delete[] temp; 238 | temp = NULL; 239 | } 240 | } 241 | }; 242 | 243 | #endif -------------------------------------------------------------------------------- /examples/Camera/cam/ov2640_regs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * OV2640 register definitions. 7 | */ 8 | #ifndef __REG_REGS_H__ 9 | #define __REG_REGS_H__ 10 | /* DSP register bank FF=0x00*/ 11 | #define QS 0x44 12 | #define HSIZE 0x51 13 | #define VSIZE 0x52 14 | #define XOFFL 0x53 15 | #define YOFFL 0x54 16 | #define VHYX 0x55 17 | #define DPRP 0x56 18 | #define TEST 0x57 19 | #define ZMOW 0x5A 20 | #define ZMOH 0x5B 21 | #define ZMHH 0x5C 22 | #define BPADDR 0x7C 23 | #define BPDATA 0x7D 24 | #define SIZEL 0x8C 25 | #define HSIZE8 0xC0 26 | #define VSIZE8 0xC1 27 | #define CTRL1 0xC3 28 | #define MS_SP 0xF0 29 | #define SS_ID 0xF7 30 | #define SS_CTRL 0xF7 31 | #define MC_AL 0xFA 32 | #define MC_AH 0xFB 33 | #define MC_D 0xFC 34 | #define P_CMD 0xFD 35 | #define P_STATUS 0xFE 36 | 37 | #define CTRLI 0x50 38 | #define CTRLI_LP_DP 0x80 39 | #define CTRLI_ROUND 0x40 40 | 41 | #define CTRL0 0xC2 42 | #define CTRL0_AEC_EN 0x80 43 | #define CTRL0_AEC_SEL 0x40 44 | #define CTRL0_STAT_SEL 0x20 45 | #define CTRL0_VFIRST 0x10 46 | #define CTRL0_YUV422 0x08 47 | #define CTRL0_YUV_EN 0x04 48 | #define CTRL0_RGB_EN 0x02 49 | #define CTRL0_RAW_EN 0x01 50 | 51 | #define CTRL2 0x86 52 | #define CTRL2_DCW_EN 0x20 53 | #define CTRL2_SDE_EN 0x10 54 | #define CTRL2_UV_ADJ_EN 0x08 55 | #define CTRL2_UV_AVG_EN 0x04 56 | #define CTRL2_CMX_EN 0x01 57 | 58 | #define CTRL3 0x87 59 | #define CTRL3_BPC_EN 0x80 60 | #define CTRL3_WPC_EN 0x40 61 | #define R_DVP_SP 0xD3 62 | #define R_DVP_SP_AUTO_MODE 0x80 63 | 64 | #define R_BYPASS 0x05 65 | #define R_BYPASS_DSP_EN 0x00 66 | #define R_BYPASS_DSP_BYPAS 0x01 67 | 68 | #define IMAGE_MODE 0xDA 69 | #define IMAGE_MODE_Y8_DVP_EN 0x40 70 | #define IMAGE_MODE_JPEG_EN 0x10 71 | #define IMAGE_MODE_YUV422 0x00 72 | #define IMAGE_MODE_RAW10 0x04 73 | #define IMAGE_MODE_RGB565 0x08 74 | #define IMAGE_MODE_HREF_VSYNC 0x02 75 | #define IMAGE_MODE_LBYTE_FIRST 0x01 76 | 77 | #define RESET 0xE0 78 | #define RESET_MICROC 0x40 79 | #define RESET_SCCB 0x20 80 | #define RESET_JPEG 0x10 81 | #define RESET_DVP 0x04 82 | #define RESET_IPU 0x02 83 | #define RESET_CIF 0x01 84 | 85 | #define MC_BIST 0xF9 86 | #define MC_BIST_RESET 0x80 87 | #define MC_BIST_BOOT_ROM_SEL 0x40 88 | #define MC_BIST_12KB_SEL 0x20 89 | #define MC_BIST_12KB_MASK 0x30 90 | #define MC_BIST_512KB_SEL 0x08 91 | #define MC_BIST_512KB_MASK 0x0C 92 | #define MC_BIST_BUSY_BIT_R 0x02 93 | #define MC_BIST_MC_RES_ONE_SH_W 0x02 94 | #define MC_BIST_LAUNCH 0x01 95 | 96 | #define BANK_SEL 0xFF 97 | #define BANK_SEL_DSP 0x00 98 | #define BANK_SEL_SENSOR 0x01 99 | 100 | /* Sensor register bank FF=0x01*/ 101 | #define GAIN 0x00 102 | #define COM1 0x03 103 | #define REG_PID 0x0A 104 | #define REG_VER 0x0B 105 | #define COM4 0x0D 106 | #define AEC 0x10 107 | #define CLKRC 0x11 108 | #define COM10 0x15 109 | #define HSTART 0x17 110 | #define HSTOP 0x18 111 | #define VSTART 0x19 112 | #define VSTOP 0x1A 113 | #define MIDH 0x1C 114 | #define MIDL 0x1D 115 | #define AEW 0x24 116 | #define AEB 0x25 117 | #define REG2A 0x2A 118 | #define FRARL 0x2B 119 | #define ADDVSL 0x2D 120 | #define ADDVSH 0x2E 121 | #define YAVG 0x2F 122 | #define HSDY 0x30 123 | #define HEDY 0x31 124 | #define ARCOM2 0x34 125 | #define REG45 0x45 126 | #define FLL 0x46 127 | #define FLH 0x47 128 | #define COM19 0x48 129 | #define ZOOMS 0x49 130 | #define COM22 0x4B 131 | #define COM25 0x4E 132 | #define BD50 0x4F 133 | #define BD60 0x50 134 | #define REG5D 0x5D 135 | #define REG5E 0x5E 136 | #define REG5F 0x5F 137 | #define REG60 0x60 138 | #define HISTO_LOW 0x61 139 | #define HISTO_HIGH 0x62 140 | 141 | #define REG04 0x04 142 | #define REG04_DEFAULT 0x28 143 | #define REG04_VFLIP_IMG 0x40 144 | #define REG04_HFLIP_IMG 0x80 145 | #define REG04_VREF_EN 0x10 146 | #define REG04_HREF_EN 0x08 147 | #define REG04_SET(x) (REG04_DEFAULT|x) 148 | 149 | #define REG08 0x08 150 | #define COM2 0x09 151 | #define COM2_STDBY 0x10 152 | #define COM2_OUT_DRIVE_1x 0x00 153 | #define COM2_OUT_DRIVE_2x 0x01 154 | #define COM2_OUT_DRIVE_3x 0x02 155 | #define COM2_OUT_DRIVE_4x 0x03 156 | 157 | #define COM3 0x0C 158 | #define COM3_DEFAULT 0x38 159 | #define COM3_BAND_50Hz 0x04 160 | #define COM3_BAND_60Hz 0x00 161 | #define COM3_BAND_AUTO 0x02 162 | #define COM3_BAND_SET(x) (COM3_DEFAULT|x) 163 | 164 | #define COM7 0x12 165 | #define COM7_SRST 0x80 166 | #define COM7_RES_UXGA 0x00 /* UXGA */ 167 | #define COM7_RES_SVGA 0x40 /* SVGA */ 168 | #define COM7_RES_CIF 0x20 /* CIF */ 169 | #define COM7_ZOOM_EN 0x04 /* Enable Zoom */ 170 | #define COM7_COLOR_BAR 0x02 /* Enable Color Bar Test */ 171 | 172 | #define COM8 0x13 173 | #define COM8_DEFAULT 0xC0 174 | #define COM8_BNDF_EN 0x20 /* Enable Banding filter */ 175 | #define COM8_AGC_EN 0x04 /* AGC Auto/Manual control selection */ 176 | #define COM8_AEC_EN 0x01 /* Auto/Manual Exposure control */ 177 | #define COM8_SET(x) (COM8_DEFAULT|x) 178 | 179 | #define COM9 0x14 /* AGC gain ceiling */ 180 | #define COM9_DEFAULT 0x08 181 | #define COM9_AGC_GAIN_2x 0x00 /* AGC: 2x */ 182 | #define COM9_AGC_GAIN_4x 0x01 /* AGC: 4x */ 183 | #define COM9_AGC_GAIN_8x 0x02 /* AGC: 8x */ 184 | #define COM9_AGC_GAIN_16x 0x03 /* AGC: 16x */ 185 | #define COM9_AGC_GAIN_32x 0x04 /* AGC: 32x */ 186 | #define COM9_AGC_GAIN_64x 0x05 /* AGC: 64x */ 187 | #define COM9_AGC_GAIN_128x 0x06 /* AGC: 128x */ 188 | #define COM9_AGC_SET(x) (COM9_DEFAULT|(x<<5)) 189 | 190 | #define COM10 0x15 191 | #define COM10_HREF_EN 0x80 /* HSYNC changes to HREF */ 192 | #define COM10_HSYNC_EN 0x40 /* HREF changes to HSYNC */ 193 | #define COM10_PCLK_FREE 0x20 /* PCLK output option: free running PCLK */ 194 | #define COM10_PCLK_EDGE 0x10 /* Data is updated at the rising edge of PCLK */ 195 | #define COM10_HREF_NEG 0x08 /* HREF negative */ 196 | #define COM10_VSYNC_NEG 0x02 /* VSYNC negative */ 197 | #define COM10_HSYNC_NEG 0x01 /* HSYNC negative */ 198 | 199 | #define CTRL1_AWB 0x08 /* Enable AWB */ 200 | 201 | #define VV 0x26 202 | #define VV_AGC_TH_SET(h,l) ((h<<4)|(l&0x0F)) 203 | 204 | #define REG32 0x32 205 | #define REG32_UXGA 0x36 206 | #define REG32_SVGA 0x09 207 | #define REG32_CIF 0x00 208 | #endif //__REG_REGS_H__ 209 | -------------------------------------------------------------------------------- /examples/Ethernet/ESP32/ESP32.ino: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Created by K. Suwatchai (Mobizt) 4 | * 5 | * Email: k_suwatchai@hotmail.com 6 | * 7 | * Github: https://github.com/ESP-Line-Notify 8 | * 9 | * Copyright (c) 2022 mobizt 10 | * 11 | */ 12 | 13 | /** 14 | * This example showed how to send the Line notify message via Ethernet. 15 | * This example is for ESP32 with LAN8720 Ethernet board. 16 | */ 17 | 18 | /** 19 | * There are may sources for LAN8720 and ESP32 interconnection on the internet which may 20 | * work for your LAN8720 board. 21 | * 22 | * Some methods worked unless no IP is available. 23 | * 24 | * This modification and interconnection provided in this example are mostly worked as 25 | * the 50 MHz clock was created internally in ESP32 which GPIO 17 is set to be output of this clock 26 | * and feeds to the LAN8720 chip XTAL input. 27 | * 28 | * The on-board LAN8720 50 MHz XTAL chip will be disabled by connect its enable pin or pin 1 to GND. 29 | * 30 | * Pleae see the images in the folder "modified_LAN8720_board_images" for how to modify the LAN8720 board. 31 | * 32 | * The LAN8720 Ethernet modified board and ESP32 board wiring connection. 33 | * 34 | * ESP32 LAN8720 35 | * 36 | * GPIO17 - EMAC_CLK_OUT_180 nINT/REFCLK - LAN8720 XTAL1/CLKIN 4k7 Pulldown 37 | * GPIO22 - EMAC_TXD1 TX1 38 | * GPIO19 - EMAC_TXD0 TX0 39 | * GPIO21 - EMAC_TX_EN TX_EN 40 | * GPIO26 - EMAC_RXD1 RX1 41 | * GPIO25 - EMAC_RXD0 RX0 42 | * GPIO27 - EMAC_RX_DV CRS 43 | * GPIO23 - MDC MDC 44 | * GPIO18 - MDIO MDIO 45 | * GND GND 46 | * 3V3 VCC 47 | * 48 | */ 49 | 50 | #include 51 | 52 | /* Define the LineNotifyClient object */ 53 | LineNotifyClient line; 54 | 55 | /* Function to print the sending result via Serial (optional) */ 56 | void printRessult(LineNotifySendingResult result); 57 | 58 | /* The sending callback function (optional) */ 59 | void sendingCallback(LineNotifySendingResult result); 60 | 61 | #ifdef ETH_CLK_MODE 62 | #undef ETH_CLK_MODE 63 | #endif 64 | #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT // RMII clock output from GPIO17 65 | 66 | // Pin# of the enable signal for the external crystal oscillator (-1 to disable) 67 | #define ETH_POWER_PIN -1 68 | 69 | // Type of the Ethernet PHY (LAN8720 or TLK110) 70 | #define ETH_TYPE ETH_PHY_LAN8720 71 | 72 | // I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110) 73 | #define ETH_ADDR 1 74 | 75 | // Pin# of the I²C clock signal for the Ethernet PHY 76 | #define ETH_MDC_PIN 23 77 | 78 | // Pin# of the I²C IO signal for the Ethernet PHY 79 | #define ETH_MDIO_PIN 18 80 | 81 | static bool eth_connected = false; 82 | 83 | unsigned long sendMessagePrevMillis = 0; 84 | 85 | #if defined(ESP32) 86 | 87 | void WiFiEvent(WiFiEvent_t event) 88 | { 89 | // Do not run any function here to prevent stack overflow or nested interrupt 90 | 91 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0) 92 | 93 | switch (event) 94 | { 95 | case ARDUINO_EVENT_ETH_START: 96 | Serial.println("ETH Started"); 97 | // set eth hostname here 98 | ETH.setHostname("esp32-ethernet"); 99 | break; 100 | case ARDUINO_EVENT_ETH_CONNECTED: 101 | Serial.println("ETH Connected"); 102 | break; 103 | case ARDUINO_EVENT_ETH_GOT_IP: 104 | Serial.print("ETH MAC: "); 105 | Serial.print(ETH.macAddress()); 106 | Serial.print(", IPv4: "); 107 | Serial.print(ETH.localIP()); 108 | if (ETH.fullDuplex()) 109 | { 110 | Serial.print(", FULL_DUPLEX"); 111 | } 112 | Serial.print(", "); 113 | Serial.print(ETH.linkSpeed()); 114 | Serial.println("Mbps"); 115 | eth_connected = true; 116 | break; 117 | case ARDUINO_EVENT_ETH_DISCONNECTED: 118 | Serial.println("ETH Disconnected"); 119 | eth_connected = false; 120 | break; 121 | case ARDUINO_EVENT_ETH_STOP: 122 | Serial.println("ETH Stopped"); 123 | eth_connected = false; 124 | break; 125 | default: 126 | break; 127 | } 128 | 129 | #else 130 | switch (event) 131 | { 132 | case SYSTEM_EVENT_ETH_START: 133 | Serial.println("ETH Started"); 134 | // set eth hostname here 135 | ETH.setHostname("esp32-ethernet"); 136 | break; 137 | case SYSTEM_EVENT_ETH_CONNECTED: 138 | Serial.println("ETH Connected"); 139 | break; 140 | case SYSTEM_EVENT_ETH_GOT_IP: 141 | Serial.print("ETH MAC: "); 142 | Serial.print(ETH.macAddress()); 143 | Serial.print(", IPv4: "); 144 | Serial.print(ETH.localIP()); 145 | if (ETH.fullDuplex()) 146 | { 147 | Serial.print(", FULL_DUPLEX"); 148 | } 149 | Serial.print(", "); 150 | Serial.print(ETH.linkSpeed()); 151 | Serial.println("Mbps"); 152 | eth_connected = true; 153 | break; 154 | case SYSTEM_EVENT_ETH_DISCONNECTED: 155 | Serial.println("ETH Disconnected"); 156 | eth_connected = false; 157 | break; 158 | case SYSTEM_EVENT_ETH_STOP: 159 | Serial.println("ETH Stopped"); 160 | eth_connected = false; 161 | break; 162 | default: 163 | break; 164 | } 165 | #endif 166 | } 167 | 168 | #endif 169 | 170 | void sendMessage() 171 | { 172 | line.reconnect_wifi = true; 173 | 174 | Serial.println("Sending Line Notify message..."); 175 | 176 | line.token = "Your Line Notify Access Token"; 177 | line.message = "Hello world"; 178 | 179 | LineNotifySendingResult result = LineNotify.send(line); 180 | 181 | // Print the sending result 182 | printRessult(result); 183 | } 184 | 185 | void setup() 186 | { 187 | 188 | Serial.begin(115200); 189 | #if defined(ESP32) 190 | WiFi.onEvent(WiFiEvent); 191 | ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE); 192 | #endif 193 | } 194 | 195 | void loop() 196 | { 197 | #if defined(ESP32) 198 | if (eth_connected && (millis() - sendMessagePrevMillis > 30000 || sendMessagePrevMillis == 0)) 199 | { 200 | sendMessagePrevMillis = millis(); 201 | sendMessage(); 202 | } 203 | #endif 204 | } 205 | 206 | /* Function to print the sending result via Serial */ 207 | void printRessult(LineNotifySendingResult result) 208 | { 209 | if (result.status == LineNotify_Sending_Success) 210 | { 211 | Serial.printf("Status: %s\n", "success"); 212 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 213 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 214 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 215 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 216 | Serial.printf("Reset: %d\n", result.quota.reset); 217 | } 218 | else if (result.status == LineNotify_Sending_Error) 219 | { 220 | Serial.printf("Status: %s\n", "error"); 221 | Serial.printf("error code: %d\n", result.error.code); 222 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 223 | } 224 | } 225 | 226 | /* The sending callback function (optional) */ 227 | void sendingCallback(LineNotifySendingResult result) 228 | { 229 | if (result.status == LineNotify_Sending_Begin) 230 | { 231 | Serial.println("Sending begin"); 232 | } 233 | else if (result.status == LineNotify_Sending_Upload) 234 | { 235 | Serial.printf("Uploaded %s, %d%s\n", result.file_name.c_str(), (int)result.progress, "%"); 236 | } 237 | else if (result.status == LineNotify_Sending_Success) 238 | { 239 | Serial.println("Sending success\n\n"); 240 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 241 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 242 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 243 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 244 | Serial.printf("Reset: %d\n", result.quota.reset); 245 | } 246 | else if (result.status == LineNotify_Sending_Error) 247 | { 248 | Serial.println("Sending failed\n\n"); 249 | Serial.printf("error code: %d\n", result.error.code); 250 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [DEPRECATED] LINE Notify Arduino Library for ESP8266 and ESP32 2 | 3 | This Arduino library allows ESP8266 and ESP32 to send LINE Notify message, sticker and images. 4 | 5 | The library supported Ethernet in ESP32 using LAN8720, TLK110 and IP101 Ethernet modules and ESP8266 using ENC28J60, W5100 and W5500 Ethernet modules 6 | 7 | This library allows you to use external Arduino Clients network interfaces e.g. WiFiClient, EthernetClient and GSMClient. 8 | 9 | To use external Client, see the [ExternalClient examples](/examples/ExternalClient). 10 | 11 | The flash and SD filesystems supports depend on the devices and third party filesystems libraries installed. 12 | 13 | 14 | Copyright (c) 2022 K. Suwatchai (Mobizt). 15 | 16 | 17 | ## Tested Devices 18 | 19 | This following devices were tested and work well. 20 | 21 | * Sparkfun ESP32 Thing 22 | * NodeMCU-32 23 | * WEMOS LOLIN32 24 | * TTGO T8 V1.8 25 | * M5Stack ESP32 26 | * NodeMCU ESP8266 27 | * Wemos D1 Mini (ESP8266) 28 | * Arduino MKR WiFi 1010 29 | * LAN8720 Ethernet PHY 30 | * ENC28J60 SPI Ethernet module 31 | 32 | 33 | 34 | ## Features 35 | 36 | * Support sending text, sticker and images from flash and SD memory. 37 | 38 | * Show upload progress via callback function. 39 | 40 | * Support SRAM/PSRAM in ESP8266 and ESP32. 41 | 42 | * Flash and SD File systems can be configured to use LittleFS, FFat and SD_MMC 43 | 44 | 45 | 46 | ## Installation 47 | 48 | 49 | Click on **Clone or download** dropdown at the top of repository, select **Download ZIP** and save file on your computer. 50 | 51 | From Arduino IDE, goto menu **Sketch** -> **Include Library** -> **Add .ZIP Library...** and choose **ESP-Line-Notify-main.zip** that previously downloaded. 52 | 53 | Go to menu **Files** -> **Examples** -> **ESP-Line-Notify-main** and choose one from examples 54 | 55 | 56 | ### Use SRAM/PSRAM in ESP32 and ESP8266 57 | 58 | 59 | To enable PSRAM in ESP32 module with on-board PSRAM chip, in Arduino IDE 60 | 61 | ![Enable PSRAM in ESP32](/media/images/ESP32-PSRAM.png) 62 | 63 | 64 | In PlatformIO in VSCode IDE, add the following build_flags in your project's platformio.ini file 65 | 66 | ```ini 67 | build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue 68 | ``` 69 | 70 | *When config the IDE or add the build flags to use PSRAM in the ESP32 dev boards that do not have on-board PSRAM chip, your device will be crashed (reset). 71 | 72 | 73 | In ESP8266, to use external Heap from 1 Mbit SRAM 23LC1024, choose the MMU **option 5**, 128K External 23LC1024. 74 | 75 | ![MMU VM 128K](/media/images/ESP8266_VM.png) 76 | 77 | To use external Heap from PSRAM, choose the MMU **option 6**, 1M External 64 MBit PSRAM. 78 | 79 | In PlatformIO, **PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_128K** or **PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_1024K** build flag should be assigned in platformio.ini. 80 | 81 | ```ini 82 | [env:d1_mini] 83 | platform = espressif8266 84 | build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_128K 85 | board = d1_mini 86 | framework = arduino 87 | monitor_speed = 115200 88 | ``` 89 | 90 | The connection between SRAM/PSRAM and ESP8266 91 | 92 | ``` 93 | 23LC1024/ESP-PSRAM64 ESP8266 94 | 95 | CS (Pin 1) GPIO15 96 | SCK (Pin 6) GPIO14 97 | MOSI (Pin 5) GPIO13 98 | MISO (Pin 2) GPIO12 99 | /HOLD (Pin 7 on 23LC1024 only) 3V3 100 | Vcc (Pin 8) 3V3 101 | Vcc (Pin 4) GND 102 | ``` 103 | 104 | 105 | To use SRAM/PSRAM in this library, the macro in file [**FS_Config.h**](src/FS_Config.h) was set. 106 | 107 | ```cpp 108 | #define ESP_LINE_NOTIFY_USE_PSRAM 109 | ``` 110 | 111 | 112 | 113 | ## Usages 114 | 115 | ```Cpp 116 | 117 | #include 118 | 119 | /* Define the LineNotifyClient object */ 120 | LineNotifyClient line; 121 | 122 | 123 | line.token = "Your Line Notify Access Token"; 124 | line.message = "Hello world"; 125 | 126 | //The image to send 127 | line.image.file.path = "/test.jpg"; 128 | line.image.file.storage_type = LineNotify_Storage_Type_Flash; //or LineNotify_Storage_Type_SD 129 | line.image.file.name = "test.jpg"; 130 | 131 | LineNotiFySendingResult result = lineNotify.send(line); 132 | 133 | if (result.status == LineNotify_Sending_Success) 134 | { 135 | Serial.printf("Status: %s\n", "success"); 136 | Serial.printf("Text limit: %d\n", result.quota.text.limit); 137 | Serial.printf("Text remaining: %d\n", result.quota.text.remaining); 138 | Serial.printf("Image limit: %d\n", result.quota.image.limit); 139 | Serial.printf("Image remaining: %d\n", result.quota.image.remaining); 140 | Serial.printf("Reset: %d\n", result.quota.reset); 141 | } 142 | else if (result.status == LineNotify_Sending_Error) 143 | { 144 | Serial.printf("Status: %s\n", "error"); 145 | Serial.printf("error code: %d\n", result.error.code); 146 | Serial.printf("error msg: %s\n", result.error.message.c_str()); 147 | } 148 | 149 | ``` 150 | 151 | 152 | See [full examples](/examples) for complete usages. 153 | 154 | 155 | 156 | ## All Supported Functions 157 | 158 | 159 | #### Send the Line Notify message. 160 | 161 | param **`client`** The LineNotifyClient data which contains TCP client with message data 162 | 163 | return **`LineNotiFySendingResult`** type data to get the sending result. 164 | 165 | ```C++ 166 | LineNotiFySendingResult send(LineNotifyClient &client); 167 | ``` 168 | 169 | 170 | 171 | 172 | #### SD card config with GPIO pins. 173 | 174 | param **`ss`** SPI Chip/Slave Select pin. 175 | 176 | param **`sck`** SPI Clock pin. 177 | 178 | param **`miso`** SPI MISO pin. 179 | 180 | param **`mosi`** SPI MOSI pin. 181 | 182 | return **`Boolean`** type status indicates the success of the operation. 183 | 184 | ```cpp 185 | bool sdBegin( int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1); 186 | ``` 187 | 188 | 189 | 190 | #### SD card config with SD FS configurations (ESP8266 only). 191 | 192 | param **`sdFSConfig`** The pointer to SDFSConfig object (ESP8266 only). 193 | 194 | return **`Boolean`** type status indicates the success of the operation. 195 | 196 | ```cpp 197 | bool sdBegin(SDFSConfig *sdFSConfig); 198 | ``` 199 | 200 | 201 | 202 | #### SD card config with chip select and SPI configuration (ESP32 only). 203 | 204 | param **`ss`** SPI Chip/Slave Select pin. 205 | 206 | param **`spiConfig`** The pointer to SPIClass object for SPI configuartion (ESP32 only). 207 | 208 | return **`Boolean`** type status indicates the success of the operation. 209 | 210 | ```cpp 211 | bool sdBegin(int8_t ss, SPIClass *spiConfig = nullptr); 212 | ``` 213 | 214 | 215 | #### SD card config with SdFat SPI and pins configurations (ESP32 with SdFat included only). 216 | 217 | param **`sdFatSPIConfig`** The pointer to SdSpiConfig object for SdFat SPI configuration. 218 | 219 | param **`ss`** SPI Chip/Slave Select pin. 220 | 221 | param **`sck`** SPI Clock pin. 222 | 223 | param **`miso`** SPI MISO pin. 224 | 225 | param **`mosi`** SPI MOSI pin. 226 | 227 | return **`Boolean`** type status indicates the success of the operation. 228 | 229 | ```cpp 230 | bool sdBegin(SdSpiConfig *sdFatSPIConfig, int8_t ss = -1, int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1); 231 | ``` 232 | 233 | 234 | 235 | #### Initialize the SD_MMC card (ESP32 only). 236 | 237 | param **`mountpoint`** The mounting point. 238 | 239 | param **`mode1bit`** Allow 1 bit data line (SPI mode). 240 | 241 | param **`format_if_mount_failed`** Format SD_MMC card if mount failed. 242 | 243 | return **`Boolean`** type status indicates the success of the operation. 244 | 245 | ```cpp 246 | bool sdMMCBegin( mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false); 247 | ``` 248 | 249 | 250 | 251 | 252 | 253 | 254 | ## License 255 | 256 | The MIT License (MIT) 257 | 258 | Copyright (c) 2022 K. Suwatchai (Mobizt) 259 | 260 | 261 | Permission is hereby granted, free of charge, to any person returning a copy of 262 | this software and associated documentation files (the "Software"), to deal in 263 | the Software without restriction, including without limitation the rights to 264 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 265 | the Software, and to permit persons to whom the Software is furnished to do so, 266 | subject to the following conditions: 267 | 268 | The above copyright notice and this permission notice shall be included in all 269 | copies or substantial portions of the Software. 270 | 271 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 272 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 273 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 274 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 275 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 276 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 277 | 278 | -------------------------------------------------------------------------------- /examples/Camera/cam/twi.c: -------------------------------------------------------------------------------- 1 | /* 2 | si2c.c - Software I2C library for ESP31B 3 | 4 | Copyright (c) 2015 Hristo Gochkov. All rights reserved. 5 | This file is part of the ESP31B core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #include 22 | #include 23 | #include "twi.h" 24 | #include "soc/gpio_reg.h" 25 | #include 26 | #include "esp32-hal-gpio.h" 27 | 28 | unsigned char twi_dcount = 18; 29 | static unsigned char twi_sda, twi_scl; 30 | 31 | static inline void SDA_LOW() 32 | { 33 | //Enable SDA (becomes output and since GPO is 0 for the pin, 34 | // it will pull the line low) 35 | if (twi_sda < 32) 36 | { 37 | REG_WRITE(GPIO_ENABLE_W1TS_REG, BIT(twi_sda)); 38 | } 39 | else 40 | { 41 | REG_WRITE(GPIO_ENABLE1_W1TS_REG, BIT(twi_sda - 32)); 42 | } 43 | } 44 | 45 | static inline void SDA_HIGH() 46 | { 47 | //Disable SDA (becomes input and since it has pullup it will go high) 48 | if (twi_sda < 32) 49 | { 50 | REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT(twi_sda)); 51 | } 52 | else 53 | { 54 | REG_WRITE(GPIO_ENABLE1_W1TC_REG, BIT(twi_sda - 32)); 55 | } 56 | } 57 | 58 | static inline uint32_t SDA_READ() 59 | { 60 | if (twi_sda < 32) 61 | { 62 | return (REG_READ(GPIO_IN_REG) & BIT(twi_sda)) != 0; 63 | } 64 | else 65 | { 66 | return (REG_READ(GPIO_IN1_REG) & BIT(twi_sda - 32)) != 0; 67 | } 68 | } 69 | 70 | static void SCL_LOW() 71 | { 72 | if (twi_scl < 32) 73 | { 74 | REG_WRITE(GPIO_ENABLE_W1TS_REG, BIT(twi_scl)); 75 | } 76 | else 77 | { 78 | REG_WRITE(GPIO_ENABLE1_W1TS_REG, BIT(twi_scl - 32)); 79 | } 80 | } 81 | 82 | static void SCL_HIGH() 83 | { 84 | if (twi_scl < 32) 85 | { 86 | REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT(twi_scl)); 87 | } 88 | else 89 | { 90 | REG_WRITE(GPIO_ENABLE1_W1TC_REG, BIT(twi_scl - 32)); 91 | } 92 | } 93 | 94 | static uint32_t SCL_READ() 95 | { 96 | if (twi_scl < 32) 97 | { 98 | return (REG_READ(GPIO_IN_REG) & BIT(twi_scl)) != 0; 99 | } 100 | else 101 | { 102 | return (REG_READ(GPIO_IN1_REG) & BIT(twi_scl - 32)) != 0; 103 | } 104 | } 105 | 106 | #ifndef FCPU80 107 | #define FCPU80 80000000L 108 | #endif 109 | 110 | #if F_CPU == FCPU80 111 | #define TWI_CLOCK_STRETCH 800 112 | #else 113 | #define TWI_CLOCK_STRETCH 1600 114 | #endif 115 | 116 | void twi_setClock(unsigned int freq) 117 | { 118 | #if F_CPU == FCPU80 119 | if (freq <= 100000) 120 | twi_dcount = 19; //about 100KHz 121 | else if (freq <= 200000) 122 | twi_dcount = 8; //about 200KHz 123 | else if (freq <= 300000) 124 | twi_dcount = 3; //about 300KHz 125 | else if (freq <= 400000) 126 | twi_dcount = 1; //about 400KHz 127 | else 128 | twi_dcount = 1; //about 400KHz 129 | #else 130 | if (freq <= 100000) 131 | twi_dcount = 32; //about 100KHz 132 | else if (freq <= 200000) 133 | twi_dcount = 14; //about 200KHz 134 | else if (freq <= 300000) 135 | twi_dcount = 8; //about 300KHz 136 | else if (freq <= 400000) 137 | twi_dcount = 5; //about 400KHz 138 | else if (freq <= 500000) 139 | twi_dcount = 3; //about 500KHz 140 | else if (freq <= 600000) 141 | twi_dcount = 2; //about 600KHz 142 | else 143 | twi_dcount = 1; //about 700KHz 144 | #endif 145 | } 146 | 147 | void i2c_pinMode(int pin, int mode) 148 | { 149 | gpio_config_t conf = {0}; 150 | conf.pin_bit_mask = 1LL << pin; 151 | if (mode == OUTPUT) 152 | { 153 | conf.mode = GPIO_MODE_OUTPUT; 154 | } 155 | if (mode == INPUT || mode == INPUT_PULLUP) 156 | { 157 | conf.mode = GPIO_MODE_INPUT; 158 | } 159 | if (mode == INPUT) 160 | { 161 | conf.pull_down_en = GPIO_PULLDOWN_DISABLE; 162 | conf.pull_up_en = GPIO_PULLUP_DISABLE; 163 | } 164 | else if (mode == INPUT_PULLUP) 165 | { 166 | conf.pull_down_en = GPIO_PULLDOWN_DISABLE; 167 | conf.pull_up_en = GPIO_PULLUP_ENABLE; 168 | } 169 | gpio_config(&conf); 170 | } 171 | 172 | void twi_init(unsigned char sda, unsigned char scl) 173 | { 174 | twi_sda = sda; 175 | twi_scl = scl; 176 | i2c_pinMode(twi_sda, OUTPUT); 177 | i2c_pinMode(twi_scl, OUTPUT); 178 | 179 | gpio_set_level(twi_sda, 0); 180 | gpio_set_level(twi_scl, 0); 181 | 182 | i2c_pinMode(twi_sda, INPUT_PULLUP); 183 | i2c_pinMode(twi_scl, INPUT_PULLUP); 184 | twi_setClock(100000); 185 | } 186 | 187 | void twi_stop(void) 188 | { 189 | i2c_pinMode(twi_sda, INPUT); 190 | i2c_pinMode(twi_scl, INPUT); 191 | } 192 | 193 | static void twi_delay(unsigned char v) 194 | { 195 | unsigned int i; 196 | #pragma GCC diagnostic push 197 | #pragma GCC diagnostic ignored "-Wunused-but-set-variable" 198 | unsigned int reg; 199 | for (i = 0; i < v; i++) 200 | reg = REG_READ(GPIO_IN_REG); 201 | #pragma GCC diagnostic pop 202 | } 203 | 204 | static bool twi_write_start(void) 205 | { 206 | SCL_HIGH(); 207 | SDA_HIGH(); 208 | if (SDA_READ() == 0) 209 | return false; 210 | twi_delay(twi_dcount); 211 | SDA_LOW(); 212 | twi_delay(twi_dcount); 213 | return true; 214 | } 215 | 216 | static bool twi_write_stop(void) 217 | { 218 | unsigned int i = 0; 219 | SCL_LOW(); 220 | SDA_LOW(); 221 | twi_delay(twi_dcount); 222 | SCL_HIGH(); 223 | while (SCL_READ() == 0 && (i++) < TWI_CLOCK_STRETCH) 224 | ; // Clock stretching (up to 100us) 225 | twi_delay(twi_dcount); 226 | SDA_HIGH(); 227 | twi_delay(twi_dcount); 228 | 229 | return true; 230 | } 231 | 232 | bool do_log = false; 233 | static bool twi_write_bit(bool bit) 234 | { 235 | unsigned int i = 0; 236 | SCL_LOW(); 237 | if (bit) 238 | { 239 | SDA_HIGH(); 240 | if (do_log) 241 | { 242 | twi_delay(twi_dcount + 1); 243 | } 244 | } 245 | else 246 | { 247 | SDA_LOW(); 248 | if (do_log) 249 | { 250 | } 251 | } 252 | twi_delay(twi_dcount + 1); 253 | SCL_HIGH(); 254 | while (SCL_READ() == 0 && (i++) < TWI_CLOCK_STRETCH) 255 | ; // Clock stretching (up to 100us) 256 | twi_delay(twi_dcount); 257 | return true; 258 | } 259 | 260 | static bool twi_read_bit(void) 261 | { 262 | unsigned int i = 0; 263 | SCL_LOW(); 264 | SDA_HIGH(); 265 | twi_delay(twi_dcount + 2); 266 | SCL_HIGH(); 267 | while (SCL_READ() == 0 && (i++) < TWI_CLOCK_STRETCH) 268 | ; // Clock stretching (up to 100us) 269 | bool bit = SDA_READ(); 270 | twi_delay(twi_dcount); 271 | return bit; 272 | } 273 | 274 | static bool twi_write_byte(unsigned char byte) 275 | { 276 | 277 | if (byte == 0x43) 278 | { 279 | // printf("TWB %02x ", (uint32_t) byte); 280 | // do_log = true; 281 | } 282 | unsigned char bit; 283 | for (bit = 0; bit < 8; bit++) 284 | { 285 | twi_write_bit((byte & 0x80) != 0); 286 | byte <<= 1; 287 | } 288 | if (do_log) 289 | { 290 | printf("\n"); 291 | do_log = false; 292 | } 293 | return !twi_read_bit(); //NACK/ACK 294 | } 295 | 296 | static unsigned char twi_read_byte(bool nack) 297 | { 298 | unsigned char byte = 0; 299 | unsigned char bit; 300 | for (bit = 0; bit < 8; bit++) 301 | byte = (byte << 1) | twi_read_bit(); 302 | twi_write_bit(nack); 303 | return byte; 304 | } 305 | 306 | unsigned char twi_writeTo(unsigned char address, unsigned char *buf, unsigned int len, unsigned char sendStop) 307 | { 308 | unsigned int i; 309 | if (!twi_write_start()) 310 | return 4; //line busy 311 | if (!twi_write_byte(((address << 1) | 0) & 0xFF)) 312 | { 313 | if (sendStop) 314 | twi_write_stop(); 315 | return 2; //received NACK on transmit of address 316 | } 317 | for (i = 0; i < len; i++) 318 | { 319 | if (!twi_write_byte(buf[i])) 320 | { 321 | if (sendStop) 322 | twi_write_stop(); 323 | return 3; //received NACK on transmit of data 324 | } 325 | } 326 | if (sendStop) 327 | twi_write_stop(); 328 | i = 0; 329 | while (SDA_READ() == 0 && (i++) < 10) 330 | { 331 | SCL_LOW(); 332 | twi_delay(twi_dcount); 333 | SCL_HIGH(); 334 | twi_delay(twi_dcount); 335 | } 336 | return 0; 337 | } 338 | 339 | unsigned char twi_readFrom(unsigned char address, unsigned char *buf, unsigned int len, unsigned char sendStop) 340 | { 341 | unsigned int i; 342 | if (!twi_write_start()) 343 | return 4; //line busy 344 | if (!twi_write_byte(((address << 1) | 1) & 0xFF)) 345 | { 346 | if (sendStop) 347 | twi_write_stop(); 348 | return 2; //received NACK on transmit of address 349 | } 350 | for (i = 0; i < (len - 1); i++) 351 | buf[i] = twi_read_byte(false); 352 | buf[len - 1] = twi_read_byte(true); 353 | if (sendStop) 354 | twi_write_stop(); 355 | i = 0; 356 | while (SDA_READ() == 0 && (i++) < 10) 357 | { 358 | SCL_LOW(); 359 | twi_delay(twi_dcount); 360 | SCL_HIGH(); 361 | twi_delay(twi_dcount); 362 | } 363 | return 0; 364 | } 365 | -------------------------------------------------------------------------------- /examples/Camera/cam/ov7725.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * OV7725 driver. 7 | * 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include "sccb.h" 13 | #include "ov7725.h" 14 | #include "ov7725_regs.h" 15 | #include 16 | 17 | static const uint8_t default_regs[][2] = { 18 | {COM3, COM3_SWAP_YUV}, 19 | {COM7, COM7_RES_QVGA | COM7_FMT_YUV}, 20 | 21 | {COM4, 0x01}, /* bypass PLL */ 22 | {CLKRC, 0xC0}, /* Res/Bypass pre-scalar */ 23 | 24 | // QVGA Window Size 25 | {HSTART, 0x3F}, 26 | {HSIZE, 0x50}, 27 | {VSTART, 0x03}, 28 | {VSIZE, 0x78}, 29 | {HREF, 0x00}, 30 | 31 | // Scale down to QVGA Resolution 32 | {HOUTSIZE, 0x50}, 33 | {VOUTSIZE, 0x78}, 34 | 35 | {COM12, 0x03}, 36 | {EXHCH, 0x00}, 37 | {TGT_B, 0x7F}, 38 | {FIXGAIN, 0x09}, 39 | {AWB_CTRL0, 0xE0}, 40 | {DSP_CTRL1, 0xFF}, 41 | 42 | {DSP_CTRL2, DSP_CTRL2_VDCW_EN | DSP_CTRL2_HDCW_EN | DSP_CTRL2_HZOOM_EN | DSP_CTRL2_VZOOM_EN}, 43 | 44 | {DSP_CTRL3, 0x00}, 45 | {DSP_CTRL4, 0x00}, 46 | {DSPAUTO, 0xFF}, 47 | 48 | {COM8, 0xF0}, 49 | {COM6, 0xC5}, 50 | {COM9, 0x11}, 51 | {COM10, COM10_VSYNC_NEG | COM10_PCLK_MASK}, //Invert VSYNC and MASK PCLK 52 | {BDBASE, 0x7F}, 53 | {DBSTEP, 0x03}, 54 | {AEW, 0x96}, 55 | {AEB, 0x64}, 56 | {VPT, 0xA1}, 57 | {EXHCL, 0x00}, 58 | {AWB_CTRL3, 0xAA}, 59 | {COM8, 0xFF}, 60 | 61 | //Gamma 62 | {GAM1, 0x0C}, 63 | {GAM2, 0x16}, 64 | {GAM3, 0x2A}, 65 | {GAM4, 0x4E}, 66 | {GAM5, 0x61}, 67 | {GAM6, 0x6F}, 68 | {GAM7, 0x7B}, 69 | {GAM8, 0x86}, 70 | {GAM9, 0x8E}, 71 | {GAM10, 0x97}, 72 | {GAM11, 0xA4}, 73 | {GAM12, 0xAF}, 74 | {GAM13, 0xC5}, 75 | {GAM14, 0xD7}, 76 | {GAM15, 0xE8}, 77 | 78 | {SLOP, 0x20}, 79 | {EDGE1, 0x05}, 80 | {EDGE2, 0x03}, 81 | {EDGE3, 0x00}, 82 | {DNSOFF, 0x01}, 83 | 84 | {MTX1, 0xB0}, 85 | {MTX2, 0x9D}, 86 | {MTX3, 0x13}, 87 | {MTX4, 0x16}, 88 | {MTX5, 0x7B}, 89 | {MTX6, 0x91}, 90 | {MTX_CTRL, 0x1E}, 91 | 92 | {BRIGHTNESS, 0x08}, 93 | {CONTRAST, 0x30}, 94 | {UVADJ0, 0x81}, 95 | {SDE, (SDE_CONT_BRIGHT_EN | SDE_SATURATION_EN)}, 96 | 97 | // For 30 fps/60Hz 98 | {DM_LNL, 0x00}, 99 | {DM_LNH, 0x00}, 100 | {BDBASE, 0x7F}, 101 | {DBSTEP, 0x03}, 102 | 103 | // Lens Correction, should be tuned with real camera module 104 | {LC_RADI, 0x10}, 105 | {LC_COEF, 0x10}, 106 | {LC_COEFB, 0x14}, 107 | {LC_COEFR, 0x17}, 108 | {LC_CTR, 0x05}, 109 | {COM5, 0xF5}, //0x65 110 | 111 | {0x00, 0x00}, 112 | }; 113 | 114 | 115 | static int reset(sensor_t *sensor) 116 | { 117 | int i=0; 118 | const uint8_t (*regs)[2]; 119 | 120 | // Reset all registers 121 | SCCB_Write(sensor->slv_addr, COM7, COM7_RESET); 122 | 123 | // Delay 10 ms 124 | systick_sleep(10); 125 | 126 | // Write default regsiters 127 | for (i=0, regs = default_regs; regs[i][0]; i++) { 128 | SCCB_Write(sensor->slv_addr, regs[i][0], regs[i][1]); 129 | } 130 | 131 | // Delay 132 | systick_sleep(30); 133 | 134 | return 0; 135 | } 136 | 137 | 138 | static int set_pixformat(sensor_t *sensor, pixformat_t pixformat) 139 | { 140 | int ret=0; 141 | // Read register COM7 142 | uint8_t reg = SCCB_Read(sensor->slv_addr, COM7); 143 | 144 | switch (pixformat) { 145 | case PIXFORMAT_RGB565: 146 | reg = COM7_SET_FMT(reg, COM7_FMT_RGB) | COM7_FMT_RGB565; 147 | break; 148 | case PIXFORMAT_YUV422: 149 | case PIXFORMAT_GRAYSCALE: 150 | reg = COM7_SET_FMT(reg, COM7_FMT_YUV); 151 | break; 152 | default: 153 | return -1; 154 | } 155 | 156 | // Write back register COM7 157 | ret = SCCB_Write(sensor->slv_addr, COM7, reg); 158 | 159 | // Delay 160 | systick_sleep(30); 161 | 162 | return ret; 163 | } 164 | 165 | static int set_framesize(sensor_t *sensor, framesize_t framesize) 166 | { 167 | int ret=0; 168 | uint16_t w = resolution[framesize][0]; 169 | uint16_t h = resolution[framesize][1]; 170 | 171 | // Write MSBs 172 | ret |= SCCB_Write(sensor->slv_addr, HOUTSIZE, w>>2); 173 | ret |= SCCB_Write(sensor->slv_addr, VOUTSIZE, h>>1); 174 | 175 | // Write LSBs 176 | ret |= SCCB_Write(sensor->slv_addr, EXHCH, ((w&0x3) | ((h&0x1) << 2))); 177 | 178 | if (framesize < FRAMESIZE_VGA) { 179 | // Enable auto-scaling/zooming factors 180 | ret |= SCCB_Write(sensor->slv_addr, DSPAUTO, 0xFF); 181 | } else { 182 | // Disable auto-scaling/zooming factors 183 | ret |= SCCB_Write(sensor->slv_addr, DSPAUTO, 0xF3); 184 | 185 | // Clear auto-scaling/zooming factors 186 | ret |= SCCB_Write(sensor->slv_addr, SCAL0, 0x00); 187 | ret |= SCCB_Write(sensor->slv_addr, SCAL1, 0x00); 188 | ret |= SCCB_Write(sensor->slv_addr, SCAL2, 0x00); 189 | } 190 | 191 | // Delay 192 | systick_sleep(30); 193 | 194 | if (ret == 0) { 195 | sensor->framesize = framesize; 196 | } 197 | 198 | return ret; 199 | } 200 | 201 | static int set_colorbar(sensor_t *sensor, int enable) 202 | { 203 | int ret=0; 204 | uint8_t reg; 205 | 206 | // Read reg COM3 207 | reg = SCCB_Read(sensor->slv_addr, COM3); 208 | // Enable colorbar test pattern output 209 | reg = COM3_SET_CBAR(reg, enable); 210 | // Write back COM3 211 | ret |= SCCB_Write(sensor->slv_addr, COM3, reg); 212 | 213 | // Read reg DSP_CTRL3 214 | reg = SCCB_Read(sensor->slv_addr, DSP_CTRL3); 215 | // Enable DSP colorbar output 216 | reg = DSP_CTRL3_SET_CBAR(reg, enable); 217 | // Write back DSP_CTRL3 218 | ret |= SCCB_Write(sensor->slv_addr, DSP_CTRL3, reg); 219 | 220 | return ret; 221 | } 222 | 223 | static int set_whitebal(sensor_t *sensor, int enable) 224 | { 225 | // Read register COM8 226 | uint8_t reg = SCCB_Read(sensor->slv_addr, COM8); 227 | 228 | // Set white bal on/off 229 | reg = COM8_SET_AWB(reg, enable); 230 | 231 | // Write back register COM8 232 | return SCCB_Write(sensor->slv_addr, COM8, reg); 233 | } 234 | 235 | static int set_gain_ctrl(sensor_t *sensor, int enable) 236 | { 237 | // Read register COM8 238 | uint8_t reg = SCCB_Read(sensor->slv_addr, COM8); 239 | 240 | // Set white bal on/off 241 | reg = COM8_SET_AGC(reg, enable); 242 | 243 | // Write back register COM8 244 | return SCCB_Write(sensor->slv_addr, COM8, reg); 245 | } 246 | 247 | static int set_exposure_ctrl(sensor_t *sensor, int enable) 248 | { 249 | // Read register COM8 250 | uint8_t reg = SCCB_Read(sensor->slv_addr, COM8); 251 | 252 | // Set white bal on/off 253 | reg = COM8_SET_AEC(reg, enable); 254 | 255 | // Write back register COM8 256 | return SCCB_Write(sensor->slv_addr, COM8, reg); 257 | } 258 | 259 | static int set_hmirror(sensor_t *sensor, int enable) 260 | { 261 | // Read register COM3 262 | uint8_t reg = SCCB_Read(sensor->slv_addr, COM3); 263 | 264 | // Set mirror on/off 265 | reg = COM3_SET_MIRROR(reg, enable); 266 | 267 | // Write back register COM3 268 | return SCCB_Write(sensor->slv_addr, COM3, reg); 269 | } 270 | 271 | static int set_vflip(sensor_t *sensor, int enable) 272 | { 273 | // Read register COM3 274 | uint8_t reg = SCCB_Read(sensor->slv_addr, COM3); 275 | 276 | // Set mirror on/off 277 | reg = COM3_SET_FLIP(reg, enable); 278 | 279 | // Write back register COM3 280 | return SCCB_Write(sensor->slv_addr, COM3, reg); 281 | } 282 | 283 | int ov7725_init(sensor_t *sensor) 284 | { 285 | // Set function pointers 286 | sensor->reset = reset; 287 | sensor->set_pixformat = set_pixformat; 288 | sensor->set_framesize = set_framesize; 289 | sensor->set_colorbar = set_colorbar; 290 | sensor->set_whitebal = set_whitebal; 291 | sensor->set_gain_ctrl = set_gain_ctrl; 292 | sensor->set_exposure_ctrl = set_exposure_ctrl; 293 | sensor->set_hmirror = set_hmirror; 294 | sensor->set_vflip = set_vflip; 295 | 296 | // Retrieve sensor's signature 297 | sensor->id.MIDH = SCCB_Read(sensor->slv_addr, REG_MIDH); 298 | sensor->id.MIDL = SCCB_Read(sensor->slv_addr, REG_MIDL); 299 | sensor->id.PID = SCCB_Read(sensor->slv_addr, REG_PID); 300 | sensor->id.VER = SCCB_Read(sensor->slv_addr, REG_VER); 301 | 302 | // Set sensor flags 303 | SENSOR_HW_FLAGS_SET(sensor, SENSOR_HW_FLAGS_VSYNC, 1); 304 | SENSOR_HW_FLAGS_SET(sensor, SENSOR_HW_FLAGS_HSYNC, 0); 305 | SENSOR_HW_FLAGS_SET(sensor, SENSOR_HW_FLAGS_PIXCK, 1); 306 | SENSOR_HW_FLAGS_SET(sensor, SENSOR_HW_FLAGS_FSYNC, 1); 307 | SENSOR_HW_FLAGS_SET(sensor, SENSOR_HW_FLAGS_JPEGE, 0); 308 | 309 | return 0; 310 | } 311 | -------------------------------------------------------------------------------- /src/ESP_Line_Notify_Const.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP_LINE_NOTIFY_CONST_H 2 | #define ESP_LINE_NOTIFY_CONST_H 3 | 4 | #include 5 | #include "FS_Config.h" 6 | 7 | #include "wcs/ESP_Line_Notify_Clients.h" 8 | 9 | enum esp_line_notify_multipart_header_type 10 | { 11 | esp_line_notify_multipart_header_type_undefined, 12 | esp_line_notify_multipart_header_type_message, 13 | esp_line_notify_multipart_header_type_sticker_package_id, 14 | esp_line_notify_multipart_header_type_sticker_id, 15 | esp_line_notify_multipart_header_type_image_thumbnail, 16 | esp_line_notify_multipart_header_type_image_full_size, 17 | esp_line_notify_multipart_header_type_notification_disabled 18 | 19 | }; 20 | 21 | typedef enum esp_line_notify_sending_status 22 | { 23 | LineNotify_Sending_None, 24 | LineNotify_Sending_Begin, 25 | LineNotify_Sending_In_Progress, 26 | LineNotify_Sending_Upload, 27 | LineNotify_Sending_Error, 28 | LineNotify_Sending_Success 29 | 30 | } LineNotify_Sending_Status; 31 | 32 | typedef enum esp_line_notify_storage_type 33 | { 34 | LineNotify_Storage_Type_Undefined, 35 | LineNotify_Storage_Type_Flash, 36 | LineNotify_Storage_Type_SD 37 | 38 | } LineNotify_Storage_Type; 39 | 40 | struct esp_line_notify_sd_config_info_t 41 | { 42 | int sck = -1; 43 | int miso = -1; 44 | int mosi = -1; 45 | int ss = -1; 46 | }; 47 | 48 | struct esp_line_notify_file_info_t 49 | { 50 | MB_String path; 51 | MB_String name; 52 | LineNotify_Storage_Type storage_type = LineNotify_Storage_Type_Undefined; 53 | }; 54 | 55 | struct esp_line_notify_blob_data_info_t 56 | { 57 | const uint8_t *blob = nullptr; 58 | size_t size = 0; 59 | MB_String file_name; 60 | }; 61 | 62 | struct esp_line_notify_gmap_info_t 63 | { 64 | MB_String google_api_key; 65 | MB_String center; 66 | MB_String size = "640x640"; 67 | MB_String map_type = "roadmap"; 68 | size_t zoom = 13; 69 | MB_String markers; 70 | }; 71 | 72 | struct esp_line_notify_image_info_t 73 | { 74 | struct esp_line_notify_blob_data_info_t data; 75 | struct esp_line_notify_file_info_t file; 76 | MB_String url; 77 | }; 78 | 79 | struct esp_line_notify_sticker_info_t 80 | { 81 | int package_id = -1; 82 | int id = -1; 83 | }; 84 | 85 | struct esp_line_notify_internal_info_t 86 | { 87 | unsigned long default_ts = 1510644967; 88 | uint16_t ntpTimeout = 5000; 89 | float esp_line_notify_gmt_offset = 0; 90 | bool esp_line_notify_clock_rdy = false; 91 | uint16_t esp_line_notify_reconnect_tmo = 10000; 92 | unsigned long esp_line_notify_last_reconnect_millis = 0; 93 | struct esp_line_notify_sd_config_info_t sd_config; 94 | int progress = -1; 95 | size_t upload_len = 0; 96 | }; 97 | 98 | struct esp_line_notify_sending_error_info_t 99 | { 100 | int code = 0; 101 | MB_String message; 102 | }; 103 | 104 | struct esp_line_notify_sending_quota_info_t 105 | { 106 | int limit = 0; 107 | int remaining = 0; 108 | }; 109 | 110 | struct esp_line_notify_sending_quotas_info_t 111 | { 112 | struct esp_line_notify_sending_quota_info_t text; 113 | struct esp_line_notify_sending_quota_info_t image; 114 | size_t reset = 0; 115 | }; 116 | 117 | typedef struct esp_line_notify_sending_result_info_t 118 | { 119 | LineNotify_Sending_Status status; 120 | struct esp_line_notify_sending_error_info_t error; 121 | struct esp_line_notify_sending_quotas_info_t quota; 122 | size_t progress = 0; 123 | MB_String file_name; 124 | 125 | } LineNotifySendingResult; 126 | 127 | struct esp_line_notify_server_response_data_t 128 | { 129 | int httpCode = -1; 130 | int payloadLen = -1; 131 | int contentLen = -1; 132 | int chunkRange = 0; 133 | int payloadOfs = 0; 134 | bool isChunkedEnc = false; 135 | bool noContent = false; 136 | MB_String location; 137 | MB_String contentType; 138 | MB_String connection; 139 | MB_String transferEnc; 140 | struct esp_line_notify_sending_quotas_info_t quota; 141 | }; 142 | 143 | struct esp_line_notify_response_t 144 | { 145 | int code = 0; 146 | }; 147 | 148 | typedef void (*LineNotifyProgressCallback)(LineNotifySendingResult); 149 | 150 | typedef struct esp_line_notify_client_info_t 151 | { 152 | 153 | MB_String token; 154 | MB_String message; 155 | struct esp_line_notify_sticker_info_t sticker; 156 | struct esp_line_notify_image_info_t image; 157 | struct esp_line_notify_gmap_info_t gmap; 158 | struct esp_line_notify_internal_info_t internal; 159 | bool reconnect_wifi = false; 160 | bool notification_disabled = false; 161 | uint16_t response_size = 2048; 162 | ESP_LINE_NOTIFY_TCP_CLIENT *tcpClient = nullptr; 163 | LineNotifyProgressCallback sending_callback = NULL; 164 | struct esp_line_notify_response_t response; 165 | 166 | esp_line_notify_client_info_t() 167 | { 168 | } 169 | 170 | ~esp_line_notify_client_info_t() 171 | { 172 | if (tcpClient) 173 | { 174 | delete tcpClient; 175 | tcpClient = nullptr; 176 | } 177 | } 178 | 179 | void setExternalClient(Client *client) 180 | { 181 | #if defined(ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT) 182 | 183 | if (!tcpClient) 184 | tcpClient = new ESP_LINE_NOTIFY_TCP_CLIENT(); 185 | 186 | tcpClient->setClient(client); 187 | #endif 188 | } 189 | 190 | void setExternalClientCallbacks(ESP_Line_Notify_TCPConnectionRequestCallback tcpConnectionCB, ESP_Line_Notify_NetworkConnectionRequestCallback networkConnectionCB, ESP_Line_Notify_NetworkStatusRequestCallback networkStatusCB) 191 | { 192 | #if defined(ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT) 193 | 194 | if (!tcpClient) 195 | tcpClient = new ESP_LINE_NOTIFY_TCP_CLIENT(); 196 | 197 | if (tcpClient) 198 | { 199 | tcpClient->tcpConnectionRequestCallback(tcpConnectionCB); 200 | 201 | tcpClient->networkConnectionRequestCallback(networkConnectionCB); 202 | 203 | tcpClient->networkStatusRequestCallback(networkStatusCB); 204 | } 205 | #endif 206 | } 207 | 208 | void setNetworkStatus(bool status) 209 | { 210 | #if defined(ESP_LINE_NOTIFY_ENABLE_EXTERNAL_CLIENT) 211 | 212 | if (!tcpClient) 213 | tcpClient = new ESP_LINE_NOTIFY_TCP_CLIENT(); 214 | 215 | if (tcpClient) 216 | tcpClient->setNetworkStatus(status); 217 | #endif 218 | } 219 | 220 | } LineNotifyClient; 221 | 222 | static const char esp_line_notify_str_1[] PROGMEM = "notify-api.line.me"; 223 | static const char esp_line_notify_str_2[] PROGMEM = " "; 224 | static const char esp_line_notify_str_3[] PROGMEM = "ESP32"; 225 | static const char esp_line_notify_str_4[] PROGMEM = "\r\n"; 226 | static const char esp_line_notify_str_5[] PROGMEM = "POST /api/notify HTTP/1.1"; 227 | static const char esp_line_notify_str_6[] PROGMEM = "cache-control: no-cache"; 228 | static const char esp_line_notify_str_7[] PROGMEM = "Authorization: Bearer "; 229 | static const char esp_line_notify_str_8[] PROGMEM = "Content-Type: multipart/form-data; boundary="; 230 | static const char esp_line_notify_str_9[] PROGMEM = "User-Agent: "; 231 | static const char esp_line_notify_str_10[] PROGMEM = "Accept: */*"; 232 | static const char esp_line_notify_str_11[] PROGMEM = "Host: "; 233 | static const char esp_line_notify_str_12[] PROGMEM = "accept-encoding: gzip, deflate"; 234 | static const char esp_line_notify_str_13[] PROGMEM = "Connection: close"; 235 | static const char esp_line_notify_str_14[] PROGMEM = "content-length: "; 236 | static const char esp_line_notify_str_15[] PROGMEM = "/api/notify"; 237 | static const char esp_line_notify_str_16[] PROGMEM = "Content-Disposition: form-data; name=\"imageFile\"; filename=\""; 238 | static const char esp_line_notify_str_17[] PROGMEM = "Content-Type: "; 239 | static const char esp_line_notify_str_18[] PROGMEM = "Content-Disposition: form-data; name=\""; 240 | static const char esp_line_notify_str_19[] PROGMEM = "message"; 241 | static const char esp_line_notify_str_20[] PROGMEM = "stickerPackageId"; 242 | static const char esp_line_notify_str_21[] PROGMEM = "stickerId"; 243 | static const char esp_line_notify_str_22[] PROGMEM = "imageThumbnail"; 244 | static const char esp_line_notify_str_23[] PROGMEM = "imageFullsize"; 245 | static const char esp_line_notify_str_24[] PROGMEM = "--"; 246 | static const char esp_line_notify_str_25[] PROGMEM = "\""; 247 | static const char esp_line_notify_str_26[] PROGMEM = ".jpg"; 248 | static const char esp_line_notify_str_27[] PROGMEM = ".jpeg"; 249 | static const char esp_line_notify_str_28[] PROGMEM = "image/jpeg"; 250 | static const char esp_line_notify_str_29[] PROGMEM = ".gif"; 251 | static const char esp_line_notify_str_30[] PROGMEM = "image/gif"; 252 | static const char esp_line_notify_str_31[] PROGMEM = ".png"; 253 | static const char esp_line_notify_str_32[] PROGMEM = "image/png"; 254 | static const char esp_line_notify_str_33[] PROGMEM = ".bmp"; 255 | static const char esp_line_notify_str_34[] PROGMEM = "image/bmp"; 256 | static const char esp_line_notify_str_35[] PROGMEM = "."; 257 | static const char esp_line_notify_str_36[] PROGMEM = "HTTP/1.1 "; 258 | static const char esp_line_notify_str_37[] PROGMEM = " "; 259 | static const char esp_line_notify_str_38[] PROGMEM = "X-RateLimit-Limit: "; 260 | static const char esp_line_notify_str_39[] PROGMEM = "X-RateLimit-ImageLimit: "; 261 | static const char esp_line_notify_str_40[] PROGMEM = "X-RateLimit-Remaining: "; 262 | static const char esp_line_notify_str_41[] PROGMEM = "X-RateLimit-ImageRemaining: "; 263 | static const char esp_line_notify_str_42[] PROGMEM = "X-RateLimit-Reset: "; 264 | static const char esp_line_notify_str_43[] PROGMEM = "/esp"; 265 | static const char esp_line_notify_str_44[] PROGMEM = "read timed out"; 266 | static const char esp_line_notify_str_45[] PROGMEM = "status"; 267 | static const char esp_line_notify_str_46[] PROGMEM = "Connection: "; 268 | static const char esp_line_notify_str_47[] PROGMEM = "Content-Length: "; 269 | static const char esp_line_notify_str_48[] PROGMEM = ";"; 270 | static const char esp_line_notify_str_49[] PROGMEM = "Location: "; 271 | static const char esp_line_notify_str_50[] PROGMEM = "Transfer-Encoding: "; 272 | static const char esp_line_notify_str_51[] PROGMEM = "chunked"; 273 | static const char esp_line_notify_str_52[] PROGMEM = "pool.ntp.org"; 274 | static const char esp_line_notify_str_53[] PROGMEM = "time.nist.gov"; 275 | static const char esp_line_notify_str_54[] PROGMEM = "=_abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 276 | static const char esp_line_notify_str_55[] PROGMEM = "File I/O error"; 277 | static const char esp_line_notify_str_56[] PROGMEM = "connection closed"; 278 | static const char esp_line_notify_str_57[] PROGMEM = "notificationDisabled"; 279 | static const char esp_line_notify_str_58[] PROGMEM = "true"; 280 | static const char esp_line_notify_str_59[] PROGMEM = "false"; 281 | static const char esp_line_notify_str_60[] PROGMEM = "https://maps.googleapis.com/maps/api/staticmap?key="; 282 | static const char esp_line_notify_str_61[] PROGMEM = "https://www.google.com/maps/@?api=1&map_action=map¢er="; 283 | static const char esp_line_notify_str_62[] PROGMEM = "¢er="; 284 | static const char esp_line_notify_str_63[] PROGMEM = "&zoom="; 285 | static const char esp_line_notify_str_64[] PROGMEM = "&maptype="; 286 | static const char esp_line_notify_str_65[] PROGMEM = "&size="; 287 | static const char esp_line_notify_str_66[] PROGMEM = "&markers="; 288 | static const char esp_line_notify_str_67[] PROGMEM = "&basemap="; 289 | static const char esp_line_notify_str_68[] PROGMEM = "\n\n"; 290 | 291 | #if defined(MBFS_FLASH_FS) || defined(MBFS_SD_FS) 292 | static const char esp_line_notify_str_69[] PROGMEM = "Flash Storage is not ready."; 293 | static const char esp_line_notify_str_70[] PROGMEM = "SD Storage is not ready."; 294 | static const char esp_line_notify_str_71[] PROGMEM = "File is still opened."; 295 | static const char esp_line_notify_str_72[] PROGMEM = "File not found."; 296 | #endif 297 | 298 | static const char esp_line_notify_str_73[] PROGMEM = "connection refused"; 299 | static const char esp_line_notify_str_74[] PROGMEM = "send request failed"; 300 | static const char esp_line_notify_str_75[] PROGMEM = "not connected"; 301 | static const char esp_line_notify_str_76[] PROGMEM = "connection lost"; 302 | static const char esp_line_notify_str_77[] PROGMEM = "no HTTP server"; 303 | static const char esp_line_notify_str_78[] PROGMEM = "bad request"; 304 | static const char esp_line_notify_str_79[] PROGMEM = "non-authoriative information"; 305 | static const char esp_line_notify_str_80[] PROGMEM = "no content"; 306 | static const char esp_line_notify_str_81[] PROGMEM = "moved permanently"; 307 | static const char esp_line_notify_str_82[] PROGMEM = "use proxy"; 308 | static const char esp_line_notify_str_83[] PROGMEM = "temporary redirect"; 309 | static const char esp_line_notify_str_84[] PROGMEM = "permanent redirect"; 310 | static const char esp_line_notify_str_85[] PROGMEM = "unauthorized"; 311 | static const char esp_line_notify_str_86[] PROGMEM = "forbidden"; 312 | static const char esp_line_notify_str_87[] PROGMEM = "not found"; 313 | static const char esp_line_notify_str_88[] PROGMEM = "method not allow"; 314 | static const char esp_line_notify_str_89[] PROGMEM = "not acceptable"; 315 | static const char esp_line_notify_str_90[] PROGMEM = "proxy authentication required"; 316 | static const char esp_line_notify_str_91[] PROGMEM = "request timed out"; 317 | static const char esp_line_notify_str_92[] PROGMEM = "length required"; 318 | static const char esp_line_notify_str_93[] PROGMEM = "too many requests"; 319 | static const char esp_line_notify_str_94[] PROGMEM = "request header fields too larg"; 320 | static const char esp_line_notify_str_95[] PROGMEM = "internal server error"; 321 | static const char esp_line_notify_str_96[] PROGMEM = "bad gateway"; 322 | static const char esp_line_notify_str_97[] PROGMEM = "service unavailable"; 323 | static const char esp_line_notify_str_98[] PROGMEM = "gateway timeout"; 324 | static const char esp_line_notify_str_99[] PROGMEM = "http version not support"; 325 | static const char esp_line_notify_str_100[] PROGMEM = "network authentication required"; 326 | static const char esp_line_notify_str_101[] PROGMEM = "precondition failed"; 327 | static const char esp_line_notify_str_102[] PROGMEM = "response payload read timed out"; 328 | static const char esp_line_notify_str_103[] PROGMEM = "Response read failed"; 329 | static const char esp_line_notify_str_104[] PROGMEM = "Custom Client is not yet enabled"; 330 | static const char esp_line_notify_str_105[] PROGMEM = "Client is not yet initialized"; 331 | static const char esp_line_notify_str_106[] PROGMEM = "undefined"; 332 | #endif -------------------------------------------------------------------------------- /src/json/MB_JSON/MB_JSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | MB_JSON.h v1.0.1 based on the modified version of cJSON.h v1.7.14 (Sept 3, 2020) 3 | 4 | All original static cJSON functions and static variables will be prefixed with MB_JSON_. 5 | 6 | Created December 20, 2021 7 | 8 | Copyright (c) 2023 Mobizt (K. Suwatchai) 9 | 10 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy 13 | of this software and associated documentation files (the "Software"), to deal 14 | in the Software without restriction, including without limitation the rights 15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | copies of the Software, and to permit persons to whom the Software is 17 | furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 | THE SOFTWARE. 29 | */ 30 | 31 | #ifndef MB_JSON_H 32 | #define MB_JSON_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" 36 | { 37 | #endif 38 | 39 | #if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) 40 | #define __WINDOWS__ 41 | #endif 42 | 43 | #ifdef __WINDOWS__ 44 | 45 | /* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options: 46 | 47 | MB_JSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols 48 | MB_JSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) 49 | MB_JSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol 50 | 51 | For *nix builds that support visibility attribute, you can define similar behavior by 52 | 53 | setting default visibility to hidden by adding 54 | -fvisibility=hidden (for gcc) 55 | or 56 | -xldscope=hidden (for sun cc) 57 | to CFLAGS 58 | 59 | then using the MB_JSON_API_VISIBILITY flag to "export" the same symbols the way MB_JSON_EXPORT_SYMBOLS does 60 | 61 | */ 62 | 63 | #define MB_JSON_CDECL __cdecl 64 | #define MB_JSON_STDCALL __stdcall 65 | 66 | /* export symbols by default, this is necessary for copy pasting the C and header file */ 67 | #if !defined(MB_JSON_HIDE_SYMBOLS) && !defined(MB_JSON_IMPORT_SYMBOLS) && !defined(MB_JSON_EXPORT_SYMBOLS) 68 | #define MB_JSON_EXPORT_SYMBOLS 69 | #endif 70 | 71 | #if defined(MB_JSON_HIDE_SYMBOLS) 72 | #define MB_JSON_PUBLIC(type) type MB_JSON_STDCALL 73 | #elif defined(MB_JSON_EXPORT_SYMBOLS) 74 | #define MB_JSON_PUBLIC(type) __declspec(dllexport) type MB_JSON_STDCALL 75 | #elif defined(MB_JSON_IMPORT_SYMBOLS) 76 | #define MB_JSON_PUBLIC(type) __declspec(dllimport) type MB_JSON_STDCALL 77 | #endif 78 | #else /* !__WINDOWS__ */ 79 | #define MB_JSON_CDECL 80 | #define MB_JSON_STDCALL 81 | 82 | #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(MB_JSON_API_VISIBILITY) 83 | #define MB_JSON_PUBLIC(type) __attribute__((visibility("default"))) type 84 | #else 85 | #define MB_JSON_PUBLIC(type) type 86 | #endif 87 | #endif 88 | 89 | /* project version */ 90 | #define MB_JSON_VERSION_MAJOR 1 91 | #define MB_JSON_VERSION_MINOR 7 92 | #define MB_JSON_VERSION_PATCH 14 93 | 94 | #include 95 | 96 | /* MB_JSON Types: */ 97 | #define MB_JSON_Invalid (0) 98 | #define MB_JSON_False (1 << 0) 99 | #define MB_JSON_True (1 << 1) 100 | #define MB_JSON_NULL (1 << 2) 101 | #define MB_JSON_Number (1 << 3) 102 | #define MB_JSON_String (1 << 4) 103 | #define MB_JSON_Array (1 << 5) 104 | #define MB_JSON_Object (1 << 6) 105 | #define MB_JSON_Raw (1 << 7) /* raw json */ 106 | 107 | #define MB_JSON_IsReference 256 108 | #define MB_JSON_StringIsConst 512 109 | 110 | /* The MB_JSON structure: */ 111 | typedef struct MB_JSON 112 | { 113 | /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ 114 | struct MB_JSON *next; 115 | struct MB_JSON *prev; 116 | /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ 117 | struct MB_JSON *child; 118 | 119 | /* The type of the item, as above. */ 120 | int type; 121 | 122 | /* The item's string, if type==MB_JSON_String and type == MB_JSON_Raw */ 123 | char *valuestring; 124 | /* writing to valueint is DEPRECATED, use MB_JSON_SetNumberValue instead */ 125 | int valueint; 126 | /* The item's number, if type==MB_JSON_Number */ 127 | double valuedouble; 128 | 129 | /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ 130 | char *string; 131 | } MB_JSON; 132 | 133 | typedef struct MB_JSON_Hooks 134 | { 135 | /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ 136 | void *(MB_JSON_CDECL *malloc_fn)(size_t sz); 137 | void (MB_JSON_CDECL *free_fn)(void *ptr); 138 | void *(MB_JSON_CDECL *realloc_fn)(void *ptr, size_t sz); 139 | } MB_JSON_Hooks; 140 | 141 | typedef int MB_JSON_bool; 142 | 143 | /* Limits how deeply nested arrays/objects can be before MB_JSON rejects to parse them. 144 | * This is to prevent stack overflows. */ 145 | #ifndef MB_JSON_NESTING_LIMIT 146 | #define MB_JSON_NESTING_LIMIT 1000 147 | #endif 148 | 149 | /* returns the version of MB_JSON as a string */ 150 | MB_JSON_PUBLIC(const char*) MB_JSON_Version(void); 151 | 152 | /* Supply malloc, realloc and free functions to MB_JSON */ 153 | MB_JSON_PUBLIC(void) MB_JSON_InitHooks(MB_JSON_Hooks* hooks); 154 | 155 | size_t MB_JSON_SerializedBufferLength(const MB_JSON *const item, MB_JSON_bool format); 156 | 157 | /* Memory Management: the caller is always responsible to free the results from all variants of MB_JSON_Parse (with MB_JSON_Delete) and MB_JSON_Print (with stdlib free, MB_JSON_Hooks.free_fn, or MB_JSON_free as appropriate). The exception is MB_JSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ 158 | /* Supply a block of JSON, and this returns a MB_JSON object you can interrogate. */ 159 | MB_JSON_PUBLIC(MB_JSON *) 160 | MB_JSON_Parse(const char *value); 161 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_ParseWithLength(const char *value, size_t buffer_length); 162 | /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ 163 | /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match MB_JSON_GetErrorPtr(). */ 164 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_ParseWithOpts(const char *value, const char **return_parse_end, MB_JSON_bool require_null_terminated); 165 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, MB_JSON_bool require_null_terminated); 166 | 167 | /* Render a MB_JSON entity to text for transfer/storage. */ 168 | MB_JSON_PUBLIC(char *) MB_JSON_Print(const MB_JSON *item); 169 | /* Render a MB_JSON entity to text for transfer/storage without any formatting. */ 170 | MB_JSON_PUBLIC(char *) MB_JSON_PrintUnformatted(const MB_JSON *item); 171 | /* Render a MB_JSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ 172 | MB_JSON_PUBLIC(char *) MB_JSON_PrintBuffered(const MB_JSON *item, int prebuffer, MB_JSON_bool fmt); 173 | /* Render a MB_JSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ 174 | /* NOTE: MB_JSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ 175 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_PrintPreallocated(MB_JSON *item, char *buffer, const int length, const MB_JSON_bool format); 176 | /* Delete a MB_JSON entity and all subentities. */ 177 | MB_JSON_PUBLIC(void) MB_JSON_Delete(MB_JSON *item); 178 | 179 | /* Returns the number of items in an array (or object). */ 180 | MB_JSON_PUBLIC(int) MB_JSON_GetArraySize(const MB_JSON *array); 181 | /* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ 182 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_GetArrayItem(const MB_JSON *array, int index); 183 | /* Get item "string" from object. Case insensitive. */ 184 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_GetObjectItem(const MB_JSON * const object, const char * const string); 185 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_GetObjectItemCaseSensitive(const MB_JSON * const object, const char * const string); 186 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_HasObjectItem(const MB_JSON *object, const char *string); 187 | /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when MB_JSON_Parse() returns 0. 0 when MB_JSON_Parse() succeeds. */ 188 | MB_JSON_PUBLIC(const char *) MB_JSON_GetErrorPtr(void); 189 | 190 | /* Check item type and return its value */ 191 | MB_JSON_PUBLIC(char *) MB_JSON_GetStringValue(const MB_JSON * const item); 192 | MB_JSON_PUBLIC(double) MB_JSON_GetNumberValue(const MB_JSON * const item); 193 | 194 | /* These functions check the type of an item */ 195 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsInvalid(const MB_JSON * const item); 196 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsFalse(const MB_JSON * const item); 197 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsTrue(const MB_JSON * const item); 198 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsBool(const MB_JSON * const item); 199 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsNull(const MB_JSON * const item); 200 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsNumber(const MB_JSON * const item); 201 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsString(const MB_JSON * const item); 202 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsArray(const MB_JSON * const item); 203 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsObject(const MB_JSON * const item); 204 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_IsRaw(const MB_JSON * const item); 205 | 206 | /* These calls create a MB_JSON item of the appropriate type. */ 207 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateNull(void); 208 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateTrue(void); 209 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateFalse(void); 210 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateBool(MB_JSON_bool boolean); 211 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateNumber(double num); 212 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateString(const char *string); 213 | /* raw json */ 214 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateRaw(const char *raw); 215 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateArray(void); 216 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateObject(void); 217 | 218 | /* Create a string where valuestring references a string so 219 | * it will not be freed by MB_JSON_Delete */ 220 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateStringReference(const char *string); 221 | /* Create an object/array that only references it's elements so 222 | * they will not be freed by MB_JSON_Delete */ 223 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateObjectReference(const MB_JSON *child); 224 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateArrayReference(const MB_JSON *child); 225 | 226 | /* These utilities create an Array of count items. 227 | * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/ 228 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateIntArray(const int *numbers, int count); 229 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateFloatArray(const float *numbers, int count); 230 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateDoubleArray(const double *numbers, int count); 231 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_CreateStringArray(const char *const *strings, int count); 232 | 233 | /* Append item to the specified array/object. */ 234 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_AddItemToArray(MB_JSON *array, MB_JSON *item); 235 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_AddItemToObject(MB_JSON *object, const char *string, MB_JSON *item); 236 | /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the MB_JSON object. 237 | * WARNING: When this function was used, make sure to always check that (item->type & MB_JSON_StringIsConst) is zero before 238 | * writing to `item->string` */ 239 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_AddItemToObjectCS(MB_JSON *object, const char *string, MB_JSON *item); 240 | /* Append reference to item to the specified array/object. Use this when you want to add an existing MB_JSON to a new MB_JSON, but don't want to corrupt your existing MB_JSON. */ 241 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_AddItemReferenceToArray(MB_JSON *array, MB_JSON *item); 242 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_AddItemReferenceToObject(MB_JSON *object, const char *string, MB_JSON *item); 243 | 244 | /* Remove/Detach items from Arrays/Objects. */ 245 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_DetachItemViaPointer(MB_JSON *parent, MB_JSON * const item); 246 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_DetachItemFromArray(MB_JSON *array, int which); 247 | MB_JSON_PUBLIC(void) MB_JSON_DeleteItemFromArray(MB_JSON *array, int which); 248 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_DetachItemFromObject(MB_JSON *object, const char *string); 249 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_DetachItemFromObjectCaseSensitive(MB_JSON *object, const char *string); 250 | MB_JSON_PUBLIC(void) MB_JSON_DeleteItemFromObject(MB_JSON *object, const char *string); 251 | MB_JSON_PUBLIC(void) MB_JSON_DeleteItemFromObjectCaseSensitive(MB_JSON *object, const char *string); 252 | 253 | /* Update array items. */ 254 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_InsertItemInArray(MB_JSON *array, int which, MB_JSON *newitem); /* Shifts pre-existing items to the right. */ 255 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_ReplaceItemViaPointer(MB_JSON * const parent, MB_JSON * const item, MB_JSON * replacement); 256 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_ReplaceItemInArray(MB_JSON *array, int which, MB_JSON *newitem); 257 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_ReplaceItemInObject(MB_JSON *object,const char *string,MB_JSON *newitem); 258 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_ReplaceItemInObjectCaseSensitive(MB_JSON *object,const char *string,MB_JSON *newitem); 259 | 260 | /* Duplicate a MB_JSON item */ 261 | MB_JSON_PUBLIC(MB_JSON *) MB_JSON_Duplicate(const MB_JSON *item, MB_JSON_bool recurse); 262 | /* Duplicate will create a new, identical MB_JSON item to the one you pass, in new memory that will 263 | * need to be released. With recurse!=0, it will duplicate any children connected to the item. 264 | * The item->next and ->prev pointers are always zero on return from Duplicate. */ 265 | /* Recursively compare two MB_JSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. 266 | * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ 267 | MB_JSON_PUBLIC(MB_JSON_bool) MB_JSON_Compare(const MB_JSON * const a, const MB_JSON * const b, const MB_JSON_bool case_sensitive); 268 | 269 | /* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. 270 | * The input pointer json cannot point to a read-only address area, such as a string constant, 271 | * but should point to a readable and writable adress area. */ 272 | MB_JSON_PUBLIC(void) MB_JSON_Minify(char *json); 273 | 274 | /* Helper functions for creating and adding items to an object at the same time. 275 | * They return the added item or NULL on failure. */ 276 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddNullToObject(MB_JSON * const object, const char * const name); 277 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddTrueToObject(MB_JSON * const object, const char * const name); 278 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddFalseToObject(MB_JSON * const object, const char * const name); 279 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddBoolToObject(MB_JSON * const object, const char * const name, const MB_JSON_bool boolean); 280 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddNumberToObject(MB_JSON * const object, const char * const name, const double number); 281 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddStringToObject(MB_JSON * const object, const char * const name, const char * const string); 282 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddRawToObject(MB_JSON * const object, const char * const name, const char * const raw); 283 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddObjectToObject(MB_JSON * const object, const char * const name); 284 | MB_JSON_PUBLIC(MB_JSON*) MB_JSON_AddArrayToObject(MB_JSON * const object, const char * const name); 285 | 286 | /* When assigning an integer value, it needs to be propagated to valuedouble too. */ 287 | #define MB_JSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) 288 | /* helper for the MB_JSON_SetNumberValue macro */ 289 | MB_JSON_PUBLIC(double) MB_JSON_SetNumberHelper(MB_JSON *object, double number); 290 | #define MB_JSON_SetNumberValue(object, number) ((object != NULL) ? MB_JSON_SetNumberHelper(object, (double)number) : (number)) 291 | /* Change the valuestring of a MB_JSON_String object, only takes effect when type of object is MB_JSON_String */ 292 | MB_JSON_PUBLIC(char*) MB_JSON_SetValuestring(MB_JSON *object, const char *valuestring); 293 | 294 | /* Macro for iterating over an array or object */ 295 | #define MB_JSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) 296 | 297 | /* malloc/free objects using the malloc/free functions that have been set with MB_JSON_InitHooks */ 298 | MB_JSON_PUBLIC(void *) MB_JSON_malloc(size_t size); 299 | MB_JSON_PUBLIC(void) MB_JSON_free(void *object); 300 | 301 | #ifdef __cplusplus 302 | } 303 | #endif 304 | 305 | #endif //FBJS_MB_JSON_H 306 | -------------------------------------------------------------------------------- /src/wcs/base/ESP_Line_Notify_TCP_Client_Base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP Line Notify TCP Client base v1.0.0 3 | * 4 | * Created May 6, 2022 5 | * 6 | * The MIT License (MIT) 7 | * Copyright (c) 2022 K. Suwatchai (Mobizt) 8 | * 9 | * 10 | * Permission is hereby granted, free of charge, to any person returning a copy of 11 | * this software and associated documentation files (the "Software"), to deal in 12 | * the Software without restriction, including without limitation the rights to 13 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 14 | * the Software, and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in all 18 | * copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 22 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 23 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 24 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef ESP_Line_Notify_TCP_CLIENT_BASE_H 29 | #define ESP_Line_Notify_TCP_CLIENT_BASE_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "./mbfs/MB_FS.h" 36 | #include "ESP_Line_Notify_Net.h" 37 | 38 | 39 | typedef void (*ESP_Line_Notify_TCPConnectionRequestCallback)(const char *, int); 40 | typedef void (*ESP_Line_Notify_NetworkConnectionRequestCallback)(void); 41 | typedef void (*ESP_Line_Notify_NetworkStatusRequestCallback)(void); 42 | 43 | #include "ESP_Line_Notify_Error.h" 44 | 45 | typedef enum 46 | { 47 | esp_line_notify_cert_type_undefined = -1, 48 | esp_line_notify_cert_type_none = 0, 49 | esp_line_notify_cert_type_data, 50 | esp_line_notify_cert_type_file 51 | 52 | } esp_line_notify_cert_type; 53 | 54 | typedef enum 55 | { 56 | esp_line_notify_tcp_client_type_undefined, 57 | esp_line_notify_tcp_client_type_internal, 58 | esp_line_notify_tcp_client_type_external 59 | 60 | } esp_line_notify_tcp_client_type; 61 | 62 | class ESP_Line_Notify_TCP_Client_Base 63 | { 64 | friend class ESP_Line_Notify; 65 | 66 | public: 67 | ESP_Line_Notify_TCP_Client_Base() 68 | { 69 | certType = esp_line_notify_cert_type_undefined; 70 | }; 71 | virtual ~ESP_Line_Notify_TCP_Client_Base(){}; 72 | 73 | virtual void ethDNSWorkAround(){}; 74 | 75 | virtual bool networkReady() { return false; } 76 | 77 | virtual void networkReconnect(){}; 78 | 79 | virtual void disconnect(){}; 80 | 81 | virtual esp_line_notify_tcp_client_type type() { return esp_line_notify_tcp_client_type_undefined; } 82 | 83 | virtual bool isInitialized() { return false; } 84 | 85 | virtual int hostByName(const char *name, IPAddress &ip) { return 0; } 86 | 87 | int virtual setError(int code) 88 | { 89 | if (!response_code) 90 | return -1000; 91 | 92 | *response_code = code; 93 | return *response_code; 94 | } 95 | 96 | virtual bool begin(const char *host, uint16_t port, int *response_code) 97 | { 98 | 99 | this->host = host; 100 | this->port = port; 101 | this->response_code = response_code; 102 | 103 | return true; 104 | } 105 | 106 | virtual bool connect() 107 | { 108 | 109 | if (!client) 110 | return false; 111 | 112 | if (connected()) 113 | { 114 | flush(); 115 | return true; 116 | } 117 | 118 | client->setTimeout(timeoutMs); 119 | 120 | if (!client->connect(host.c_str(), port)) 121 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 122 | 123 | return connected(); 124 | } 125 | 126 | virtual void stop() 127 | { 128 | if (!client) 129 | return; 130 | 131 | if (connected()) 132 | return client->stop(); 133 | }; 134 | 135 | virtual bool connected() 136 | { 137 | if (client) 138 | { 139 | bool ret = client->connected(); 140 | 141 | if (!ret) 142 | { 143 | setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 144 | client->stop(); 145 | client->flush(); 146 | } 147 | 148 | return ret; 149 | } 150 | 151 | return false; 152 | } 153 | 154 | virtual int write(uint8_t *data, int len) 155 | { 156 | if (!data || !client) 157 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_SEND_REQUEST_FAILED); 158 | 159 | if (len == 0) 160 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_SEND_REQUEST_FAILED); 161 | 162 | // call base or derived connect. 163 | if (!connect()) 164 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 165 | 166 | int toSend = chunkSize; 167 | int sent = 0; 168 | while (sent < len) 169 | { 170 | if (sent + toSend > len) 171 | toSend = len - sent; 172 | 173 | #if defined(ESP8266) 174 | delay(0); 175 | #endif 176 | int res = client->write(data + sent, toSend); 177 | 178 | 179 | 180 | if (res != toSend) 181 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_SEND_REQUEST_FAILED); 182 | 183 | sent += toSend; 184 | } 185 | 186 | setError(ESP_LINE_NOTIFY_ERROR_HTTP_CODE_OK); 187 | 188 | return len; 189 | } 190 | 191 | virtual int send(const char *data, int len = 0) 192 | { 193 | if (len == 0) 194 | len = strlen(data); 195 | return write((uint8_t *)data, len); 196 | } 197 | 198 | virtual int print(const char *data) 199 | { 200 | return send(data); 201 | } 202 | 203 | virtual int print(int data) 204 | { 205 | char *buf = (char *)mbfs->newP(64); 206 | sprintf(buf, (const char *)MBSTRING_FLASH_MCR("%d"), data); 207 | int ret = send(buf); 208 | mbfs->delP(&buf); 209 | return ret; 210 | } 211 | 212 | virtual int println(const char *data) 213 | { 214 | int len = send(data); 215 | if (len < 0) 216 | return len; 217 | int sz = send((const char *)MBSTRING_FLASH_MCR("\r\n")); 218 | if (sz < 0) 219 | return sz; 220 | return len + sz; 221 | } 222 | 223 | virtual int println(int data) 224 | { 225 | char *buf = (char *)mbfs->newP(64); 226 | sprintf(buf, (const char *)MBSTRING_FLASH_MCR("%d\r\n"), data); 227 | int ret = send(buf); 228 | mbfs->delP(&buf); 229 | return ret; 230 | } 231 | 232 | virtual int available() 233 | { 234 | if (!client) 235 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 236 | 237 | return client->available(); 238 | } 239 | 240 | virtual int read() 241 | { 242 | if (!client) 243 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 244 | 245 | int r = client->read(); 246 | 247 | if (r < 0) 248 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_RESPONSE_READ_FAILED); 249 | 250 | return r; 251 | } 252 | 253 | virtual int readBytes(uint8_t *buf, int len) 254 | { 255 | if (!client) 256 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 257 | 258 | int r = client->readBytes(buf, len); 259 | 260 | if (r != len) 261 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_RESPONSE_READ_FAILED); 262 | 263 | setError(ESP_LINE_NOTIFY_ERROR_HTTP_CODE_OK); 264 | 265 | return r; 266 | } 267 | 268 | virtual int readBytes(char *buf, int len) { return readBytes((uint8_t *)buf, len); } 269 | 270 | void baseSetCertType(esp_line_notify_cert_type type) { certType = type; } 271 | 272 | void baseSetTimeout(uint32_t timeoutSec) { timeoutMs = timeoutSec * 1000; } 273 | 274 | int readLine(char *buf, int bufLen) 275 | { 276 | if (!client) 277 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 278 | 279 | int res = -1; 280 | char c = 0; 281 | int idx = 0; 282 | if (!client) 283 | return idx; 284 | while (client->available() && idx <= bufLen) 285 | { 286 | if (!client) 287 | break; 288 | 289 | #if defined(ESP8266) 290 | delay(0); 291 | #endif 292 | res = client->read(); 293 | if (res > -1) 294 | { 295 | c = (char)res; 296 | strcat_c(buf, c); 297 | idx++; 298 | if (c == '\n') 299 | return idx; 300 | } 301 | } 302 | return idx; 303 | } 304 | 305 | int readLine(MB_String &buf) 306 | { 307 | if (!client) 308 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 309 | 310 | int res = -1; 311 | char c = 0; 312 | int idx = 0; 313 | if (!client) 314 | return idx; 315 | while (client->available()) 316 | { 317 | if (!client) 318 | break; 319 | 320 | #if defined(ESP8266) 321 | delay(0); 322 | #endif 323 | res = client->read(); 324 | if (res > -1) 325 | { 326 | c = (char)res; 327 | buf += c; 328 | idx++; 329 | if (c == '\n') 330 | return idx; 331 | } 332 | } 333 | return idx; 334 | } 335 | 336 | int readChunkedData(char *out, int &chunkState, int &chunkedSize, int &dataLen, int bufLen) 337 | { 338 | if (!client) 339 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 340 | 341 | char *tmp = nullptr; 342 | char *buf = nullptr; 343 | int p1 = 0; 344 | int olen = 0; 345 | 346 | if (chunkState == 0) 347 | { 348 | chunkState = 1; 349 | chunkedSize = -1; 350 | dataLen = 0; 351 | buf = (char *)mbfs->newP(bufLen); 352 | int readLen = readLine(buf, bufLen); 353 | if (readLen) 354 | { 355 | p1 = strpos(buf, (const char *)MBSTRING_FLASH_MCR(";"), 0); 356 | if (p1 == -1) 357 | { 358 | p1 = strpos(buf, (const char *)MBSTRING_FLASH_MCR("\r\n"), 0); 359 | } 360 | 361 | if (p1 != -1) 362 | { 363 | tmp = (char *)mbfs->newP(p1 + 1); 364 | memcpy(tmp, buf, p1); 365 | chunkedSize = hex2int(tmp); 366 | mbfs->delP(&tmp); 367 | } 368 | 369 | // last chunk 370 | if (chunkedSize < 1) 371 | olen = -1; 372 | } 373 | else 374 | chunkState = 0; 375 | 376 | mbfs->delP(&buf); 377 | } 378 | else 379 | { 380 | 381 | if (chunkedSize > -1) 382 | { 383 | buf = (char *)mbfs->newP(bufLen); 384 | int readLen = readLine(buf, bufLen); 385 | 386 | if (readLen > 0) 387 | { 388 | // chunk may contain trailing 389 | if (dataLen + readLen - 2 < chunkedSize) 390 | { 391 | dataLen += readLen; 392 | memcpy(out, buf, readLen); 393 | olen = readLen; 394 | } 395 | else 396 | { 397 | if (chunkedSize - dataLen > 0) 398 | memcpy(out, buf, chunkedSize - dataLen); 399 | dataLen = chunkedSize; 400 | chunkState = 0; 401 | olen = readLen; 402 | } 403 | } 404 | else 405 | { 406 | olen = -1; 407 | } 408 | 409 | mbfs->delP(&buf); 410 | } 411 | } 412 | 413 | return olen; 414 | } 415 | 416 | int readChunkedData(MB_String &out, int &chunkState, int &chunkedSize, int &dataLen) 417 | { 418 | if (!client) 419 | return setError(ESP_LINE_NOTIFY_ERROR_TCP_ERROR_CONNECTION_REFUSED); 420 | 421 | char *tmp = nullptr; 422 | int p1 = 0; 423 | int olen = 0; 424 | 425 | if (chunkState == 0) 426 | { 427 | chunkState = 1; 428 | chunkedSize = -1; 429 | dataLen = 0; 430 | MB_String s; 431 | int readLen = readLine(s); 432 | if (readLen) 433 | { 434 | p1 = strpos(s.c_str(), (const char *)MBSTRING_FLASH_MCR(";"), 0); 435 | if (p1 == -1) 436 | { 437 | p1 = strpos(s.c_str(), (const char *)MBSTRING_FLASH_MCR("\r\n"), 0); 438 | } 439 | 440 | if (p1 != -1) 441 | { 442 | tmp = (char *)mbfs->newP(p1 + 1); 443 | memcpy(tmp, s.c_str(), p1); 444 | chunkedSize = hex2int(tmp); 445 | mbfs->delP(&tmp); 446 | } 447 | 448 | // last chunk 449 | if (chunkedSize < 1) 450 | olen = -1; 451 | } 452 | else 453 | chunkState = 0; 454 | } 455 | else 456 | { 457 | 458 | if (chunkedSize > -1) 459 | { 460 | MB_String s; 461 | int readLen = readLine(s); 462 | 463 | if (readLen > 0) 464 | { 465 | // chunk may contain trailing 466 | if (dataLen + readLen - 2 < chunkedSize) 467 | { 468 | dataLen += readLen; 469 | out += s; 470 | olen = readLen; 471 | } 472 | else 473 | { 474 | if (chunkedSize - dataLen > 0) 475 | out += s; 476 | dataLen = chunkedSize; 477 | chunkState = 0; 478 | olen = readLen; 479 | } 480 | } 481 | else 482 | { 483 | olen = -1; 484 | } 485 | } 486 | } 487 | 488 | return olen; 489 | } 490 | 491 | virtual void flush() 492 | { 493 | if (!client) 494 | return; 495 | 496 | while (client->available() > 0) 497 | client->read(); 498 | } 499 | 500 | esp_line_notify_cert_type getCertType() { return certType; } 501 | 502 | private: 503 | void strcat_c(char *str, char c) 504 | { 505 | for (; *str; str++) 506 | ; 507 | *str++ = c; 508 | *str++ = 0; 509 | } 510 | 511 | int strpos(const char *haystack, const char *needle, int offset) 512 | { 513 | if (!haystack || !needle) 514 | return -1; 515 | 516 | int hlen = strlen(haystack); 517 | int nlen = strlen(needle); 518 | 519 | if (hlen == 0 || nlen == 0) 520 | return -1; 521 | 522 | int hidx = offset, nidx = 0; 523 | while ((*(haystack + hidx) != '\0') && (*(needle + nidx) != '\0') && hidx < hlen) 524 | { 525 | if (*(needle + nidx) != *(haystack + hidx)) 526 | { 527 | hidx++; 528 | nidx = 0; 529 | } 530 | else 531 | { 532 | nidx++; 533 | hidx++; 534 | if (nidx == nlen) 535 | return hidx - nidx; 536 | } 537 | } 538 | 539 | return -1; 540 | } 541 | 542 | uint32_t hex2int(const char *hex) 543 | { 544 | uint32_t val = 0; 545 | while (*hex) 546 | { 547 | // get current character then increment 548 | uint8_t byte = *hex++; 549 | // transform hex character to the 4bit equivalent number, using the ascii table indexes 550 | if (byte >= '0' && byte <= '9') 551 | byte = byte - '0'; 552 | else if (byte >= 'a' && byte <= 'f') 553 | byte = byte - 'a' + 10; 554 | else if (byte >= 'A' && byte <= 'F') 555 | byte = byte - 'A' + 10; 556 | // shift 4 to make space for new digit, and add the 4 bits of the new digit 557 | val = (val << 4) | (byte & 0xF); 558 | } 559 | return val; 560 | } 561 | 562 | int tcpTimeout() 563 | { 564 | return timeoutMs; 565 | } 566 | 567 | void setMBFS(MB_FS *mbfs) { this->mbfs = mbfs; } 568 | 569 | void setSPIEthernet(SPI_ETH_Module *eth) { this->eth = eth; } 570 | 571 | esp_line_notify_cert_type certType = esp_line_notify_cert_type_undefined; 572 | 573 | protected: 574 | MB_String host; 575 | uint16_t port = 0; 576 | MB_FS *mbfs = nullptr; 577 | Client *client = nullptr; 578 | int chunkSize = 1024; 579 | 580 | // In esp8266, this is actually Arduino base Stream (char read) timeout. 581 | // This will override internally by WiFiClientSecureCtx::_connectSSL 582 | // to 5000 after SSL handshake was done with success. 583 | int timeoutMs = 40000; // 40 sec 584 | bool clockReady = false; 585 | time_t now = 0; 586 | int *response_code = nullptr; 587 | SPI_ETH_Module *eth = NULL; 588 | }; 589 | 590 | #endif 591 | --------------------------------------------------------------------------------