找回密码
 立即注册

QQ登录

只需一步,快速开始

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

ESP8266手机TCP&UDP调试助手与USR-TCP232-Test下载

[复制链接]
跳转到指定楼层
楼主
ESP8266 手机调试助手


包含手机TCP&UDP调试助手.apk与USR-TCP232-Test.exe

全部资料51hei下载地址:
手机调试助手.rar (3.93 MB, 下载次数: 56)



esp_iot_sdk(完整,还差模块从调试助手获得数据传给手机)源程序如下:
  1. /******************************************************************************
  2. * Copyright 2013-2014 Espressif Systems (Wuxi)
  3. *
  4. * FileName: user_main.c
  5. *
  6. * Description: entry file of user application
  7. *
  8. * Modification history:
  9. *     2014/1/1, v1.0 create this file.
  10. *******************************************************************************/
  11. #include "ets_sys.h"

  12. #include "user_interface.h"

  13. #include "user_devicefind.h"
  14. //#include "user_webserver.h"

  15. #include "version.h"

  16. #include "espmissingincludes.h"
  17. #include "osapi.h"
  18. #include "driver/uart.h"

  19. //#if ESP_PLATFORM
  20. //#include "user_esp_platform.h"
  21. //#endif

  22. #ifdef SERVER_SSL_ENABLE
  23. #include "ssl/cert.h"
  24. #include "ssl/private_key.h"
  25. #else
  26. #ifdef CLIENT_SSL_ENABLE
  27. unsigned char *default_certificate;
  28. unsigned int default_certificate_len = 0;
  29. unsigned char *default_private_key;
  30. unsigned int default_private_key_len = 0;
  31. #endif
  32. #endif

  33. #include "user_smartconfig.h"
  34. #include "driver/uart.h"

  35. #include "espconn.h"
  36. #include "mem.h"

  37. #define NET_DOMAIN "cn点bing点com.sherry"
  38. #define pheadbuffer "GET / HTTP/1.1\r\nUser-Agent: curl/7.37.0\r\nHost: %s\r\nAccept: */*\r\n\r\n"
  39. #define INTRODUCTION "connect succeed!I am ESP8266!"


  40. #define packet_size   (2 * 1024)
  41. #define MY_SSID "miwalk_office"
  42. #define MY_PASSWORD "cqmyg14dss.miwalk"

  43. LOCAL os_timer_t test_timer;
  44. LOCAL struct espconn user_tcp_conn;
  45. LOCAL struct _esp_tcp user_tcp;
  46. ip_addr_t tcp_server_ip;



  47. /******************************************************************************
  48. * FunctionName : user_tcp_recv_cb
  49. * Description  : receive callback.
  50. * Parameters   : arg -- Additional argument to pass to the callback function
  51. * Returns      : none
  52. *******************************************************************************/
  53. LOCAL void ICACHE_FLASH_ATTR
  54. user_tcp_recv_cb(void *arg, char *pusrdata, unsigned short length)
  55. {
  56.    //received some data from tcp connection

  57.     //os_printf("tcp recv !!! %s \r\n", pusrdata);   //init command
  58.     os_printf("server: %s \r\n", pusrdata);

  59.     //sherry add below
  60.     struct espconn *pesp_conn = arg;

  61.            remot_info *premot = NULL;
  62.            sint8 value = ESPCONN_OK;
  63.            if (espconn_get_connection_info(pesp_conn,&premot,0) == ESPCONN_OK){
  64.                  pesp_conn->proto.tcp->remote_port = premot->remote_port;
  65.                  pesp_conn->proto.tcp->remote_ip[0] = premot->remote_ip[0];
  66.                  pesp_conn->proto.tcp->remote_ip[1] = premot->remote_ip[1];
  67.                  pesp_conn->proto.tcp->remote_ip[2] = premot->remote_ip[2];
  68.                  pesp_conn->proto.tcp->remote_ip[3] = premot->remote_ip[3];
  69.                  espconn_sent(pesp_conn , "\r\n me: " , os_strlen("\r\n me: "));
  70.                  espconn_sent(pesp_conn , pusrdata , os_strlen(pusrdata));
  71.            }


  72. }
  73. /******************************************************************************
  74. * FunctionName : user_tcp_sent_cb
  75. * Description  : data sent callback.
  76. * Parameters   : arg -- Additional argument to pass to the callback function
  77. * Returns      : none
  78. *******************************************************************************/
  79. LOCAL void ICACHE_FLASH_ATTR
  80. user_tcp_sent_cb(void *arg)
  81. {
  82. }
  83. /******************************************************************************
  84. * FunctionName : user_tcp_discon_cb
  85. * Description  : disconnect callback.
  86. * Parameters   : arg -- Additional argument to pass to the callback function
  87. * Returns      : none
  88. *******************************************************************************/
  89. LOCAL void ICACHE_FLASH_ATTR
  90. user_tcp_discon_cb(void *arg)
  91. {
  92.    //tcp disconnect successfully

  93.     os_printf("tcp disconnect succeed !!! \r\n");
  94. }
  95. /******************************************************************************
  96. * FunctionName : user_esp_platform_sent
  97. * Description  : Processing the application data and sending it to the host
  98. * Parameters   : pespconn -- the espconn used to connetion with the host
  99. * Returns      : none
  100. *******************************************************************************/
  101. LOCAL void ICACHE_FLASH_ATTR
  102. user_sent_data(struct espconn *pespconn)
  103. {
  104.     char *pbuf = (char *)os_zalloc(packet_size);
  105.     os_sprintf(pbuf, INTRODUCTION);
  106.     espconn_sent(pespconn, pbuf, os_strlen(pbuf));
  107.     os_free(pbuf);

  108. }

  109. /******************************************************************************
  110. * FunctionName : user_tcp_connect_cb
  111. * Description  : A new incoming tcp connection has been connected.
  112. * Parameters   : arg -- Additional argument to pass to the callback function
  113. * Returns      : none
  114. *******************************************************************************/
  115. LOCAL void ICACHE_FLASH_ATTR
  116. user_tcp_connect_cb(void *arg)
  117. {
  118.     struct espconn *pespconn = arg;

  119.     os_printf("connect succeed !!! \r\n");

  120.     espconn_regist_recvcb(pespconn, user_tcp_recv_cb);
  121.     espconn_regist_sentcb(pespconn, user_tcp_sent_cb);
  122.    espconn_regist_disconcb(pespconn, user_tcp_discon_cb);

  123.     user_sent_data(pespconn);
  124. }

  125. /******************************************************************************
  126. * FunctionName : user_tcp_recon_cb
  127. * Description  : reconnect callback, error occured in TCP connection.
  128. * Parameters   : arg -- Additional argument to pass to the callback function
  129. * Returns      : none
  130. *******************************************************************************/
  131. LOCAL void ICACHE_FLASH_ATTR
  132. user_tcp_recon_cb(void *arg, sint8 err)
  133. {
  134.    //error occured , tcp connection broke. user can try to reconnect here.

  135.     os_printf("reconnect callback, error code %d !!! \r\n",err);
  136. }

  137. #ifdef DNS_ENABLE
  138. /******************************************************************************
  139. * FunctionName : user_dns_found
  140. * Description  : dns found callback
  141. * Parameters   : name -- pointer to the name that was looked up.
  142. *                ipaddr -- pointer to an ip_addr_t containing the IP address of
  143. *                the hostname, or NULL if the name could not be found (or on any
  144. *                other error).
  145. *                callback_arg -- a user-specified callback argument passed to
  146. *                dns_gethostbyname
  147. * Returns      : none
  148. *******************************************************************************/
  149. LOCAL void ICACHE_FLASH_ATTR
  150. user_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
  151. {
  152.     struct espconn *pespconn = (struct espconn *)arg;

  153.     if (ipaddr == NULL)
  154.    {
  155.         os_printf("user_dns_found NULL \r\n");
  156.         return;
  157.     }

  158.    //dns got ip
  159.     os_printf("user_dns_found %d.%d.%d.%d \r\n",
  160.             *((uint8 *)&ipaddr->addr), *((uint8 *)&ipaddr->addr + 1),
  161.             *((uint8 *)&ipaddr->addr + 2), *((uint8 *)&ipaddr->addr + 3));

  162.     if (tcp_server_ip.addr == 0 && ipaddr->addr != 0)
  163.    {
  164.       // dns succeed, create tcp connection
  165.         os_timer_disarm(&test_timer);
  166.         tcp_server_ip.addr = ipaddr->addr;
  167.         os_memcpy(pespconn->proto.tcp->remote_ip, &ipaddr->addr, 4); // remote ip of tcp server which get by dns

  168.         pespconn->proto.tcp->remote_port = 80; // remote port of tcp server

  169.         pespconn->proto.tcp->local_port = espconn_port(); //local port of ESP8266

  170.         espconn_regist_connectcb(pespconn, user_tcp_connect_cb); // register connect callback
  171.         espconn_regist_reconcb(pespconn, user_tcp_recon_cb); // register reconnect callback as error handler

  172.         espconn_connect(pespconn); // tcp connect
  173.     }
  174. }

  175. /******************************************************************************
  176. * FunctionName : user_esp_platform_dns_check_cb
  177. * Description  : 1s time callback to check dns found
  178. * Parameters   : arg -- Additional argument to pass to the callback function
  179. * Returns      : none
  180. *******************************************************************************/
  181. LOCAL void ICACHE_FLASH_ATTR
  182. user_dns_check_cb(void *arg)
  183. {
  184.     struct espconn *pespconn = arg;

  185.     espconn_gethostbyname(pespconn, NET_DOMAIN, &tcp_server_ip, user_dns_found); // recall DNS function

  186.     os_timer_arm(&test_timer, 1000, 0);
  187. }
  188. #endif
  189. /******************************************************************************
  190. * FunctionName : user_check_ip
  191. * Description  : check whether get ip addr or not
  192. * Parameters   : none
  193. * Returns      : none
  194. *******************************************************************************/
  195. void ICACHE_FLASH_ATTR
  196. user_check_ip(void)
  197. {
  198.     struct ip_info ipconfig;

  199.    //disarm timer first
  200.     os_timer_disarm(&test_timer);

  201.    //get ip info of ESP8266 station
  202.     wifi_get_ip_info(STATION_IF, &ipconfig);

  203.     if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0)
  204.    {

  205.       os_printf("got ip !!! \r\n");

  206.       // Connect to tcp server as NET_DOMAIN
  207.       user_tcp_conn.proto.tcp = &user_tcp;
  208.       user_tcp_conn.type = ESPCONN_TCP;
  209.       user_tcp_conn.state = ESPCONN_NONE;

  210. #ifdef DNS_ENABLE
  211.       tcp_server_ip.addr = 0;
  212.        espconn_gethostbyname(&user_tcp_conn, NET_DOMAIN, &tcp_server_ip, user_dns_found); // DNS function

  213.        os_timer_setfn(&test_timer, (os_timer_func_t *)user_dns_check_cb, user_tcp_conn);
  214.        os_timer_arm(&test_timer, 1000, 0);
  215. #else

  216.         const char esp_tcp_server_ip[4] = {192, 168, 0, 153}; // remote IP of TCP server,

  217.        os_memcpy(user_tcp_conn.proto.tcp->remote_ip, esp_tcp_server_ip, 4);

  218.        user_tcp_conn.proto.tcp->remote_port = 1234;  // remote port

  219.        user_tcp_conn.proto.tcp->local_port = espconn_port(); //local port of ESP8266

  220.        espconn_regist_connectcb(&user_tcp_conn, user_tcp_connect_cb); // register connect callback
  221.        espconn_regist_reconcb(&user_tcp_conn, user_tcp_recon_cb); // register reconnect callback as error handler
  222.        espconn_connect(&user_tcp_conn);

  223. #endif
  224.     }
  225.    else
  226.    {

  227.         if ((wifi_station_get_connect_status() == STATION_WRONG_PASSWORD ||
  228.                 wifi_station_get_connect_status() == STATION_NO_AP_FOUND ||
  229.                 wifi_station_get_connect_status() == STATION_CONNECT_FAIL))
  230.         {
  231.          os_printf("connect fail !!! \r\n");
  232.         }
  233.       else
  234.       {
  235.            //re-arm timer to check ip
  236.             os_timer_setfn(&test_timer, (os_timer_func_t *)user_check_ip, NULL);
  237.             os_timer_arm(&test_timer, 100, 0);
  238.         }
  239.     }
  240. }


  241. /******************************************************************************
  242. * FunctionName : user_set_station_config
  243. * Description  : set the router info which ESP8266 station will connect to
  244. * Parameters   : none
  245. * Returns      : none
  246. *******************************************************************************/
  247. void ICACHE_FLASH_ATTR
  248. user_set_station_config(void)
  249. {
  250.    // Wifi configuration
  251.    char ssid[32] = MY_SSID;
  252.    char password[64] = MY_PASSWORD;
  253.    struct station_config stationConf;

  254.    os_memset(stationConf.ssid, 0, 32);
  255.    os_memset(stationConf.password, 0, 64);

  256.    //need not mac address
  257.    //stationConf.bssid_set = 0;

  258. ……………………

  259. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

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

使用道具 举报

沙发
ID:18591 发表于 2019-1-20 20:26 | 只看该作者
感謝~~~~~~~~~~~~~~~~~~~
回复

使用道具 举报

板凳
ID:761559 发表于 2020-5-26 13:26 | 只看该作者
多谢楼主分享
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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