找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2575|回复: 0
打印 上一主题 下一主题
收起左侧

ESP8266_OTA_LEXIN_学习版源码(原创)

[复制链接]
跳转到指定楼层
楼主
ID:229389 发表于 2019-12-8 09:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ESP8266 之OTA升级学习源码,原创,可以自己学习用也可以改,分享给大家!

单片机源程序如下:
  1. /* main.c -- MQTT client example
  2. *
  3. * Copyright (c) 2014-2015, Tuan PM <tuanpm at live dot com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Redis nor the names of its contributors may be used
  15. * to endorse or promote products derived from this software without
  16. * specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */


  30. #include "ets_sys.h"
  31. #include "driver/uart.h"
  32. #include "osapi.h"
  33. //#include "wifi.h"
  34. #include "config.h"
  35. #include "gpio.h"
  36. #include "user_interface.h"
  37. #include "mem.h"
  38. #include "../iotserver/include/user_net.h"



  39. void wifiConnectCb(uint8_t status)
  40. {
  41.         //tcp服务器
  42.                 if(status == STATION_GOT_IP)
  43.                 {
  44.                         if(mDebug)
  45.                         {
  46.                                 at_port_print("Connect to TCP Server\r\n");
  47.                         }
  48.                         connect_tcp_server();
  49.                 }
  50.                 else
  51.                 {
  52.                         disconnect_tcp_server();
  53.                 }

  54. }


  55. /******************************************************************************
  56. * FunctionName : user_rf_cal_sector_set
  57. * Description  : SDK just reversed 4 sectors, used for rf init data and paramters.
  58. *                We add this function to force users to set rf cal sector, since
  59. *                we don't know which sector is free in user's application.
  60. *                sector map for last several sectors : ABCCC
  61. *                A : rf cal
  62. *                B : rf init data
  63. *                C : sdk parameters
  64. * Parameters   : none
  65. * Returns      : rf cal sector
  66. *******************************************************************************/
  67. uint32 ICACHE_FLASH_ATTR
  68. user_rf_cal_sector_set(void)
  69. {
  70.     enum flash_size_map size_map = system_get_flash_size_map();
  71.     uint32 rf_cal_sec = 0;

  72.     switch (size_map) {
  73.         case FLASH_SIZE_4M_MAP_256_256:
  74.             rf_cal_sec = 128 - 5;
  75.             break;

  76.         case FLASH_SIZE_8M_MAP_512_512:
  77.             rf_cal_sec = 256 - 5;
  78.             break;

  79.         case FLASH_SIZE_16M_MAP_512_512:
  80.         case FLASH_SIZE_16M_MAP_1024_1024:
  81.             rf_cal_sec = 512 - 5;
  82.             break;

  83.         case FLASH_SIZE_32M_MAP_512_512:
  84.         case FLASH_SIZE_32M_MAP_1024_1024:
  85.             rf_cal_sec = 1024 - 5;
  86.             break;

  87.         case FLASH_SIZE_64M_MAP_1024_1024:
  88.             rf_cal_sec = 2048 - 5;
  89.             break;
  90.         case FLASH_SIZE_128M_MAP_1024_1024:
  91.             rf_cal_sec = 4096 - 5;
  92.             break;
  93.         default:
  94.             rf_cal_sec = 0;
  95.             break;
  96.     }

  97.     return rf_cal_sec;
  98. }


  99. void user_init(void)
  100. {
  101.         //此例子完全开源,某些作者还需要打赏,这个完全是根据乐鑫的官方例子的改进的,需要商用版的请联系
  102.         BOOL bRet = FALSE;
  103.         char buffer[20] = {0};
  104.         uart_init(BIT_RATE_115200, BIT_RATE_115200);//jay lee 20180228 波特率
  105.         os_delay_us(60000);
  106.         user_net_init(wifiConnectCb);
  107. }
复制代码

所有资料51hei提供下载:
ESP8266_OTA_LEXIN.7z (2.13 MB, 下载次数: 10)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表