mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-22 01:27:11 +08:00
feat(hello_world): add example hello_world from esp-idf and modify it for ESP8266
Commit ID: b0456cc9
This commit is contained in:
@ -71,7 +71,7 @@ export IDF_PATH=~/esp/ESP8266_RTOS_SDK
|
||||
```
|
||||
|
||||
## Start a Project
|
||||
Now you are ready to prepare your application for ESP8266. To start off quickly, we can use `examples/get-started/project_template` project from `examples` directory in SDK.
|
||||
Now you are ready to prepare your application for ESP8266. To start off quickly, we can use `examples/get-started/hello_world` project from `examples` directory in SDK.
|
||||
|
||||
Once you've found the project you want to work with, change to its directory and you can configure and build it.
|
||||
|
||||
@ -81,10 +81,10 @@ You are almost there. To be able to proceed further, connect ESP8266 board to PC
|
||||
|
||||
## Configuring the Project
|
||||
|
||||
Being in terminal window, go to directory of `project_template` application by typing `cd ~/esp/ESP8266_RTOS_SDK/examples/get-started/project_template`. Then start project configuration utility `menuconfig`:
|
||||
Being in terminal window, go to directory of `hello_world` application by typing `cd ~/esp/ESP8266_RTOS_SDK/examples/get-started/hello_world`. Then start project configuration utility `menuconfig`:
|
||||
|
||||
```
|
||||
cd ~/esp/ESP8266_RTOS_SDK/examples/get-started/project_template
|
||||
cd ~/esp/ESP8266_RTOS_SDK/examples/get-started/hello_world
|
||||
make menuconfig
|
||||
```
|
||||
|
||||
|
@ -7,7 +7,7 @@ concept of "components"
|
||||
Read this document if you want to know how to organise a new ESP8266\_RTOS\
|
||||
-SDK (ESP-IDF Style) project.
|
||||
|
||||
We recommend using the project_template project at directory of examples/get-started as a starting point for your project.
|
||||
We recommend using the hello_world project at directory of examples/get-started as a starting point for your project.
|
||||
|
||||
Using the Build System
|
||||
======================
|
||||
|
@ -111,7 +111,7 @@ Configure the flash size according to your actual development board's flash.
|
||||
(mypassword) WiFi Password
|
||||
(192.168.0.3) HTTP Server IP
|
||||
(8070)HTTP Server Port
|
||||
(/project_template.ota.bin) HTTP GET Filename
|
||||
(/hello_world.ota.bin) HTTP GET Filename
|
||||
|
||||
- WiFi SSID: Wi-Fi SSID of router
|
||||
- WiFi Password: Wi-Fi password of router
|
||||
|
@ -144,12 +144,12 @@ Python packages required by ESP8266\_RTOS\_SDK are located in the ``$IDF_PATH/re
|
||||
Start a Project
|
||||
===============
|
||||
|
||||
Now you are ready to prepare your application for ESP8266. To start off quickly, we will use :example:`get-started/project_template` project from :idf:`examples` directory in IDF.
|
||||
Now you are ready to prepare your application for ESP8266. To start off quickly, we will use :example:`get-started/hello_world` project from :idf:`examples` directory in IDF.
|
||||
|
||||
Copy :example:`get-started/project_template` to ``~/esp`` directory::
|
||||
Copy :example:`get-started/hello_world` to ``~/esp`` directory::
|
||||
|
||||
cd ~/esp
|
||||
cp -r $IDF_PATH/examples/get-started/project_template .
|
||||
cp -r $IDF_PATH/examples/get-started/hello_world .
|
||||
|
||||
You can also find a range of example projects under the :idf:`examples` directory in ESP-IDF. These example project directories can be copied in the same way as presented above, to begin your own projects.
|
||||
|
||||
@ -171,9 +171,9 @@ You are almost there. To be able to proceed further, connect ESP8266 board to PC
|
||||
Configure
|
||||
=========
|
||||
|
||||
Being in terminal window, go to directory of ``project_template`` application by typing ``cd ~/esp/project_template``. Then start project configuration utility ``menuconfig``::
|
||||
Being in terminal window, go to directory of ``hello_world`` application by typing ``cd ~/esp/hello_world``. Then start project configuration utility ``menuconfig``::
|
||||
|
||||
cd ~/esp/project_template
|
||||
cd ~/esp/hello_world
|
||||
make menuconfig
|
||||
|
||||
If previous steps have been done correctly, the following menu will be displayed:
|
||||
@ -245,7 +245,7 @@ This will compile the application and all the ESP8266\_RTOS\_SDK components, gen
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
|
||||
If there are no issues, at the end of build process, you should see messages describing progress of loading process. Finally, the end module will be reset and "project_template" application will start.
|
||||
If there are no issues, at the end of build process, you should see messages describing progress of loading process. Finally, the end module will be reset and "hello_world" application will start.
|
||||
|
||||
If you'd like to use the Eclipse IDE instead of running ``make``, check out the :doc:`Eclipse guide <eclipse-setup>`.
|
||||
|
||||
@ -255,7 +255,7 @@ If you'd like to use the Eclipse IDE instead of running ``make``, check out the
|
||||
Monitor
|
||||
=======
|
||||
|
||||
To see if "project_template" application is indeed running, type ``make monitor``.
|
||||
To see if "hello_world" application is indeed running, type ``make monitor``.
|
||||
|
||||
$ make monitor
|
||||
MONITOR
|
||||
|
33
examples/README.md
Normal file
33
examples/README.md
Normal 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).
|
6
examples/get-started/hello_world/CMakeLists.txt
Normal file
6
examples/get-started/hello_world/CMakeLists.txt
Normal 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)
|
@ -3,7 +3,7 @@
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := project_template
|
||||
PROJECT_NAME := hello-world
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
5
examples/get-started/hello_world/README.md
Normal file
5
examples/get-started/hello_world/README.md
Normal 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.
|
2
examples/get-started/hello_world/main/CMakeLists.txt
Normal file
2
examples/get-started/hello_world/main/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "hello_world_main.c"
|
||||
INCLUDE_DIRS "")
|
38
examples/get-started/hello_world/main/hello_world_main.c
Normal file
38
examples/get-started/hello_world/main/hello_world_main.c
Normal 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();
|
||||
}
|
@ -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)
|
@ -1,3 +0,0 @@
|
||||
set(COMPONENT_SRCDIRS "folder1" "folder2")
|
||||
|
||||
register_component()
|
@ -1 +0,0 @@
|
||||
COMPONENT_SRCDIRS := folder1 folder2
|
@ -1,3 +0,0 @@
|
||||
set(COMPONENT_SRCS "user_main.c")
|
||||
|
||||
register_component()
|
@ -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());
|
||||
}
|
@ -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
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user