ESP AT Lib

group ESP

ESP stack.

Defines

esp_set_fw_version(v, major_, minor_, patch_)

Set and format major, minor and patch values to firmware version.

Parameters
  • [in] v: Version output, pointer to esp_sw_version_t structure

  • [in] major_: Major version

  • [in] minor_: Minor version

  • [in] patch_: Patch version

esp_get_min_at_fw_version(v)

Get minimal AT version supported by library.

Parameters

Functions

espr_t esp_init(esp_evt_fn cb_func, const uint32_t blocking)

Init and prepare ESP stack for device operation.

Note

Function must be called from operating system thread context. It creates necessary threads and waits them to start, thus running operating system is important.

Return

espOK on success, member of espr_t enumeration otherwise

Parameters

espr_t esp_reset(const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Execute reset and send default commands.

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

espr_t esp_reset_with_delay(uint32_t delay, const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Execute reset and send default commands with delay before first command.

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] delay: Number of milliseconds to wait before initiating first command to device

  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

espr_t esp_restore(const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Execute restore command and set module to default values.

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

espr_t esp_set_at_baudrate(uint32_t baud, const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Sets baudrate of AT port (usually UART)

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] baud: Baudrate in units of bits per second

  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

espr_t esp_set_wifi_mode(esp_mode_t mode, const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Sets WiFi mode to either station only, access point only or both.

Configuration changes will be saved in the NVS area of ESP device.

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] mode: Mode of operation. This parameter can be a value of esp_mode_t enumeration

  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

espr_t esp_get_wifi_mode(esp_mode_t *mode, const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Gets WiFi mode of either station only, access point only or both.

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] mode: point to space of Mode to get. This parameter can be a pointer of esp_mode_t enumeration

  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

espr_t esp_set_server(uint8_t en, esp_port_t port, uint16_t max_conn, uint16_t timeout, esp_evt_fn cb, const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Enables or disables server mode.

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] en: Set to 1 to enable server, 0 otherwise

  • [in] port: Port number used to listen on. Must also be used when disabling server mode

  • [in] max_conn: Number of maximal connections populated by server

  • [in] timeout: Time used to automatically close the connection in units of seconds. Set to 0 to disable timeout feature (not recommended)

  • [in] server_evt_fn: Connection callback function for new connections started as server

  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

espr_t esp_update_sw(const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Update ESP software remotely.

Note

ESP must be connected to access point to use this feature

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

espr_t esp_core_lock(void)

Lock stack from multi-thread access, enable atomic access to core.

If lock was 0 prior funcion call, lock is enabled and increased

Note

Function may be called multiple times to increase locks. Application must take care to call esp_core_unlock the same amount of time to make sure lock gets back to 0

Return

espOK on success, member of espr_t enumeration otherwise

espr_t esp_core_unlock(void)

Unlock stack for multi-thread access.

Used in conjunction with esp_core_lock function

If lock was non-zero before function call, lock is decreased. When lock == 0, protection is disabled and other threads may access to core

Return

espOK on success, member of espr_t enumeration otherwise

espr_t esp_device_set_present(uint8_t present, const esp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Notify stack if device is present or not.

Use this function to notify stack that device is not physically connected and not ready to communicate with host device

Return

espOK on success, member of espr_t enumeration otherwise

Parameters
  • [in] present: Flag indicating device is present

  • [in] evt_fn: Callback function called when command has finished. Set to NULL when not used

  • [in] evt_arg: Custom argument for event callback function

  • [in] blocking: Status whether command should be blocking or not

uint8_t esp_device_is_present(void)

Check if device is present.

Return

1 on success, 0 otherwise

uint8_t esp_device_is_esp8266(void)

Check if modem device is ESP8266.

Return

1 on success, 0 otherwise

uint8_t esp_device_is_esp32(void)

Check if modem device is ESP32.

Return

1 on success, 0 otherwise

uint8_t esp_delay(const uint32_t ms)

Delay for amount of milliseconds.

Delay is based on operating system semaphores. It locks semaphore and waits for timeout in ms time. Based on operating system, thread may be put to blocked list during delay and may improve execution speed

Return

1 on success, 0 otherwise

Parameters
  • [in] ms: Milliseconds to delay

uint8_t esp_get_current_at_fw_version(esp_sw_version_t *const version)

Get current AT firmware version of connected device.

Return

1 on success, 0 otherwise

Parameters
  • [out] version: Output version variable