#include "driver/uart.h"
#include "espconn.h" void ICACHE_FLASH_ATTR
user_rf_pre_init(void){} struct espconn user_udp_espconn; ETSTimer connect_timer;
ETSTimer test_timer; //udp发送函数
void ICACHE_FLASH_ATTR user_udp_send(void *data)
{
char yladdr[6] = {0};
char DeviceBuffer[40] = {0};//将获取的MAC地址格式化输出到一个buffer里面 os_printf("正在发送...\r\n"); wifi_get_macaddr(STATION_IF, yladdr);//查询MAC地址
os_sprintf(DeviceBuffer,"设备地址为:"MACSTR"\r\n", MAC2STR(yladdr));//格式化MAC地址
espconn_sent(&user_udp_espconn, DeviceBuffer, os_strlen(DeviceBuffer));
} //udp发送回调
void ICACHE_FLASH_ATTR user_udp_sent_cb(void *arg)
{
os_timer_disarm(&test_timer);
os_timer_setfn(&test_timer, user_udp_send, NULL);
os_timer_arm(&test_timer, 1000, 0);//1秒钟发送一次
} //udp接收回调
void ICACHE_FLASH_ATTR user_udp_recv_cb(void *arg,
char *pdata,
unsigned short len)
{
os_printf("UDP已经接收数据:%s", pdata);
} //创建UDP连接
void ICACHE_FLASH_ATTR wifi_conned(void *arg)
{
uint8 status = 0;
static uint8 count = 0; count++;
os_timer_disarm(&connect_timer); status = wifi_station_get_connect_status();
if(status == STATION_GOT_IP)
{
wifi_set_broadcast_if(STATIONAP_MODE); //设置UDP广播的发送接口
user_udp_espconn.type = ESPCONN_UDP;
user_udp_espconn.proto.udp = (esp_udp*)os_zalloc(sizeof(esp_udp));
user_udp_espconn.proto.udp->local_port = 2525;
user_udp_espconn.proto.udp->remote_port = 1112; const char udp_remote_ip[] = {255,255,255,255}; //用于存放远程IP地址
os_memcpy(&user_udp_espconn.proto.udp->remote_ip, udp_remote_ip, sizeof(udp_remote_ip)); espconn_regist_recvcb(&user_udp_espconn, user_udp_recv_cb); //接收回调函数
espconn_regist_sentcb(&user_udp_espconn, user_udp_sent_cb); //发送回调函数
espconn_create(&user_udp_espconn); //创建UDP连接
user_udp_send(NULL); return;
}
else
{
if(count >= 7)
{
os_printf("wifi连接失败!");
return;
}
} os_timer_arm(&connect_timer, 2000, 0);
} //加入当前可用wiff
void ICACHE_FLASH_ATTR scan_done(void *arg, STATUS status)
{
char ssid[] = "Feixun_1003";
char password[] = "12345678";
struct station_config stationConf = {0}; if (status == OK)
{
os_memcpy(&stationConf.ssid, ssid, os_strlen(ssid)); //加入当前可用wiff
os_memcpy(&stationConf.password, password, os_strlen(password)); //密码
wifi_station_set_config_current(&stationConf);
wifi_station_connect();
os_timer_setfn(&connect_timer, wifi_conned, NULL);
os_timer_arm(&connect_timer, 2000, 0);
}
} void to_scan(void)
{
wifi_station_scan(NULL, scan_done); return;
} //配置ESP8266
void user_init()
{
struct softap_config config = {0};
char ssid[] = "ESP8266";
char password[] = "12345678"; uart_init(BIT_RATE_115200, BIT_RATE_115200);
os_delay_us(60000); wifi_set_opmode(STATIONAP_MODE); wifi_softap_get_config(&config); config.ssid_len = os_strlen(ssid);
os_memset(config.ssid, 0, sizeof(config.ssid));
os_memcpy(config.ssid, ssid, config.ssid_len);
os_memset(config.password, 0, sizeof(config.password));
os_memcpy(config.password, password, os_strlen(password)); wifi_softap_set_config(&config); system_init_done_cb(to_scan); return;
}



ESP8266 UDP通信的更多相关文章

  1. 高性能 TCP & UDP 通信框架 HP-Socket v3.5.3

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  2. 高性能 TCP & UDP 通信框架 HP-Socket v3.5.2

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  3. 高性能 TCP & UDP 通信框架 HP-Socket v3.5.1

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  4. 高性能 TCP & UDP 通信框架 HP-Socket v3.4.1

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  5. 高性能 TCP & UDP 通信框架 HP-Socket v3.3.1

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  6. HP-SOCKET TCP/UDP通信框架库解析

    项目概述: HP-SOCKET是一套通用TCP/UDP通信框架,包括服务器.客户端.Agent组件:其目标是提供高性能.通用性.简易性.可扩展.可定制: 鉴于此,其仅实现基本的通用框架通信.数据收发功 ...

  7. .Net开发笔记(十四) 基于“泵”的UDP通信(接上篇)

    上一篇中说到了“泵”在编程中的作用以及一些具体用处,但没有实际demo,可能不好理解,这篇文章我分享一个UDP通信的demo,大概实现了类似“飞鸽传书”在局域网中文本消息和文件传输的功能.功能不全也不 ...

  8. 高性能 TCP & UDP 通信框架 HP-Socket v3.2.3

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

  9. 高性能 TCP & UDP 通信框架 HP-Socket v3.2.2 正式发布

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#.Del ...

随机推荐

  1. ubuntu18 bluebooth

    QDBusPendingReply: type ManagedObjectList is not registered with QtDBus 19:36:14: The program has un ...

  2. Matplotlib数据可视化基础

    import numpy as np import matplotlib.pyplot as plt ## %matplotlib inline表示在行中显示图片,在命令行运行报错 data = np ...

  3. 二分类Logistic回归模型

    Logistic回归属于概率型的非线性回归,分为二分类和多分类的回归模型.这里只讲二分类. 对于二分类的Logistic回归,因变量y只有“是.否”两个取值,记为1和0.这种值为0/1的二值品质型变量 ...

  4. nrpe command

    1. nrpe 连接问题: 报错:/usr/local/nagios/libexec/check_nrpe  -H  destip   ;   CHECK_NRPE: Error - Could no ...

  5. 【并行计算与CUDA开发】英伟达硬件加速解码器在 FFMPEG 中的使用

    目录(?)[-] 私有驱动 编译 FFMPEG 使用 nvenc 这篇文档介绍如何在 ffmpeg 中使用 nvenc 硬件编码器. 私有驱动 nvenc 本身是依赖于 nvidia 底层的私有驱动的 ...

  6. VS.vs15

    1.20190615 安装的 vs2015(cn_visual_studio_enterprise_2015_with_update_3_x86_x64_dvd_8923298.iso) 的目录为: ...

  7. spring boot工程如何启用 热启动功能

    1.在pom.xml里面添加一个依赖即可 关键代码 <dependency> <groupId>org.springframework.boot</groupId> ...

  8. 真理胜于一切 JAVA模拟表单提交

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  9. 记2017年年底,几次Python后端面试

    1. 果壳 电话面试: 说一下TCP的三次握手,四次挥手,为什么会这样? http安全的性的了解,说一下对cookie和session的了解: 对mysql的了解,说一下你常用的数据类型,char和v ...

  10. c# base64及MD5工具类

    using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Lin ...