LwESP

group LWESP

Lightweight ESP-AT parser.

Defines

lwesp_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 lwesp_sw_version_t structure

  • [in] major_: Major version

  • [in] minor_: Minor version

  • [in] patch_: Patch version

lwesp_get_min_at_fw_version(v)

Get minimal AT version supported by library.

Parameters

Functions

lwespr_t lwesp_init(lwesp_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

lwespOK on success, member of lwespr_t enumeration otherwise

Parameters

lwespr_t lwesp_reset(const lwesp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Execute reset and send default commands.

Return

lwespOK on success, member of lwespr_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

lwespr_t lwesp_reset_with_delay(uint32_t delay, const lwesp_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

lwespOK on success, member of lwespr_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

lwespr_t lwesp_restore(const lwesp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Execute restore command and set module to default values.

Return

lwespOK on success, member of lwespr_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

lwespr_t lwesp_set_at_baudrate(uint32_t baud, const lwesp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Sets baudrate of AT port (usually UART)

Return

lwespOK on success, member of lwespr_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

lwespr_t lwesp_set_wifi_mode(lwesp_mode_t mode, const lwesp_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

lwespOK on success, member of lwespr_t enumeration otherwise

Parameters
  • [in] mode: Mode of operation. This parameter can be a value of lwesp_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

lwespr_t lwesp_get_wifi_mode(lwesp_mode_t *mode, const lwesp_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

lwespOK on success, member of lwespr_t enumeration otherwise

Parameters
  • [in] mode: point to space of Mode to get. This parameter can be a pointer of lwesp_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

lwespr_t lwesp_set_server(uint8_t en, lwesp_port_t port, uint16_t max_conn, uint16_t timeout, lwesp_evt_fn cb, const lwesp_api_cmd_evt_fn evt_fn, void *const evt_arg, const uint32_t blocking)

Enables or disables server mode.

Return

lwespOK on success, member of lwespr_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

lwespr_t lwesp_update_sw(const lwesp_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

lwespOK on success, member of lwespr_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

lwespr_t lwesp_core_lock(void)

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

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

Note

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

Return

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_core_unlock(void)

Unlock stack for multi-thread access.

Used in conjunction with lwesp_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

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_device_set_present(uint8_t present, const lwesp_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

lwespOK on success, member of lwespr_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 lwesp_device_is_present(void)

Check if device is present.

Return

1 on success, 0 otherwise

uint8_t lwesp_device_is_esp8266(void)

Check if modem device is ESP8266.

Return

1 on success, 0 otherwise

uint8_t lwesp_device_is_esp32(void)

Check if modem device is ESP32.

Return

1 on success, 0 otherwise

uint8_t lwesp_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 lwesp_get_current_at_fw_version(lwesp_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