/* * ESPRSSIF MIT License * * Copyright (c) 2015 * * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_common.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "lwip/sockets.h" #include "lwip/dns.h" #include "lwip/netdb.h" #include "espressif/espconn.h" #include "espressif/airkiss.h" #define server_ip "192.168.101.142" #define server_port 9669 #define DEVICE_TYPE "gh_9e2cff3dfa51" //wechat public number #define DEVICE_ID "122475" //model ID #define DEFAULT_LAN_PORT 12476 LOCAL esp_udp ssdp_udp; LOCAL struct espconn pssdpudpconn; LOCAL os_timer_t ssdp_time_serv; uint8 lan_buf[200]; uint16 lan_buf_len; uint8 udp_sent_cnt = 0; const airkiss_config_t akconf = { (airkiss_memset_fn)&memset, (airkiss_memcpy_fn)&memcpy, (airkiss_memcmp_fn)&memcmp, 0, }; LOCAL void ICACHE_FLASH_ATTR airkiss_wifilan_time_callback(void) { uint16 i; airkiss_lan_ret_t ret; if ((udp_sent_cnt++) >30) { udp_sent_cnt = 0; os_timer_disarm(&ssdp_time_serv);//s //return; } ssdp_udp.remote_port = DEFAULT_LAN_PORT; ssdp_udp.remote_ip[0] = 255; ssdp_udp.remote_ip[1] = 255; ssdp_udp.remote_ip[2] = 255; ssdp_udp.remote_ip[3] = 255; lan_buf_len = sizeof(lan_buf); ret = airkiss_lan_pack(AIRKISS_LAN_SSDP_NOTIFY_CMD, DEVICE_TYPE, DEVICE_ID, 0, 0, lan_buf, &lan_buf_len, &akconf); if (ret != AIRKISS_LAN_PAKE_READY) { os_printf("Pack lan packet error!"); return; } ret = espconn_sendto(&pssdpudpconn, lan_buf, lan_buf_len); if (ret != 0) { os_printf("UDP send error!"); } os_printf("Finish send notify!\n"); } LOCAL void ICACHE_FLASH_ATTR airkiss_wifilan_recv_callbk(void *arg, char *pdata, unsigned short len) { uint16 i; remot_info* pcon_info = NULL; airkiss_lan_ret_t ret = airkiss_lan_recv(pdata, len, &akconf); airkiss_lan_ret_t packret; switch (ret){ case AIRKISS_LAN_SSDP_REQ: espconn_get_connection_info(&pssdpudpconn, &pcon_info, 0); os_printf("remote ip: %d.%d.%d.%d \r\n",pcon_info->remote_ip[0],pcon_info->remote_ip[1], pcon_info->remote_ip[2],pcon_info->remote_ip[3]); os_printf("remote port: %d \r\n",pcon_info->remote_port); pssdpudpconn.proto.udp->remote_port = pcon_info->remote_port; memcpy(pssdpudpconn.proto.udp->remote_ip,pcon_info->remote_ip,4); ssdp_udp.remote_port = DEFAULT_LAN_PORT; lan_buf_len = sizeof(lan_buf); packret = airkiss_lan_pack(AIRKISS_LAN_SSDP_RESP_CMD, DEVICE_TYPE, DEVICE_ID, 0, 0, lan_buf, &lan_buf_len, &akconf); if (packret != AIRKISS_LAN_PAKE_READY) { os_printf("Pack lan packet error!"); return; } os_printf("\r\n\r\n"); for (i=0; i