Giter Club home page Giter Club logo

lwesp's Introduction

Lightweight ESP-AT parser

LwESP is lightweight ESP AT commands parser library to communicate with ESP8266 or ESP32 Wi-Fi modules using AT commands. Module is written in C99 and is system platform agnostic. Its main targets are embedded system devices like ARM Cortex-M, AVR, PIC and others, but can easily work under Windows, Linux or MAC environments too.

Espressif module runs official AT Commands (esp-at) software and communicates with host device via UART or SPI communication protocol.

Follow documentation for more information on implementation and details.

Read first: Documentation

Features

  • Supports latest ESP32, ESP32-C2, ESP32-C3, ESP32-C6 & ESP8266 AT software from Espressif system
  • Platform independent and very easy to port
  • Development of library under Win32 platform
  • Available examples for ARM Cortex-M, Win32 or POSIX (mostly Linux) platforms
  • Written in C language (C99)
  • Allows different configurations to optimize user requirements
  • Supports implementation with operating systems with advanced inter-thread communications
  • Uses 2 tasks for data handling from user and device
  • Includes several applications built on top of library
    • Netconn sequential API for client and server
    • HTTP server with dynamic files (file system) supported
    • MQTT client
  • Embeds other AT features, such as WPS management, custom DNS setup, Hostname for DHCP, Ping feature
  • User friendly MIT license

Contribute

Fresh contributions are always welcome. Simple instructions to proceed:

  1. Fork Github repository
  2. Follow C style & coding rules already used in the project
  3. Create a pull request to develop branch with new features or bug fixes

Alternatively you may:

  1. Report a bug
  2. Ask for a feature request

lwesp's People

Contributors

bertlammers avatar dependabot[bot] avatar imi415 avatar lisekt84 avatar majerle avatar matstm avatar mcesnik1 avatar michprev avatar niedong avatar sn00pster avatar takashikusachi avatar turmary avatar unspecd avatar xiongyu0523 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lwesp's Issues

Issue with CIPCLOSE

In my applications sometimes it happens although MQTT port close command is sent ( AT+CIPCLOSE) , no response (either CLOSED or ERROR ) is received and since the MQTT connection state is ESP_MQTT_CONN_DISCONNECTING , ESP AT Lib stays in this state forever no matter if esp_mqtt_client_disconnect is sent again because it never try to send AT+CIPCLOSE.

Performans

Hi @MaJerle,

Great thanks for such beatifull library.

I have some performance concern. Have you done any performance test?

Is it possible to make a http camera server with this library?

Stm32 reads camera data over dcmi, serves via esp32 over uart. Is it possible, can uart speed overcome this?

too many ESP_CORE_PROTECT calls ,cause dead lock

    ESP_CORE_PROTECT();                     /* Protect core */
    res = espi_process(data, len);          /* Process input data */
    ESP_CORE_UNPROTECT();   

    espi_process(data,len) ->   may callback esp_reset(),    then dead lock happen.

Configuration

I'm using STM32 with HAL Layer, where do i define the UART com port in your module ?

ESP8266 returns busy p...

I am using F407 with ESP8266. I upgraded the firmware of the ESP8266 to latest version:

AT version:1.6.2.0(Apr 13 2018 11:10:59)
SDK version:2.2.1(6ab97e9)
compile time:Jun 7 2018 19:34:26

The ESP8266 most of the time returns:

busy p...

If i put a few ms sleep in the send_data function the library keeps reseting the ESP8266.

If you need more messages between the F407 and the ESP8266 let me know.

Add custom AT command issue

The supplier of the board provides a custom AT command to read the ADC value of ESP32. How do I add it to esp_AT_lib and get its return value or is there any other example of adding a custom AT command?How many files do I need to change?

NULL check

Hello!
mem_insertfreeblock() has following lines:

