Creelinks wifi test.
#include "Creelinks.h"
#include "CeWifiEsp.h"
CeWifiEsp myWifiEsp;
#define MY_TASK1_STACK_BUF_SIZE 1024
CE_STK MY_TASK1_STACK_BUF[MY_TASK1_STACK_BUF_SIZE];
CeTask myTask1;
void myTask1CallBack(void * pAddPar)
{
while(1)
{
ceDebugOp.printf("Task 1 is running...");
ceWifiEspOp.sendData(&myWifiEsp, 0, (uint8 *)("Hello server!\n"), ceStringOp.strlen("Hello server!\n"));
ceSystemOp.delayMs(500);
}
}
void callBackServerRecv(uint8 linkID, uint8* recvBuf, uint16 recvCount)
{
uint16 i;
ceDebugOp.printf("CeWifiEsp has recv data from client, linkID:%d, DataCount:%d, Data:\n", linkID, recvCount);
for(i = 0; i < recvCount; i++)
{
ceDebugOp.printf("%c", recvBuf[i]);
}
ceDebugOp.printf("\n");
}
void initialWifi(void)
{
ceWifiEspOp.initial(&myWifiEsp, R14Uart); //
ceWifiEspOp.setWorkMode(&myWifiEsp, CE_WIFI_ESP_MODE_AP); // 设置模块为路由器
while(CE_STATUS_SUCCESS != ceWifiEspOp.createWifi(&myWifiEsp, "192.168.1.188", "Creelinks", "12345678", 1, CE_WIFI_ESP_ECN_WPA2_PSK))
{
ceDebugOp.printf("Cannot create Wifi!\n");
ceSystemOp.delayMs(1000);
}
while(ceWifiEspOp.getConnectedDeviceCount(&myWifiEsp) == 0)
{
ceDebugOp.printf("Wait for device connect wifi ... \n");
ceSystemOp.delayMs(1000);
}
while(CE_STATUS_SUCCESS != ceWifiEspOp.createServer(&myWifiEsp, 2121, CE_WIFI_ESP_SOCKET_MODE_TCP, callBackServerRecv))
{
ceDebugOp.printf("Cannot create Server!\n");
ceSystemOp.delayMs(1000);
}
}
int main(void)
{
ceSystemOp.initial();
ceDebugOp.initial(R9Uart);
myTask1.ID = 0x0033;
myTask1.taskName = "My Task1";
myTask1.callBack = myTask1CallBack;
myTask1.pAddPar = &myTask1;
myTask1.taskPriority = CE_TASK_PRIORITY_H;
myTask1.taskStackBuf = MY_TASK1_STACK_BUF;
myTask1.taskStackBufSize = MY_TASK1_STACK_BUF_SIZE;
ceTaskOp.registerTask(&myTask1);
initialWifi();
ceTaskOp.start(&myTask1);
ceTaskOp.mainTask();
return 0;
}