初级会员
- 积分
- 53
- 金钱
- 53
- 注册时间
- 2015-5-3
- 在线时间
- 0 小时
|
5金钱
我想通过这个函数实现将ATK-RM04配置成AP模式下的TCP服务器。成为一个热点,但是虽然程序运行没有问题但是下载到miniSTM32板子上后,WiFi模块的参数没有配置成功。这个程序是在配套历程上修改的,所以有些头文件可能没有用到。水平低,还希望各位前辈勿喷。
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "led.h"
#include "lcd.h"
#include "key.h"
#include "usmart.h"
#include "malloc.h"
#include "ff.h"
#include "exfuns.h"
#include "text.h"
#include "common.h"
#include "touch.h"
#include "usart2.h"
const u8* portnum="8086";
const u8* wifiap_ssid="shiyan"; //对外SSID号
const u8* wifiap_encryption="wpawpa2_aes"; //wpa/wpa2 aes加密方式
const u8* wifiap_password="12345678"; //连接密码
const u8 *ATK_RM04_NETMODE_TBL[4]={" ROUTER ","ETH-COM ","WIFI-STA","WIFI-AP "}; //ATK-RM04,4种网络模式,默认为路由器(ROUTER)模式
const u8 *ATK_RM04_WORKMODE_TBL[4]={"TCP服务器","TCP客户端","UDP服务器","UDP客户端"}; //ATK-RM04,4种工作模式
void atk_rm04_init(void)
{
#if AT_MODE_CONFIG==0
RCC->APB2ENR|=1<<2; //PA时钟使能
GPIOA->CRL&=0XFFF0FFFF;
GPIOA->CRL|=3<<4*4; //PA4推挽输出
ES_CTRL=1; //PA4输出高
#endif
USART2_Init(36,115200); //初始化串口2
}
u8 atk_rm04_wifiap_test(void)
{
u8 netpro=0; //网络模式
//// u8 key;
// u8 timex=0;
// u8 ipbuf[16]; //IP缓存
u8 *p;
u16 t=999; //加速第一次获取链接状态
u8 res=0;
// u16 rlen=0;
// u8 constate=0; //连接状态
p=mymalloc(32); //申请32字节内存
atk_rm04_quit_trans();
atk_rm04_send_cmd("at+netmode=3","ok",500); //设置WIFI AP模式
atk_rm04_send_cmd("at+dhcpd=1","ok",500); //DHCP服务器开启(仅AP模式有效,默认路由器模式也有效)
atk_rm04_send_cmd("at+dhcpc=0","ok",500); //DHCP客户端禁止(net_ip有效)
atk_rm04_send_cmd("at+dhcpd_ip=192.168.16.100,192.168.16.200,255.255.255.0,192.168.16.1","ok",500);
atk_rm04_send_cmd("at+dhcpd_dns=192.168.16.1,0.0.0.0","ok",500);//DHCP服务器DNS设置
atk_rm04_send_cmd("at+net_ip=192.168.16.254,255.255.255.0,192.168.16.1","ok",500);
atk_rm04_send_cmd("at+net_dns=192.168.16.1,0.0.0.0","ok",500);//设置DNS设置
sprintf((char*)p,"at+wifi_conf=%s,%s,%s",wifiap_ssid,wifiap_encryption,wifiap_password);//设置无线参数:ssid,加密方式,密码
atk_rm04_send_cmd(p,"ok",500); //配置无线参数
//PRESTA:
netpro=atk_rm04_netpro_sel(50,30,(u8*)ATK_RM04_NETMODE_TBL[3]); //选择网络模式
atk_rm04_send_cmd("at+remotepro=tcp","ok",500); //TCP协议
sprintf((char*)p,"at+remoteport=%s",portnum);
atk_rm04_send_cmd(p,"ok",500); //设置 端口号.
atk_rm04_send_cmd("at+mode=server","ok",500); //设置为服务端 回车了
atk_rm04_send_cmd("at+net_commit=1","\r\n",4000);//提交网络配置。
atk_rm04_send_cmd("at+out_trans=0","ok",50);//发送at+out_trans=0,进入透传模式。
sprintf((char*)p,"ATK-RM04 %s ceshi%02d\r\n",ATK_RM04_WORKMODE_TBL[netpro],t/10);//测试数据 发送语句????????????
Show_Str(30+54,100,200,12,p,12,0);
u2_printf("%s",p); //发送该数据到ATK-RM04模块
myfree(p); //释放内存
return res;
}
int main(void)
{
u16 t=999; //加速第一次获取链接状态
u8 netpro=0; //网络模式
u8 *p;
u8 res=0;
Stm32_Clock_Init(9); //系统时钟设置
delay_init(72); //延时初始化
uart_init(72,115200); //串口1初始化
LCD_Init(); //初始化液晶
LED_Init(); //LED初始化
KEY_Init(); //按键初始化
usmart_dev.init(72); //usmart初始化
tp_dev.init(); //触摸屏初始化
mem_init(); //初始化内存池
exfuns_init(); //为fatfs相关变量申请内存
atk_rm04_init(); //初始化RM04模块
atk_rm04_wifiap_test();
}
|
|