for (ptr = &start_block; ptr != NULL && ptr->next < nb; ptr = ptr->next) {}
...
if ((uint8_t*)(addr + ptr->size) == (uint8_t*)nb) {

so ptr can be NULL and this should be checked before using it in if(), or remove NULL check from for() loop, if it can't be so

if ((uint8_t*)(addr + ptr->size) == (uint8_t*)nb) {

Basic AT commands problem in esp_private.h

I try to get the RAM of the ESP32 using ESP_AT_LIB. I notice that a basic AT command "ESP_CMD_SYSRAM"in esp_private.h line 69 may help me, but i can't find anything about it in esp_int.c like others such as "ESP_CMD_GMR". Does it mean that I have to write my own code or I miss something?

ESP8266 DHCP support

Hi MaJerle,

You're doing well, could you add DHCP feature (AT+CWDHCP command) for station wifi mode?

Thank for your time.

Feature proposal: Support for SDIO in stead of UART communication

Please see this question (not mine) on the esp-at issues list: espressif/esp-at#379

For my use case I'm downloading large files (>10MB) and even using a relatively high UART clock rate of 2.000.000 this takes a few minutes. (My assumption is that the clock rate of the UART is the bottleneck here)

I am exploring possibilities to improve the performance. So after reading the above issue and reading up on the low level driver documentation for your library I thought it should be feasible.

Do you have any thoughts on this? Did you ever try this? My target platform is an STM32 MCU.

NB. After writing this message I found that the same user that posted the above question to the esp-at issues also send in an issue for this project: #60 It looks like he's attempting to do the same...

Full re-init esp_ll in case of system errors

I've tested with esp_reset, but I realize that it does not reset chip. I mean RST command is ok, and may be sometimes its useful. But in case of some hardware errors its better to have reset with safe closing any socket and fully re-init harware esp_ll layer. For example, if there is on-board power problem, and esp was reset AND libraary use not default baudrate then there is no chance to restore communication.

Originally posted by @biovoid in #39 (comment)

About the cursor movement

[left] key:
cliprintf("^[D");
replace with:
cliprintf("\033[%dD", 1);

[right] key:
cliprintf("^[C");
replace with:
cliprintf("\033[%dC", 1);

[delete] key:
//cliprintf("%c", ch);
replace with:
cliprintf("\033[%dD", 1); cliprintf("\033[K");

Feature request: support for SSL client certificates

The esp-at firmware supports using client certificates for SSL connections. (See here). This is required when setting up an SSL link to e.g. AWS IOT. I have successfully tested the concept by providing manual AT commands. Steps to reproduce:

  1. make sure to have client certificate/key/CA-cert on the ESP. (I chose them to be at index 0)
  2. init ESP as usual and make connection to internet
  3. configure an NTP server to get current time and date (required to provide/validate SSL certificates) using AT+CIPSNTPCFG
  4. Configure SSL using AT+CIPSSLCCONF and specify auth_mode 3 and certificate indexes.
  5. Start SSL connection using AT+CIPSTART

For a full UART log of my manual PoC see this gist (redacted sensitive info)

Step 3. is not complex. It's just another init step which can be solved with some config (timezone and NTP host) and a new command: AT+CIPSNTPCFG
Step 4. is a bit more complex (I think), because the AT+CIPSSLCCONF requires the <link ID> of the connection. This value is not known prior to the AT+CIPSTART command. I guess it's possible to generate this value in the AT+CIPSSLCCONF command execution and store it in the connection object and check in the AT+CIPSTART command whether this value has previously been set (and the connection is in the correct state). Or do you see any other possibility?

Do you accept pull requests? First for step 3 and when we figured out an approach for Step 4 I can work on that as well.

Cyclic attempts to restart

I'm using your library on stm32l476-nucleo board.
If i follow same LL-init sequence like in stm32 examples(DMA is started before pulling RST up) - startup info end up in the buffer before return from LL-init function and it causes stack to send restsrt cmd over and over again, because it apparently thinks that restart wasn't forced.

For now i circumvent it by waiting long enough to let module spit startup info before starting DMA, but i think that this case(startup info after LL init function) should be handled in stack.

Return value of esp_netconn_connect()

The esp_netconn_connect() function returns espOK, even if there is no connection to the Wi-Fi access point.

Is this a bug or I just use it incorrectly?

By the way, it returns espOK, even if there is a WiFi link, but the remote host does not exist (or when the port is closed).

--
Sorry for my English

How we can publish large files?

Hi @MaJerle
I need to send some images to the server. Image size can be as big as 250KB. Is there any size limitation to publish a large file to MQTT? In esp_mqtt_client_publish function, payload len is uint16_t which means that data has to be <65535. However, I've tried to send a 50KB image but it gave me espERRMEM issue while I've set the mqtt tx buffer size 100KB. Any idea?

Improvement for "ports"

I've just discovered your library and am getting it working under FreeRTOS (plain freertos, not using the cmsis layer). Something that I've noticed is that you've decided to use defines to select the "OS" port.

Was there any reason for this? In my mind it would be much cleaner to just have a folder for each port and keep the file names for each port the same, you then just include the correct files to your project and set the correct include path for the platform.

Reason for me asking is that to add a platform you currently have to modify the source of the library, if you do it the other way around then you don't, you just add the correct files to your project and you can use it and update the library without causing yourself any issues.

If you're not keen on that, then maybe a third OS option could be "USER", where you can select that in the config and it uses files for the port suffixed with user, that way you can keep it as you currently do and people can do their own ports and can update without having to make changes to the underlying library.

HTML wrong in example data?

Hi,

I don't know enough about the frameworks being used here, but the demo suggests that there should be a message written to a div dynamically via javascript after the page is loaded.

However, the div with the id "maindiv" doesn't exist, therefore the message never appears.

I fixed this with:

static const uint8_t
responseData[] = ""
    "HTTP/1.1 200 OK\r\n"
    "Server: " HTTP_SERVER_NAME "\r\n"
    "Content-Type: text/html\r\n"
    "\r\n"
    "<html>\n"
    "   <head>\n"
    "       <title><!--#title--></title>\n"
    "       <meta http-equiv=\"Refresh\" content=\"1\" />\n"
    "       <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>\n"
    "       <script src=\"/js/js.js\" type=\"text/javascript\"></script>\n"
    "       <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css\" integrity=\"sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb\" crossorigin=\"anonymous\" />\n"
    "       <link rel=\"stylesheet\" type=\"text/css\" href=\"/css/style.css\" />\n"
    "   </head>\n"
    "   <body>\n"
    "       <div class=\"container\">\n"
    "           <h1>Welcome to web server hosted by ESP8266 Wi-Fi module!</h1>\n"
    "       </div>\n"
    "       <div id=\"maindiv\"/>"
    "       <footer>\n"
    "           <div class=\"container\">\n"
    "               Copyright &copy; 2017. All rights reserved. Webserver is hosted on ESP8266.\n"
    "           </div>\n"
    "       </footer>\n"
    "   </body>\n"
    "</html>\n";

But as I said, I don't know enough about the frameworks being used here as to whether they themselves create divs on the fly, but with this modification it does work how I would expect it to.

how to port to other platform.

i am so sorry about that, i am not so clear about how to port to other platform. i see some template in system dir. but i can only find how send data to esp8266 module. and i do not know how to recveive data from esp8266.

Workaround for missing +IDP message when server is in passive mode

There's an issue in the esp-at firmware where no +IDP message is received when in "passive mode" (Manual TCP receive) and a server is listening for connections. I've mentioned this issue here: #46

The issue report for the esp-at firmware is here: espressif/esp-at#294

We can (probably) fix/workaround this in the library as well by sending a AT+CIPRECVLEN? right after receiving a +LINK_CONN when it's a server connection and in "passive mode". Would you be inclined for this?

About the cursor movement

cliprintf("\033[%dD", 1); REPLACE cliprintf("^[D"); --------->move the cursor left
cliprintf("\033[%dC", 1); REPLACE cliprintf("^[C"); --------->move the cursor right

One more thing, about the [delete] key, i found cliprintf("%c", ch); doesnt work, here is the solution:
cliprintf("\033[%dD", 1); cliprintf("\033[K"); REPLACE cliprintf("%c", ch);

By the way, i am using xshell and securecrt for testing terminal, works fine.

Creation of server fails because of missing parameter

I've found an issue when trying out the netconn API. Setting up a new server on port 80 generated (and sent) the following AT command sequence:

AT+CIPSERVERMAXCONN=5

OK
AT+CIPSERVER=,80

ERROR

Notice the ERROR response on the last command. It's missing the first paramter of the AT+CIPSERVER command. This should be either a 0 (delete server) or 1 (create server). It looks like this can be fixed by adding the AT_PORT_SEND_CONST_STR("1");. This is the full code block:

case ESP_CMD_TCPIP_CIPSERVER: {         /* Enable or disable server */
            AT_PORT_SEND_BEGIN_AT();
            AT_PORT_SEND_CONST_STR("+CIPSERVER=");
            if (msg->msg.tcpip_server.en) {     /* Do we want to enable server? */
                AT_PORT_SEND_CONST_STR("1"); // this line is added
                espi_send_port(msg->msg.tcpip_server.port, 0, 1);
            } else {                            /* Disable server */
                AT_PORT_SEND_CONST_STR("0");
            }
            AT_PORT_SEND_END_AT();
            break;
        }

Software de-init

Hi,
I found that the library does not have deinit functon to dispose all memory and tasks. Some times there hardware error in communication and the only one way is to fully reset board, but it will be better to try re-init all or communication part of the library to retry initialization.

esp_sys_mbox_putnow implemention in freertos port

In freertos system porting file, why xQueueSendFromISR is called? I think all APIs are in task context..
From the document I can see the only difference between put and putnow is whether timeout is used.

uint8_t
esp_sys_mbox_putnow(esp_sys_mbox_t* b, void* m) {
    freertos_mbox mb;

    mb.d = m;
    return xQueueSendFromISR(*b, &mb, 0) == pdPASS;
}

esp_set_server callback doesn't work

Hello,
Apparently callback after creating server under 80 port doesn't work. I have configured separate esp_input_process thread with DMA buffer. Callback after esp_sta_join works fine, but once I call esp_set_server nothing happen. I checked system under gdb, and everything looks fine, data are present in dma buffer, but it is not processed. It worked under previous version of library - which were marked deprecated and removed, so I don't think it's AT firmware issue.
My code is pushed on github: https://github.com/rafalo235/nixie-clock-sw/tree/esp-lib
https://github.com/rafalo235/nixie-clock-sw/blob/esp-lib/src/connection-task/input-task.c - input task
https://github.com/rafalo235/nixie-clock-sw/blob/esp-lib/src/connection-task/connection-task.c - worker thread - line 72 is called, but Server_Callback is not called even if data are received
https://github.com/rafalo235/nixie-clock-sw/blob/esp-lib/inc/port/esp8266-at-lib/esp_config.h - esp config
esp_sys.h is coppied from cmsis sample

Data loss in TCP rx

I am having issues of incomplete data received on TCP links. My application protocol server expects bursts of 32kB of data in TCP and it times out because it only get a fraction of it (from 9 to 16kB usually).

After dumping the received data and comparing it with what was sent by the TCP client (windows PC) I see that big chunks of data are missing inside the received data. In other words, I only get the first and the last part of the 32k (the actual sizes vary).

After some debugging I think I confirmed this has to do with an invalid IPD buffer in espi_process(). At first I thought this was due to a failed pbuf allocation (I was getting allocation failures in esp_pbuf_new()), due to the fact that the server may be slow in consuming the data in this particual case.

So I tried to enlarge the available memory to 64kB (32kB at a time should be the biggest data flowing through the stack, only in the worst case that the server does not consume anything when the full burst is received).

However, this solved the esp_pbuf_new() allocation failures, but I still get NULL esp.m.ipd.buff in espi_process().

Then I have two questions:

  1. Is it correct that we drop the incoming data if esp.m.ipd.buff is NULL? see the following code
            if (len > 0) {
                if (esp.m.ipd.buff != NULL) {   /* Is buffer valid? */
                    ESP_MEMCPY(&esp.m.ipd.buff->payload[esp.m.ipd.buff_ptr], d, len);
                    ESP_DEBUGF(ESP_CFG_DBG_IPD | ESP_DBG_TYPE_TRACE,
                        "[IPD] Bytes read: %d\r\n", (int)len);
                    dbg_ipd_tag_count += len;
                } else {                        /* Simply skip the data in buffer */
                    ESP_DEBUGF(ESP_CFG_DBG_IPD | ESP_DBG_TYPE_TRACE,
                        "[IPD] Bytes skipped: %d\r\n", (int)len);
                    dbg_ipd_err = 1;    /******************** <<<breakpoint stops here>>> *******************/
                }
                d_len -= len;                   /* Decrease effective length */
                d += len;                       /* Skip remaining length */
                esp.m.ipd.buff_ptr += len;      /* Forward buffer pointer */
                esp.m.ipd.rem_len -= len;       /* Decrease remaining length */
            }

should we not fail (e.g. drop connection) in case esp.m.ipd.buff is NULL?

  1. Do you have any specific suggestion for further investigation in understanding why we have invalid buffers in the first place? Note that the communication is working with the same pattern in other test conditions. From the TCP server standpoint the working and not working case are quite similiar, the only difference I can think of is the speed of incoming data consumption, which can lead to higher buffering in the stack

comment misleading

Hi, In your code lwesp_int.c line 738-739 and 748-749

if (!CMD_IS_CUR(LWESP_CMD_WIFI_CWJAP)) { /* ### In case of auto connection /
lwesp_sta_getip(NULL, NULL, NULL, NULL, NULL, 0); /
Get new IP address */

Actually, it is not only in case of auto connection. Whenever I call "lwesp_sta_join()", this function "lwesp_sta_getip" will be triggered, and this is where I got my IP address. Right?

the comment should be something like "In case of receive "WIFI CONNECTED".

And I suggest to remove line 738-739, and keep 748-749 sometimes, getip is 0.0.0.0 at this point.

Thanks.

Callback when station connects to SoftAP on ESP8266

For the last couple of days I've been working on an integration between a STMF769i-discovery and a ESP8266 WiFi module using your library.

A long story short: i'm able to successfully initialise the library and instruct the ESP8266 to setup an access point (with WPA_WPA2). Very similar to the Win32 access_point_rtos example. Once I connect my phone to the access point the callback for the event ESP_EVT_AP_CONNECTED_STA is not fired. Is this a known issue?

A bit more about my setup:
I've got several ESP8266 lying around:

  • A Wemos D1 mini pro (v1.0.0) with 16MB
  • A Lolin new NodeMCU v3 with 4MB
  • ESP-01 module with 1MB

I've successfully updated the Wemos and Lolin to the stock "ESP8266 IDF AT Bin V2.0" firmware from the espressif website. The ESP-01 only has 1MB, which is not large enough for the stock firmware. Building my own firmware for the smaller memory has not yet been successful. For 2MB+ I was successful.

I've put a working setup together using the stock 2.0 firmware on the NodeMCU and connecting the STM32F769i discovery with a handful of breadboard cables. I had to use the UART2 ports on the NodeMCU for UART TX/RX. Took me a while to figure that out. Only to find out later that you've (kind of) mentioned this in this post as well. Or it's actually not the UART2 port, but the swapped RTS0/CTS0 pins for UART0. Espressif acutally mentions this here and how you can swap this back when building your own firmware.

The ESP_AT_Lib is initialising correctly. This is the output from the serial console

Initializing ESP-AT Lib
ESP callback evt: 0
Library initialized!
ESP callback evt: 1
Device reset detected!
ESP callback evt: 4
[THREAD] Timeout in produce thread waiting for command to finish in process thread
ESP callback evt: 3
ESP callback evt: 1
Device reset detected!
ESP callback evt: 2
ESP-AT Lib initialized!

The "ESP callback evt: N" lines are from an added printf("ESP callback evt: %d\r\n", esp_evt_get_type(evt)); line in esp_callback_func.

What I did notice it that the ESP8266 on the v2.0 firmware is no longer sending the following lines on the UART once a new station connects:

+STA_CONNECTED:"xx:xx:xx:xx:xx:xx"
+DIST_STA_IP:"xx:xx:xx:xx:xx:xx","192.168.4.2"

It was doing that with the older firmware. This seems to be related to my issue with the missing events.

ESP_32 support

Hi All,

I was wondering if library supports esp_32 WROOM? I tried to set the ESP_CFG_ESP32 to 1 and ESP_CFG_ESP8266 to 0 to be able to use the library for ESP32 but I've received an error at the compile time. In esp_config_default.h it's mentioned that ESP_CFG_ESP32 must be set to 0, so does this mean that library doesn't support ESP32?
Also I should mention that when I set get time and date request I am getting the following format which is not compatible with the current parser :
image

I've added the following code in (espi_parse_cipsntptime.c before "msg->msg.tcpip_sntp_time.dt->date = espi_parse_number(&str);" ) and problem is resolved:
if (*str == ' ') str++;

False positive return code

I need to investigate this, but I was playing with baud rates earlier (seeing what I could go up to) and the following code:

esp_init(esp_callback_func, 1);
    
esp_set_at_baudrate(921600*2, 1);

//set_baud(921600*2);`

if (esp_sta_join("SSID", "PASSWORD", 0, 0, 1)==espOK)
    print("joined");
else
    print("failed");

esp_sta_join was returning espOK when the baud rate of the ESP was changed but not the baud rate of the board, I confirmed by debug that the baud rate change on the ESP was taking place and that after that no more comms were taking place.

I would expect the esp_sta_join to return a failure code.

esp_netconn_close() crashes

Hello,

In esp_netconn_close() (esp_netconn.c on lines 697-698):

    esp_conn_set_arg(conn, NULL);               /* Reset argument */
    esp_conn_close(conn, 1);                    /* Close the connection */

Meanwhile, in netconn_evt() on lines 178-185:

        case ESP_EVT_CONN_RECV: {
            esp_pbuf_p pbuf;

    (1)     nc = esp_conn_get_arg(conn);        /* Get API from connection */
            pbuf = esp_evt_conn_recv_get_buff(evt); /* Get received buff */

            esp_conn_recved(conn, pbuf);        /* Notify stack about received data */
    (2)     nc->rcv_packets++;                  /* Increase number of received packets */
            ...

Suppose there is a connection to a host that is actively transmitting data to us (i. e. with a high bit rate). If the esp_netconn_close() function is called at this moment, the program will crash.

Screenshots: exception and stack trace.

a
b

cursor

[left] key:
cliprintf("^[D");
replace with:
cliprintf("\033[%dD", 1);

[right] key:
cliprintf("^[C");
replace with:
cliprintf("\033[%dC", 1);

[delete] key:
//cliprintf("%c", ch);
replace with:
cliprintf("\033[%dD", 1); cliprintf("\033[K");

MQTT length decoding issue

Hi @MaJerle
Thanks for all your efforts.
I found an issue in mqtt_parse_incoming function when data length is >=128
I modified the function and fixed it as bellow :


static uint8_t
mqtt_parse_incoming(esp_mqtt_client_p client, esp_pbuf_p pbuf) {
    size_t idx, buff_len = 0, buff_offset = 0;
    const uint8_t* d;
    uint8_t ch;
    uint8_t multiplier = 1;

    do {
        buff_offset += buff_len;                /* Calculate new offset of buffer */
        d = esp_pbuf_get_linear_addr(pbuf, buff_offset, &buff_len); /* Get address pointer */

        idx = 0;
        while (d != NULL && idx < buff_len) {   /* Process entire linear buffer */
            ch = d[idx++];                      /* Get element */
            switch (client->parser_state) {     /* Check parser state */
                case MQTT_PARSER_STATE_INIT: {  /* We are waiting for start byte and packet type */
                    ESP_DEBUGF(ESP_CFG_DBG_MQTT_STATE,
                        "[MQTT] Parser init state, received first byte of packet 0x%02X\r\n", (unsigned)ch);

                    /* Save other info about message */
                    client->msg_hdr_byte = ch;  /* Save first entry */
                    client->msg_rem_len = 0;    /* Reset remaining length */
                    client->msg_curr_pos = 0;   /* Reset current buffer write pointer */

                    client->parser_state = MQTT_PARSER_STATE_CALC_REM_LEN;
                    break;
                }
                case MQTT_PARSER_STATE_CALC_REM_LEN: {  /* Calculate remaining length of packet */
                  client->msg_rem_len += (ch & 127) * multiplier;
                   multiplier *= 128;
                //    client->msg_rem_len <<= 7;  /* Shift remaining length by 7 bits */
                //    client->msg_rem_len |= (ch & 0x7F);
                    /* TODO: Ignore too-big messages */
                    if (!(ch & 0x80)) {         /* Is this last entry? */
                        ESP_DEBUGF(ESP_CFG_DBG_MQTT_STATE,
                            "[MQTT] Remaining length received: %d bytes\r\n", (int)client->msg_rem_len);

                        if (client->msg_rem_len > 0) {
                            client->parser_state = MQTT_PARSER_STATE_READ_REM;
                        } else {
                            mqtt_process_incoming_message(client);
                            client->parser_state = MQTT_PARSER_STATE_INIT;
                        }
                    }
                    break;
                }
                case MQTT_PARSER_STATE_READ_REM: {  /* Read remaining bytes and write to RX buffer */
                    client->rx_buff[client->msg_curr_pos++] = ch;   /* Write received character */

                    if (client->msg_curr_pos == client->msg_rem_len) {
                        ESP_DEBUGF(ESP_CFG_DBG_MQTT_STATE,
                            "[MQTT] Packet parsed and ready for processing\r\n");

                        mqtt_process_incoming_message(client);  /* Process incoming packet */
                        client->parser_state = MQTT_PARSER_STATE_INIT;  /* Go to initial state and listen for next received packet */
                    }
                    break;
                }
                default:
                    client->parser_state = MQTT_PARSER_STATE_INIT;
            }
        }
    } while (buff_len);
    return 0;
}
```
`

SmartConfig

Glad to see this library, I am looking for such a library, which is already used in RTThread.
But I didn't see the instructions for SmartConfig. Do I have a plan to add this command?

sem-sync

Hi MaJerle,

/* Create threads */
    esp_sys_sem_wait(&esp.sem_sync, 0);         /* Lock semaphore */
    if (!esp_sys_thread_create(&esp.thread_produce, "esp_produce", esp_thread_producer, &esp.sem_sync, ESP_SYS_THREAD_SS, ESP_SYS_THREAD_PRIO)) {
        esp_sys_sem_release(&esp.sem_sync);     /* Release semaphore */
        goto cleanup;
    }
    esp_sys_sem_wait(&esp.sem_sync, 0);         /* Wait semaphore, should be unlocked in producer thread */
    if (!esp_sys_thread_create(&esp.thread_process, "esp_process", esp_thread_process, &esp.sem_sync, ESP_SYS_THREAD_SS, ESP_SYS_THREAD_PRIO)) {
        esp_sys_sem_release(&esp.sem_sync);     /* Release semaphore */
        goto cleanup;
    }
    esp_sys_sem_wait(&esp.sem_sync, 0);         /* Wait semaphore, should be unlocked in producer thread */
    esp_sys_sem_release(&esp.sem_sync);         /* Release semaphore            ① */

esp_netconn_receive() returns not all data

Hi.

Suppose we have following setup. A TCP server that sends N bytes at the maximum possible bit rate immediately after the client connects.

Server:

$ wc -c < SOMEFILE
9504
$ socat tcp4-listen:8888,forever,fork,reuseaddr file:SOMEFILE

And a client:

    esp_pbuf_p buf;
    esp_netconn_p conn;
    size_t N = 9504;
    size_t n_recv;
    size_t n_recv_total;
    espr_t status;

    conn = esp_netconn_new(ESP_NETCONN_TYPE_TCP);
    assert(conn != NULL);

    if ((status = esp_netconn_connect(conn, "192.168.1.1", 8888)) != espOK)
    {
        printf("esp_netconn_connect() failed (%u)", status);
    }
    else
    {
        n_recv_total = 0;

        for (;;)
        {
            if ((status = esp_netconn_receive(conn, &buf)) != espOK)
            {
                printf("Expected: %u, received: %u", N, n_recv_total);
                break;
            }

            n_recv = esp_pbuf_length(buf, 1);
            n_recv_total += n_recv;

            esp_pbuf_free(buf);
            buf = NULL;
        }

        if (status != espCLOSED)
            esp_netconn_close(conn);

        esp_netconn_delete(conn);
    }

And here is what the client prints:

Expected: 9504, received: 8760

To reproduce this problem, make sure the network latency is minimal.

Communicate with STM32

Hi,

I have STM32 Firmware running with CAN stack.

I have esp8286 Wifi Module attached to STM32 32.
How can I run web server on STM32 and communcate with esp8286 using AT commands.

Have you tried out?

Incorrect tick calculations

I noticed in your port for cmsis that you often time the number of ticks that it took to complete the operation on queues, however, you have assigned the type as uint32_t, this will produce an incorrect value when the tick overflows and should actually be a signed calculation.

Semaphore(sem_sync ) multiple meaningless calls

Hi MaJerle:

In Esp.c File:

/* Create threads */
esp_sys_sem_wait(&esp.sem_sync, 0);         /* ①*/
if (!esp_sys_thread_create(&esp.thread_producer, "esp_producer", esp_thread_producer, &esp.sem_sync, ESP_SYS_THREAD_SS, ESP_SYS_THREAD_PRIO)) {
    esp_sys_sem_release(&esp.sem_sync);     /* Release semaphore */
    goto cleanup;
}
esp_sys_sem_wait(&esp.sem_sync, 0);         /* ② */
if (!esp_sys_thread_create(&esp.thread_process, "esp_producer", esp_thread_process, &esp.sem_sync, ESP_SYS_THREAD_SS, ESP_SYS_THREAD_PRIO)) {
    esp_sys_sem_release(&esp.sem_sync);     /* Release semaphore */
    goto cleanup;
}
esp_sys_sem_wait(&esp.sem_sync, 0);         /* ③ */
esp_sys_sem_release(&esp.sem_sync);         /* Release semaphore */

①:A sem_sync lock is obtained,If the producer thread is created successfully
②:It will try to get the lock again,If the process thread is created successfully,But no one released the lock,So will this lock fail?
③:try to get the lock again,Fail?

And in the producer thread, why continue to acquire this lock?

I'm puzzled. Please give me some advice. Thank you.

ESP32 support (was ESP32 minimum version)

I am integrating ESP_AT_Lib on a Spansion S6E2CCCAJ device connected to ESP32_DevkitC_v4.

The library initialization stops because the device reports minimal version 1.1.3 whereas the library expects at least 1.6.0.

If I understand correctly this version is that of ESP8266 AT fw. Can I just change the min numbers and expect everything works? What is the minimum version of ESP32-AT fw supported?

Is there a way to specify I am using ESP32 in lieu of ESP8266?

esp_config.h - Missing?

There is a header file named "esp_config.h" that's referred to by other files here but it isn't present anywhere in the folder hierarchy, did I do something wrong or is this an oversight?

Thanks

Support for AT+SYSFLASH?

First, thanks for this fantastic library!

I am currently working on a project where I need to update SSL client certificates. This can be done using the AT+SYSFLASH command (ESP32 only). Are there any plans to introduce support for this command?

If not I will consider writing it myself.

Documentation on Firmware

Hi,

The documentation could do with a bit more of a hint/warning about the firmware that people have on their device, it absolutely requires the official firmware from ESP to work properly (I couldn't get the http server working, so spent ages figuring out how to flash the ESP firmware on it)

After flashing, the HTTP server works correctly. While bits may work fine with the AI-THINKER firmware not all of it will as I found out!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.