feat(hello_world): add example hello_world from esp-idf and modify it for ESP8266

Commit ID: b0456cc9
This commit is contained in:
dongheng
2019-07-26 11:24:03 +08:00
parent 0193d06019
commit cc267ab0df
30 changed files with 113 additions and 120 deletions

33
examples/README.md Normal file
View File

@ -0,0 +1,33 @@
# Examples
This directory contains a range of example ESP8266_RTOS_SDK projects. These are intended to demonstrate parts of ESP8266_RTOS_SDK functionality, and to provide code that you can copy and adapt into your own projects.
# Example Layout
The examples are grouped into subdirectories by category. Each category directory contains one or more example projects:
* `get-started` contains some very simple examples with minimal functionality.
* `peripherals` contains examples showing driver functionality for the various onboard ESP8266 peripherals.
* `protocols` contains examples showing network protocol interactions.
* `provisioning` contains examples showing how to configurate target AP information to ESP8266.
* `storage` contains examples showing data storage methods using SPI flash.
* `system` contains examples which demonstrate some debugging, factory-test and OTA.
* `wifi` contains examples of advanced Wi-Fi features. (For network protocol examples, see `protocols` instead.)
# Using Examples
Building an example is the same as building any other project:
* Follow the Getting Started instructions which include building the "Hello World" example.
* Change into the directory of the new example you'd like to build.
* Run `make menuconfig` to open the project configuration menu. Most examples have a project-specific "Example Configuration" section here (for example, to set the WiFi SSID & password to use).
* `make` to build the example.
* Follow the printed instructions to flash, or run `make flash`.
# Copying Examples
Each example is a standalone project. The examples *do not have to be inside the SDK directory*. You can copy an example directory to anywhere on your computer in order to make a copy that you can modify and work with.
The `IDF_PATH` environment variable is the only thing that connects the example to the rest of ESP8266_RTOS_SDK.
If you're looking for a more bare-bones project to start from, try [esp-idf-template](https://github.com/espressif/esp-idf-template).

View File

@ -0,0 +1,6 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(hello-world)

View File

@ -3,7 +3,7 @@
# project subdirectory.
#
PROJECT_NAME := project_template
PROJECT_NAME := hello-world
include $(IDF_PATH)/make/project.mk

View File

@ -0,0 +1,5 @@
# Hello World Example
Starts a FreeRTOS task to print "Hello World"
See the README.md file in the upper level 'examples' directory for more information about examples.

View File

@ -0,0 +1,2 @@
idf_component_register(SRCS "hello_world_main.c"
INCLUDE_DIRS "")

View File

