ESP32 2 boards (AP and Station) WiFi COMM Toggle LED in ESP-IDF.
Posted: Tue Feb 11, 2020 5:57 am
Hi All,
I need to toggle LED of one ESP32 board (STATION) from another ESP32 board (AP) using WiFi and vice versa, in esp-idf and no arduino. I am able to do it via a web page with ON and OFF button but I don't want to use a web page.
For example if one EP32(AP) board switch toggled the other ESP32 board (Station) LED need to be ON. and Vice-Versa.
I am no where near a programmer, but the below code work for me, (this is using a web page for turn on and off LED) how can I modify this code to do what I want.
I am trying to modify below code but, no success. Please don't point to arduino coding.
Thank you.
I need to toggle LED of one ESP32 board (STATION) from another ESP32 board (AP) using WiFi and vice versa, in esp-idf and no arduino. I am able to do it via a web page with ON and OFF button but I don't want to use a web page.
For example if one EP32(AP) board switch toggled the other ESP32 board (Station) LED need to be ON. and Vice-Versa.
I am no where near a programmer, but the below code work for me, (this is using a web page for turn on and off LED) how can I modify this code to do what I want.
I am trying to modify below code but, no success. Please don't point to arduino coding.
Thank you.
Code: Select all
static void
http_server_netconn_serve(struct netconn *conn)
{
struct netbuf *inbuf;
char *buf;
u16_t buflen;
err_t err;
/* Read the data from the port, blocking if nothing yet there.
We assume the request (the part we care about) is in one netbuf */
err = netconn_recv(conn, &inbuf);
if (err == ERR_OK) {
netbuf_data(inbuf, (void**)&buf, &buflen);
/* Is this an HTTP GET command? (only check the first 5 chars, since
there are other formats for GET, and we're keeping it very simple )*/
if (buflen>=5 &&
buf[0]=='G' &&
buf[1]=='E' &&
buf[2]=='T' &&
buf[3]==' ' &&
buf[4]=='/' ) {
printf("%c\n", buf[5]);
/* Send the HTML header
* subtract 1 from the size, since we dont send the \0 in the string
* NETCONN_NOCOPY: our data is const static, so no need to copy it
*/
gpio_pad_select_gpio(DIODE_PIN);
/* Set the GPIO as a push/pull output */
gpio_set_direction(DIODE_PIN, GPIO_MODE_OUTPUT);
if(buf[5]=='h'){
gpio_set_level(DIODE_PIN,1);
}
if(buf[5]=='l'){
gpio_set_level(DIODE_PIN,0);
}
netconn_write(conn, http_html_hdr, sizeof(http_html_hdr)-1, NETCONN_NOCOPY);
/* Send our HTML page */
netconn_write(conn, http_index_hml, sizeof(http_index_hml)-1, NETCONN_NOCOPY);
}
}
/* Close the connection (server closes in HTTP) */
netconn_close(conn);
/* Delete the buffer (netconn_recv gives us ownership,
so we have to make sure to deallocate the buffer) */
netbuf_delete(inbuf);
}
static void http_server(void *pvParameters)
{
struct netconn *conn, *newconn;
err_t err;
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, NULL, 80);
netconn_listen(conn);
do {
err = netconn_accept(conn, &newconn);
if (err == ERR_OK) {
http_server_netconn_serve(newconn);
netconn_delete(newconn);
}
} while(err == ERR_OK);
netconn_close(conn);
netconn_delete(conn);
}