|
ESP8266 之OTA升級學(xué)習(xí)源碼,原創(chuàng),可以自己學(xué)習(xí)用也可以改,分享給大家!
單片機(jī)源程序如下:
- /* main.c -- MQTT client example
- *
- * Copyright (c) 2014-2015, Tuan PM <tuanpm at live dot com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Redis nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
- #include "ets_sys.h"
- #include "driver/uart.h"
- #include "osapi.h"
- //#include "wifi.h"
- #include "config.h"
- #include "gpio.h"
- #include "user_interface.h"
- #include "mem.h"
- #include "../iotserver/include/user_net.h"
- void wifiConnectCb(uint8_t status)
- {
- //tcp服務(wù)器
- if(status == STATION_GOT_IP)
- {
- if(mDebug)
- {
- at_port_print("Connect to TCP Server\r\n");
- }
- connect_tcp_server();
- }
- else
- {
- disconnect_tcp_server();
- }
- }
- /******************************************************************************
- * FunctionName : user_rf_cal_sector_set
- * Description : SDK just reversed 4 sectors, used for rf init data and paramters.
- * We add this function to force users to set rf cal sector, since
- * we don't know which sector is free in user's application.
- * sector map for last several sectors : ABCCC
- * A : rf cal
- * B : rf init data
- * C : sdk parameters
- * Parameters : none
- * Returns : rf cal sector
- *******************************************************************************/
- uint32 ICACHE_FLASH_ATTR
- user_rf_cal_sector_set(void)
- {
- enum flash_size_map size_map = system_get_flash_size_map();
- uint32 rf_cal_sec = 0;
- switch (size_map) {
- case FLASH_SIZE_4M_MAP_256_256:
- rf_cal_sec = 128 - 5;
- break;
- case FLASH_SIZE_8M_MAP_512_512:
- rf_cal_sec = 256 - 5;
- break;
- case FLASH_SIZE_16M_MAP_512_512:
- case FLASH_SIZE_16M_MAP_1024_1024:
- rf_cal_sec = 512 - 5;
- break;
- case FLASH_SIZE_32M_MAP_512_512:
- case FLASH_SIZE_32M_MAP_1024_1024:
- rf_cal_sec = 1024 - 5;
- break;
- case FLASH_SIZE_64M_MAP_1024_1024:
- rf_cal_sec = 2048 - 5;
- break;
- case FLASH_SIZE_128M_MAP_1024_1024:
- rf_cal_sec = 4096 - 5;
- break;
- default:
- rf_cal_sec = 0;
- break;
- }
- return rf_cal_sec;
- }
- void user_init(void)
- {
- //此例子完全開源,某些作者還需要打賞,這個(gè)完全是根據(jù)樂鑫的官方例子的改進(jìn)的,需要商用版的請聯(lián)系
- BOOL bRet = FALSE;
- char buffer[20] = {0};
- uart_init(BIT_RATE_115200, BIT_RATE_115200);//jay lee 20180228 波特率
- os_delay_us(60000);
- user_net_init(wifiConnectCb);
- }
復(fù)制代碼
所有資料51hei提供下載:
ESP8266_OTA_LEXIN.7z
(2.13 MB, 下載次數(shù): 10)
2019-12-8 14:25 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|