void wifi_init_softap() { ap_event_group = xEventGroupCreate(); //tcpip_adapter_init(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); wifi_config_t wifi_config = { .ap = { .ssid = EXAMPLE_DEFAULT_SSID, .ssid_len = 0, .max_connection=EXAMPLE_MAX_STA_CONN, .password = EXAMPLE_DEFAULT_PWD, .authmode = WIFI_AUTH_WPA_WPA2_PSK }, }; if (strlen(EXAMPLE_DEFAULT_PWD) ==0) { wifi_config.ap.authmode = WIFI_AUTH_OPEN; } ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP)); ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config)); ESP_ERROR_CHECK(esp_wifi_start()); ESP_LOGI(TAG, "wifi_init_softap finished.SSID:%s password:%s \n", EXAMPLE_DEFAULT_SSID, EXAMPLE_DEFAULT_PWD); }
void app_main() { /* Initialize NVS — it is used to store PHY calibration data */ esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK( ret ); ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE)); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) { ESP_LOGE(GAP_TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret)); return; } if ((ret = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)) != ESP_OK) { ESP_LOGE(GAP_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret)); return; } if ((ret = esp_bluedroid_init()) != ESP_OK) { ESP_LOGE(GAP_TAG, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(ret)); return; } if ((ret = esp_bluedroid_enable()) != ESP_OK) { ESP_LOGE(GAP_TAG, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(ret)); return; } bt_app_gap_start_up(); }
static void sc_callback(smartconfig_status_t status, void *pdata) { switch (status) { case SC_STATUS_WAIT: ESP_LOGI(TAG, "SC_STATUS_WAIT"); break; case SC_STATUS_FIND_CHANNEL: ESP_LOGI(TAG, "SC_STATUS_FINDING_CHANNEL"); break; case SC_STATUS_GETTING_SSID_PSWD: ESP_LOGI(TAG, "SC_STATUS_GETTING_SSID_PSWD"); break; case SC_STATUS_LINK: ESP_LOGI(TAG, "SC_STATUS_LINK"); wifi_config_t *wifi_config = pdata; ESP_LOGI(TAG, "SSID:%s", wifi_config->sta.ssid); ESP_LOGI(TAG, "PASSWORD:%s", wifi_config->sta.password); ESP_ERROR_CHECK( esp_wifi_disconnect() ); ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, wifi_config) ); ESP_ERROR_CHECK( esp_wifi_connect() ); break; case SC_STATUS_LINK_OVER: ESP_LOGI(TAG, "SC_STATUS_LINK_OVER"); if (pdata != NULL) { uint8_t phone_ip[4] = { 0 }; memcpy(phone_ip, (uint8_t* )pdata, 4); ESP_LOGI(TAG, "Phone ip: %d.%d.%d.%d\n", phone_ip[0], phone_ip[1], phone_ip[2], phone_ip[3]); } xEventGroupSetBits(wifi_event_group, ESPTOUCH_DONE_BIT); break; default: break; } }
void app_main() { vTaskDelay(1000 / portTICK_PERIOD_MS); ESP_ERROR_CHECK(nvs_flash_init_partition("Mynvs")); nvs_handle handle; ESP_ERROR_CHECK(nvs_open_from_partition("Mynvs","store", NVS_READWRITE, &handle)); int32_t val = 0; esp_err_t result = nvs_get_i32(handle, "val", &val); switch (result) { case ESP_ERR_NOT_FOUND: ESP_LOGE(TAG, "Value not set yet"); break; case ESP_OK: ESP_LOGI(TAG, "Value is %d", val); break; default: ESP_LOGE(TAG, "Error (%s) opening NVS handle!\n", esp_err_to_name(result)); break; } val++; ESP_ERROR_CHECK(nvs_set_i32(handle, "val", val)); ESP_ERROR_CHECK(nvs_commit(handle)); nvs_close(handle); }
static esp_err_t event_handler(void *ctx, system_event_t *event) { httpd_handle_t *server = (httpd_handle_t *) ctx; switch(event->event_id) { case SYSTEM_EVENT_STA_START: ESP_LOGI(TAG, "SYSTEM_EVENT_STA_START"); ESP_ERROR_CHECK(esp_wifi_connect()); break; case SYSTEM_EVENT_STA_GOT_IP: ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP"); ESP_LOGI(TAG, "Got IP: '%s'", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip)); /* Start the web server */ if (*server == NULL) { *server = start_webserver(); } break; case SYSTEM_EVENT_STA_DISCONNECTED: ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED"); ESP_ERROR_CHECK(esp_wifi_connect()); /* Stop the web server */ if (*server) { stop_webserver(*server); *server = NULL; } break; default: break; } return ESP_OK; }
void ets_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg) { if (!timer_initialized(ptimer)) { memset(ptimer, 0, sizeof(*ptimer)); TIMER_INITIALIZED_FIELD(ptimer) = TIMER_INITIALIZED_VAL; } if (ESP_TIMER(ptimer) == NULL) { const esp_timer_create_args_t create_args = { .callback = pfunction, .arg = parg, .name = "ETSTimer", .dispatch_method = ESP_TIMER_TASK }; ESP_ERROR_CHECK( esp_timer_create(&create_args, (esp_timer_handle_t*)&(ptimer->timer_arg)) ); } } void IRAM_ATTR ets_timer_arm_us(ETSTimer *ptimer, uint32_t time_us, bool repeat_flag) { assert(timer_initialized(ptimer)); esp_timer_stop(ESP_TIMER(ptimer)); // no error check if (!repeat_flag) { ESP_ERROR_CHECK( esp_timer_start_once(ESP_TIMER(ptimer), time_us) ); } else { ESP_ERROR_CHECK( esp_timer_start_periodic(ESP_TIMER(ptimer), time_us) ); } }
void app_main(void) { // Initialize NVS esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret); initialise_wifi(); ret = xTaskCreate(&mqtt_client_thread, MQTT_CLIENT_THREAD_NAME, MQTT_CLIENT_THREAD_STACK_WORDS, NULL, MQTT_CLIENT_THREAD_PRIO, NULL); if (ret != pdPASS) { ESP_LOGE(TAG, "mqtt create client thread %s failed", MQTT_CLIENT_THREAD_NAME); } }
static int eth_cmd_control(int argc, char **argv) { int nerrors = arg_parse(argc, argv, (void **)ð_control_args); if (nerrors != 0) { arg_print_errors(stderr, eth_control_args.end, argv[0]); return 1; } if (!strncmp(eth_control_args.control->sval[0], "start", 5) && !started) { ESP_ERROR_CHECK(esp_eth_enable()); started = true; } if (!strncmp(eth_control_args.control->sval[0], "stop", 4) && started) { ESP_ERROR_CHECK(esp_eth_disable()); started = false; } if (!strncmp(eth_control_args.control->sval[0], "info", 4)) { uint8_t mac_addr[6]; esp_eth_get_mac(mac_addr); printf("HW ADDR: " MACSTR "\r\n", MAC2STR(mac_addr)); tcpip_adapter_get_ip_info(ESP_IF_ETH, &ip); printf("ETHIP: " IPSTR "\r\n", IP2STR(&ip.ip)); printf("ETHMASK: " IPSTR "\r\n", IP2STR(&ip.netmask)); printf("ETHGW: " IPSTR "\r\n", IP2STR(&ip.gw)); } return 0; }
static bool wifi_cmd_sta_join(const char* ssid, const char* pass) { int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0); wifi_config_t wifi_config = { 0 }; strlcpy((char*) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid)); if (pass) { strncpy((char*) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password)); } if (bits & CONNECTED_BIT) { reconnect = false; xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); ESP_ERROR_CHECK( esp_wifi_disconnect() ); xEventGroupWaitBits(wifi_event_group, DISCONNECTED_BIT, 0, 1, portTICK_RATE_MS); } reconnect = true; ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) ); ESP_ERROR_CHECK( esp_wifi_connect() ); xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 5000/portTICK_RATE_MS); return true; }
static void setup_gpios() { // Input: // 4: Joy #2 Pot x // // Output: // 5: Joy #1 Pot X // 21: Joy #1 Pot X // Output: 5 (LED) and 21 gpio_config_t io_conf; io_conf.intr_type = GPIO_INTR_DISABLE; io_conf.mode = GPIO_MODE_OUTPUT; io_conf.pin_bit_mask = ((1ULL << GPIO_NUM_21) | (1ULL << GPIO_NUM_5)); io_conf.pull_down_en = false; io_conf.pull_up_en = false; ESP_ERROR_CHECK( gpio_config(&io_conf) ); // Input: read POT X io_conf.intr_type = GPIO_INTR_POSEDGE; io_conf.mode = GPIO_MODE_INPUT; io_conf.pin_bit_mask = 1ULL << GPIO_NUM_18; io_conf.pull_down_en = false; io_conf.pull_up_en = true; ESP_ERROR_CHECK( gpio_config(&io_conf) ); // install gpio isr service ESP_ERROR_CHECK( gpio_install_isr_service(0) ); //hook isr handler for specific gpio pin ESP_ERROR_CHECK( gpio_isr_handler_add(GPIO_NUM_18, gpio_isr_handler_up, (void*) GPIO_NUM_18) ); // ESP_ERROR_CHECK( gpio_isr_register(gpio_isr_handler_up, (void*) GPIO_NUM_4, 0, NULL) ); }
void test_spi_task(void *ignore) { ESP_LOGD(tag, ">> test_spi_task"); spi_bus_config_t bus_config; bus_config.sclk_io_num = 21; // CLK bus_config.mosi_io_num = 22; // MOSI bus_config.miso_io_num = -1; // MISO bus_config.quadwp_io_num = -1; // Not used bus_config.quadhd_io_num = -1; // Not used ESP_LOGI(tag, "... Initializing bus."); ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &bus_config, 1)); spi_device_handle_t handle; spi_device_interface_config_t dev_config; dev_config.address_bits = 0; dev_config.command_bits = 0; dev_config.dummy_bits = 0; dev_config.mode = 0; dev_config.duty_cycle_pos = 0; dev_config.cs_ena_posttrans = 0; dev_config.cs_ena_pretrans = 0; dev_config.clock_speed_hz = 10000; dev_config.spics_io_num = 23; dev_config.flags = 0; dev_config.queue_size = 1; dev_config.pre_cb = NULL; dev_config.post_cb = NULL; ESP_LOGI(tag, "... Adding device bus."); ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle)); char data[3]; spi_transaction_t trans_desc; trans_desc.address = 0; trans_desc.command = 0; trans_desc.flags = 0; trans_desc.length = 3 * 8; trans_desc.rxlength = 0; trans_desc.tx_buffer = data; trans_desc.rx_buffer = data; data[0] = 0x12; data[1] = 0x34; data[2] = 0x56; ESP_LOGI(tag, "... Transmitting."); ESP_ERROR_CHECK(spi_device_transmit(handle, &trans_desc)); ESP_LOGI(tag, "... Removing device."); ESP_ERROR_CHECK(spi_bus_remove_device(handle)); ESP_LOGI(tag, "... Freeing bus."); ESP_ERROR_CHECK(spi_bus_free(HSPI_HOST)); ESP_LOGD(tag, "<< test_spi_task"); vTaskDelete(NULL); }
/** * Save our connection info for retrieval on a subsequent restart. */ static void saveConnectionInfo(connection_info_t *pConnectionInfo) { nvs_handle handle; ESP_ERROR_CHECK(nvs_open(BOOTWIFI_NAMESPACE, NVS_READWRITE, &handle)); ESP_ERROR_CHECK(nvs_set_blob(handle, KEY_CONNECTION_INFO, pConnectionInfo, sizeof(connection_info_t))); ESP_ERROR_CHECK(nvs_set_u32(handle, KEY_VERSION, g_version)); ESP_ERROR_CHECK(nvs_commit(handle)); nvs_close(handle); } // setConnectionInfo
static void initialise_wifi(void) { wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL)); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_start()); }
static void scan_task(void *pvParameters) { while(1) { xEventGroupWaitBits(wifi_event_group, SCAN_DONE_BIT, false, true, portMAX_DELAY); ESP_LOGI(TAG, "WIFI scan doen"); xEventGroupClearBits(wifi_event_group, SCAN_DONE_BIT); uint16_t apCount = 0; esp_wifi_scan_get_ap_num(&apCount); printf("Number of access points found: %d\n", apCount); if (apCount == 0) { ESP_LOGI(TAG, "Nothing AP found"); return; } wifi_ap_record_t *list = (wifi_ap_record_t *)malloc(sizeof(wifi_ap_record_t) * apCount); ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&apCount, list)); int i; printf("======================================================================\n"); printf(" SSID | RSSI | AUTH \n"); printf("======================================================================\n"); for (i=0; i<apCount; i++) { char *authmode; switch(list[i].authmode) { case WIFI_AUTH_OPEN: authmode = "WIFI_AUTH_OPEN"; break; case WIFI_AUTH_WEP: authmode = "WIFI_AUTH_WEP"; break; case WIFI_AUTH_WPA_PSK: authmode = "WIFI_AUTH_WPA_PSK"; break; case WIFI_AUTH_WPA2_PSK: authmode = "WIFI_AUTH_WPA2_PSK"; break; case WIFI_AUTH_WPA_WPA2_PSK: authmode = "WIFI_AUTH_WPA_WPA2_PSK"; break; default: authmode = "Unknown"; break; } printf("%26.26s | % 4d | %22.22s\n",list[i].ssid, list[i].rssi, authmode); } free(list); printf("\n\n"); // scan again vTaskDelay(2000 / portTICK_PERIOD_MS); //The true parameter cause the function to block until the scan is done. ESP_ERROR_CHECK(esp_wifi_scan_start(&scanConf, true)); } }
void IRAM_ATTR ets_timer_arm(ETSTimer *ptimer, uint32_t time_ms, bool repeat_flag) { uint64_t time_us = 1000LL * (uint64_t) time_ms; assert(timer_initialized(ptimer)); esp_timer_stop(ESP_TIMER(ptimer)); // no error check if (!repeat_flag) { ESP_ERROR_CHECK( esp_timer_start_once(ESP_TIMER(ptimer), time_us) ); } else { ESP_ERROR_CHECK( esp_timer_start_periodic(ESP_TIMER(ptimer), time_us) ); } }
void Service::register_characteristic(Characteristic *nC) { assert(handle != 0); if(nC->is_descriptor) { auto ret = esp_ble_gatts_add_char_descr(handle, &(nC->id), nC->perm, &(nC->value), &(nC->autoResp)); ESP_ERROR_CHECK(ret); } else { auto ret = esp_ble_gatts_add_char(handle, &(nC->id), nC->perm, nC->prop, &(nC->value), &(nC->autoResp)); ESP_ERROR_CHECK(ret); } }
void initI2C() { i2c_config_t conf; conf.mode = I2C_MODE_MASTER; conf.sda_io_num = SDA_PIN; conf.scl_io_num = SCL_PIN; conf.sda_pullup_en = GPIO_PULLUP_ENABLE; conf.scl_pullup_en = GPIO_PULLUP_ENABLE; conf.master.clk_speed = 100000; ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &conf)); ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0)); }
void app_main() { // Initialize NVS esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK( ret ); wifi_scan(); }
void app_main() { uint8_t sha_256[HASH_LEN] = { 0 }; esp_partition_t partition; // get sha256 digest for the partition table partition.address = ESP_PARTITION_TABLE_OFFSET; partition.size = ESP_PARTITION_TABLE_MAX_LEN; partition.type = ESP_PARTITION_TYPE_DATA; esp_partition_get_sha256(&partition, sha_256); print_sha256(sha_256, "SHA-256 for the partition table: "); // get sha256 digest for bootloader partition.address = ESP_BOOTLOADER_OFFSET; partition.size = ESP_PARTITION_TABLE_OFFSET; partition.type = ESP_PARTITION_TYPE_APP; esp_partition_get_sha256(&partition, sha_256); print_sha256(sha_256, "SHA-256 for bootloader: "); // get sha256 digest for running partition esp_partition_get_sha256(esp_ota_get_running_partition(), sha_256); print_sha256(sha_256, "SHA-256 for current firmware: "); const esp_partition_t *running = esp_ota_get_running_partition(); esp_ota_img_states_t ota_state; if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) { if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) { // run diagnostic function ... bool diagnostic_is_ok = diagnostic(); if (diagnostic_is_ok) { ESP_LOGI(TAG, "Diagnostics completed successfully! Continuing execution ..."); esp_ota_mark_app_valid_cancel_rollback(); } else { ESP_LOGE(TAG, "Diagnostics failed! Start rollback to the previous version ..."); esp_ota_mark_app_invalid_rollback_and_reboot(); } } } // Initialize NVS. esp_err_t err = nvs_flash_init(); if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { // OTA app partition table has a smaller NVS partition size than the non-OTA // partition table. This size mismatch may cause NVS initialization to fail. // If this happens, we erase NVS partition and initialize NVS again. ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } ESP_ERROR_CHECK( err ); initialise_wifi(); xTaskCreate(&ota_example_task, "ota_example_task", 8192, NULL, 5, NULL); }
void app_main() { /* Initialize NVS — it is used to store PHY calibration data */ esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK( ret ); start_wps(); }
void initialize_console() { /* Disable buffering on stdin */ setvbuf(stdin, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); /* Configure UART. Note that REF_TICK is used so that the baud rate remains * correct while APB frequency is changing in light sleep mode. */ uart_config_t uart_config; memset(&uart_config, 0, sizeof(uart_config)); uart_config.baud_rate = CONFIG_CONSOLE_UART_BAUDRATE; uart_config.data_bits = UART_DATA_8_BITS; uart_config.parity = UART_PARITY_DISABLE; uart_config.stop_bits = UART_STOP_BITS_1; uart_config.use_ref_tick = true; ESP_ERROR_CHECK(uart_param_config((uart_port_t) CONFIG_CONSOLE_UART_NUM, &uart_config)); /* Install UART driver for interrupt-driven reads and writes */ ESP_ERROR_CHECK(uart_driver_install((uart_port_t) CONFIG_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0)); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); /* Initialize the console */ esp_console_config_t console_config; memset(&console_config, 0, sizeof(console_config)); console_config.max_cmdline_args = 8; console_config.max_cmdline_length = 256; #if CONFIG_LOG_COLORS console_config.hint_color = atoi(LOG_COLOR_CYAN); #endif ESP_ERROR_CHECK(esp_console_init(&console_config)); /* Configure linenoise line completion library */ /* Enable multiline editing. If not set, long commands will scroll within * single line. */ linenoiseSetMultiLine(1); /* Tell linenoise where to get command completions and hints */ linenoiseSetCompletionCallback(&esp_console_get_completion); linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint); /* Set command history size */ linenoiseHistorySetMaxLen(100); }
void app_main() { // Initialize NVS. esp_err_t err = nvs_flash_init(); if (err == ESP_ERR_NVS_NO_FREE_PAGES) { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } ESP_ERROR_CHECK( err ); initialise_wifi(); xTaskCreate(&aws_iot_task, "aws_iot_task", 9216, NULL, 5, NULL); }
int app_main(void) { nvs_flash_init(); system_init(); tcpip_adapter_init(); ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); I2CScanner(); return 0; }
void app_main() { esp_err_t err = nvs_flash_init(); if (err == ESP_ERR_NVS_NO_FREE_PAGES) { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } ESP_ERROR_CHECK( err ); initialise_wifi(); /* Temporarily pin task to core, due to FPU uncertainty */ xTaskCreatePinnedToCore(&aws_iot_task, "aws_iot_task", 16384+1024, NULL, 5, NULL, 1); }
/** * Main entry into bootWiFi */ void bootWiFi(bootwifi_callback_t callback) { ESP_LOGD(tag, ">> bootWiFi"); g_callback = callback; nvs_flash_init(); tcpip_adapter_init(); ESP_ERROR_CHECK(esp_event_loop_init(esp32_wifi_eventHandler, NULL)); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); bootWiFi2(); ESP_LOGD(tag, "<< bootWiFi"); } // bootWiFi
void register_ethernet() { eth_event_group = xEventGroupCreate(); tcpip_adapter_init(); ESP_ERROR_CHECK(esp_event_loop_init(eth_event_handler, NULL)); eth_config_t config = DEFAULT_ETHERNET_PHY_CONFIG; config.phy_addr = CONFIG_PHY_ADDRESS; config.gpio_config = eth_gpio_config_rmii; config.tcpip_input = tcpip_adapter_eth_input; config.clock_mode = CONFIG_PHY_CLOCK_MODE; #ifdef CONFIG_PHY_USE_POWER_PIN /* Replace the default 'power enable' function with an example-specific one that toggles a power GPIO. */ config.phy_power_enable = phy_device_power_enable_via_gpio; #endif ESP_ERROR_CHECK(esp_eth_init(&config)); eth_control_args.control = arg_str1(NULL, NULL, "<start|stop|info>", "Start/Stop Ethernet or Get info of Ethernet"); eth_control_args.end = arg_end(1); const esp_console_cmd_t cmd = { .command = "ethernet", .help = "Control Ethernet interface", .hint = NULL, .func = eth_cmd_control, .argtable = ð_control_args }; ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); iperf_args.ip = arg_str0("c", "client", "<ip>", "run in client mode, connecting to <host>"); iperf_args.server = arg_lit0("s", "server", "run in server mode"); iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP"); iperf_args.port = arg_int0("p", "port", "<port>", "server port to listen on/connect to"); iperf_args.interval = arg_int0("i", "interval", "<interval>", "seconds between periodic bandwidth reports"); iperf_args.time = arg_int0("t", "time", "<time>", "time in seconds to transmit for (default 10 secs)"); iperf_args.abort = arg_lit0("a", "abort", "abort running iperf"); iperf_args.end = arg_end(1); const esp_console_cmd_t iperf_cmd = { .command = "iperf", .help = "iperf command", .hint = NULL, .func = ð_cmd_iperf, .argtable = &iperf_args }; ESP_ERROR_CHECK(esp_console_cmd_register(&iperf_cmd)); }
void test_loop(void* arg) { ESP_ERROR_CHECK( gpio_set_direction(GPIO_NUM_22, GPIO_MODE_OUTPUT) ); ESP_ERROR_CHECK( gpio_set_level(GPIO_NUM_22, 0) ); while (1) { /* Block for 500ms. */ const TickType_t xDelay = 10 / portTICK_PERIOD_MS; vTaskDelay(xDelay); gpio_set_level(GPIO_NUM_22, true); vTaskDelay(xDelay); gpio_set_level(GPIO_NUM_22, false); } }
int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf, lws_filepos_t *amount) { nvs_handle nvh; size_t s; int n = 0; ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh)); if (nvs_get_blob(nvh, filename, NULL, &s) != ESP_OK) { n = 1; goto bail; } *buf = lws_malloc(s, "alloc_file"); if (!*buf) { n = 2; goto bail; } if (nvs_get_blob(nvh, filename, (char *)*buf, &s) != ESP_OK) { lws_free(*buf); n = 1; goto bail; } *amount = s; bail: nvs_close(nvh); return n; }
void app_main() { // Initialize NVS. esp_err_t err = nvs_flash_init(); if (err == ESP_ERR_NVS_NO_FREE_PAGES) { // OTA app partition table has a smaller NVS partition size than the non-OTA // partition table. This size mismatch may cause NVS initialization to fail. // If this happens, we erase NVS partition and initialize NVS again. ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } ESP_ERROR_CHECK( err ); initialise_wifi(); xTaskCreate(&ota_example_task, "ota_example_task", 8192, NULL, 5, NULL); }
void app_main(void) { ESP_ERROR_CHECK( nvs_flash_init() ); wifi_conn_init(); xTaskCreate(coap_example_thread, "coap", 1024 * 5, NULL, 5, NULL); }