Statistics: Posted by steve2077 — Tue Mar 17, 2015 12:58 am
Statistics: Posted by Her Mary — Mon Mar 09, 2015 4:23 pm
Code:
/******************************************************************************
* Copyright 2013-2014 Espressif Systems
*
*******************************************************************************/
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
#include "espconn.h"
#include "user_json.h"
#include "user_devicefind.h"
#define ESPCONN_OK 0
const char *device_find_request = "Are You Smart Device?";
const char *device_find_response_ok = "I'm Steve Device.";
/*---------------------------------------------------------------------------*/
LOCAL struct espconn ptrespconn;
/******************************************************************************
* FunctionName : user_udp_sent_cb
* Description : Data has been sent successfully and acknowledged by the remote host.
* Parameters : arg -- Additional argument to pass to the callback function
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_udp_sent_cb(void *arg)
{
struct espconn *pespconn = arg;
os_printf("user_udp_sent_cb\n");
}
/******************************************************************************
* FunctionName : user_udp_sent
* Description : Processing the application data and sending it to the host
* Parameters : pespconn -- the espconn used to connetion with the host
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_udp_sent(struct espconn *pespconn)
{
unsigned short length;
unsigned short packet_size=1024;
char *pbuf = (char *)os_zalloc(packet_size);
length=os_strlen(device_find_request);
os_memcpy(pbuf,device_find_request,length);
espconn_sent(pespconn, pbuf, os_strlen(pbuf));
os_free(pbuf);
}
/******************************************************************************
* FunctionName : user_devicefind_init
* Description : create a udp listening
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_udp_init(void)
{
const char dst_ip[4]={192,168,1,108}; // Server IP
ptrespconn.type = ESPCONN_UDP;
ptrespconn.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
ptrespconn.proto.udp->remote_port = 1025;// Remote Server Port
os_memcpy(ptrespconn.proto.udp->remote_ip, dst_ip, 4); // Remote Server IP
ptrespconn.proto.udp->local_port=espconn_port();// ESP8266 udp port
//ptrespconn.proto.udp->local_port = 1025; // ESP8266 udp port
//espconn_regist_recvcb(&ptrespconn, user_udp_recv); // register a udp packet receiving callback
espconn_regist_sentcb(&ptrespconn, user_udp_sent_cb); // register a udp packet sending callback
user_udp_sent(&ptrespconn); // sent data
espconn_create(&ptrespconn); // create udp
}
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void user_init(void)
{
os_printf("SDK version:%s\n", system_get_sdk_version());
char ssid[32] = "steve";
char password[64] = "steveahn";
struct station_config stationConf;
//Set softAP + station mode
wifi_set_opmode(STATIONAP_MODE);
//Set ap settings
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 64);
wifi_station_set_config(&stationConf);
os_delay_us(15000000);
os_printf("start from here\r\n");
// Create udp listening.
user_udp_init();
}
Statistics: Posted by steve2077 — Sun Mar 08, 2015 12:56 pm