@ -0,0 +1,38 @@
/* Hello World Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
void app_main()
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
printf("This is ESP8266 chip with %d CPU cores, WiFi, ",
chip_info.cores);
printf("silicon revision %d, ", chip_info.revision);
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
for (int i = 10; i >= 0; i--) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
}

View File

@ -1,6 +0,0 @@
# The following four lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(project_template)

View File

@ -1,3 +0,0 @@
set(COMPONENT_SRCDIRS "folder1" "folder2")
register_component()

View File

@ -1 +0,0 @@
COMPONENT_SRCDIRS := folder1 folder2

View File

@ -1,3 +0,0 @@
set(COMPONENT_SRCS "user_main.c")
register_component()

View File

@ -1,22 +0,0 @@
/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "esp_system.h"
/******************************************************************************
* FunctionName : app_main
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void app_main(void)
{
printf("SDK version:%s\n", esp_get_idf_version());
}

View File

@ -1,56 +0,0 @@
This is a simple project template.
sample_lib is an example for multi-level folder Makefile, notice the folder structure and each Makefile, you can get the clue.
HOWTO:
1. Copy this folder to anywhere.
Example:
Copy to ~/workspace/project_template
You can rename this folder as you like.
2. Export SDK_PATH and BIN_PATH.
Example:
Your SDK path is ~/esp_iot_rtos_sdk, and want generate bin at ~/esp8266_bin.
Do follow steps:
1>. export SDK_PATH=~/esp_iot_rtos_sdk
2>. export BIN_PATH=~/esp8266_bin
SDK and project are seperate, you can update SDK without change your project.
3. Enter project_template folder, run ./gen_misc.sh, and follow the tips and steps.
Compile Options:
(1) COMPILE
Possible value: xcc
Default value:
If not set, use gcc by default.
(2) BOOT
Possible value: none/old/new
none: no need boot
old: use boot_v1.1
new: use boot_v1.2
Default value: new
(3) APP
Possible value: 0/1/2
0: original mode, generate eagle.app.v6.flash.bin and eagle.app.v6.irom0text.bin
1: generate user1
2: generate user2
Default value: 0
(3) SPI_SPEED
Possible value: 20/26.7/40/80
Default value: 40
(4) SPI_MODE
Possible value: QIO/QOUT/DIO/DOUT
Default value: QIO
(4) SPI_SIZE_MAP
Possible value: 0/2/3/4/5/6
Default value: 0
For example:
make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=0

View File

@ -136,7 +136,7 @@ When the example starts up, it will print "ota: Starting OTA example..." then:
* Check whether your PC can ping the ESP8266 at its IP, and make sure that the IP, AP and other configuration settings are correct in menuconfig.
* Check if there is any firewall software on the PC that prevents incoming connections.
* Check whether you can see the configured file (default project_template.ota.bin) when browsing the file listing at http://127.0.0.1/
* Check whether you can see the configured file (default hello_world.ota.bin) when browsing the file listing at http://127.0.0.1/
* If you have another PC or a phone, try viewing the file listing from the separate host.
## Error "ota_begin error err=0x104"

View File

@ -32,7 +32,7 @@ config SERVER_PORT
config EXAMPLE_FILENAME
string "HTTP GET Filename"
default "/project_template.bin"
default "/hello_world.bin"
help
Filename of the app image file to download for
the OTA update.

View File

@ -146,7 +146,7 @@ When the example starts up, it will print "ota: Starting OTA example..." then:
* Check whether your PC can ping the ESP8266 at its IP, and make sure that the IP, AP and other configuration settings are correct in menuconfig.
* Check if there is any firewall software on the PC that prevents incoming connections.
* Check whether you can see the configured file (default project_template.ota.bin) when browsing the file listing at http://127.0.0.1/
* Check whether you can see the configured file (default hello_world.ota.bin) when browsing the file listing at http://127.0.0.1/
* If you have another PC or a phone, try viewing the file listing from the separate host.
## Error "ota_begin error err=0x104"

View File

@ -32,7 +32,7 @@ config SERVER_PORT
config EXAMPLE_FILENAME
string "HTTP GET Filename"
default "/project_template.bin"
default "/hello_world.bin"
help
Filename of the app image file to download for
the OTA update.

View File

@ -159,7 +159,7 @@ When the example starts up, it will print "ota: Starting OTA example..." then:
* Check whether your PC can ping the ESP8266 at its IP, and make sure that the IP, AP and other configuration settings are correct in menuconfig.
* Check if there is any firewall software on the PC that prevents incoming connections.
* Check whether you can see the configured file (default project_template.ota.bin) when browsing the file listing at http://127.0.0.1/
* Check whether you can see the configured file (default hello_world.ota.bin) when browsing the file listing at http://127.0.0.1/
* If you have another PC or a phone, try viewing the file listing from the separate host.
## Error "ota_begin error err=0x104"

View File

@ -40,7 +40,7 @@ config SERVER_PORT
config EXAMPLE_FILENAME
string "HTTP GET Filename"
default "/project_template.ota.bin"
default "/hello_world.ota.bin"
help
Filename of the app image file to download for
the OTA update.

View File

@ -127,7 +127,7 @@ When the example starts up, it will print "ota: Starting OTA example..." then:
* Check whether your PC can ping the ESP8266 at its IP, and make sure that the IP, AP and other configuration settings are correct in menuconfig.
* Check if there is any firewall software on the PC that prevents incoming connections.
* Check whether you can see the configured file (default project_template.ota.bin) when browsing the file listing at http://127.0.0.1/
* Check whether you can see the configured file (default hello_world.ota.bin) when browsing the file listing at http://127.0.0.1/
* If you have another PC or a phone, try viewing the file listing from the separate host.
## Error "ota_begin error err=0x104"

View File

@ -32,7 +32,7 @@ config SERVER_PORT
config EXAMPLE_FILENAME
string "HTTP GET Filename"
default "/project_template.bin"
default "/hello_world.bin"
help
Filename of the app image file to download for
the OTA update.

View File

@ -151,7 +151,7 @@ When the example starts up, it will print "ota: Starting OTA example..." then:
* Check whether your PC can ping the ESP8266 at its IP, and make sure that the IP, AP and other configuration settings are correct in menuconfig.
* Check if there is any firewall software on the PC that prevents incoming connections.
* Check whether you can see the configured file (default project_template.ota.bin) when browsing the file listing at http://127.0.0.1/
* Check whether you can see the configured file (default hello_world.ota.bin) when browsing the file listing at http://127.0.0.1/
* If you have another PC or a phone, try viewing the file listing from the separate host.
## Error "ota_begin error err=0x104"

View File

@ -40,7 +40,7 @@ config SERVER_PORT
config EXAMPLE_FILENAME
string "HTTP GET Filename"
default "/project_template.ota.bin"
default "/hello_world.ota.bin"
help
Filename of the app image file to download for
the OTA update.

View File

@ -31,17 +31,17 @@ The OTA_workflow.png diagram demonstrates the overall workflow:
Connect your host PC to the same AP that you will use for the ESP8266.
### Step 2: Generate the OTA Binary
For our upgrade example OTA file, we're going to use the `get-started/project_template` example.
For our upgrade example OTA file, we're going to use the `get-started/hello_world` example.
Build the example:
```
cd $IDF_PATH/examples/get-started/project_template
cd $IDF_PATH/examples/get-started/hello_world
make
cd build
```
Note: You've probably noticed there is nothing special about the "project_template" example when used for OTA updates. This is because any .bin app file which is built by ESP8266_RTOS_SDK can be used as an app image for OTA. The only difference is whether it is written to a factory partition or an OTA partition.
Note: You've probably noticed there is nothing special about the "hello_world" example when used for OTA updates. This is because any .bin app file which is built by ESP8266_RTOS_SDK can be used as an app image for OTA. The only difference is whether it is written to a factory partition or an OTA partition.
### Step 3: Run HTTPS Server
@ -69,7 +69,7 @@ Start the HTTPS server:
openssl s_server -WWW -key ca_key.pem -cert ca_cert.pem -port 8070
```
Copy the generated binary(project_template.bin) into the folder in which the HTTPS server is running.
Copy the generated binary(hello_world.bin) into the folder in which the HTTPS server is running.
If you have any firewall software running that will block incoming access to port 8070, configure it to allow access while running the example.
### Step 4: Build OTA Example
@ -83,7 +83,7 @@ Change back to the OTA example directory, and type `make menuconfig` to configur
https://<host-ip-address>:<host-port>/<firmware-image-filename>
for e.g,
https://192.168.0.3:8070/project_template.bin
https://192.168.0.3:8070/hello_world.bin
```
Save your changes, and type `make` to build the example.
@ -112,7 +112,7 @@ When the example starts up, it will print "Starting OTA example..." then:
* Check your PC can ping the ESP8266 at its IP, and that the IP, AP and other configuration settings are correct in menuconfig.
* Check if any firewall software is preventing incoming connections on the PC.
* Check whether you can see the configured file (default project_template.bin), by checking the output of following command:
* Check whether you can see the configured file (default hello_world.bin), by checking the output of following command:
```
curl -v https://<host-ip-address>:<host-port>/<firmware-image-filename>