void ICACHE_FLASH_ATTR station_connect_status_check_timercb(void* _timer) { ETSTimer* timer = (ETSTimer*)_timer; os_printf("wifi_station_dhcpc_status: [%d]\n", wifi_station_dhcpc_status()); if(wifi_station_dhcpc_status() == DHCP_STOPPED && !wifi_station_dhcpc_start()) { os_printf("wifi_station_dhcpc_start error\n"); } os_printf("wifi station connect status: [%d]\n", wifi_station_get_connect_status()); if(wifi_station_get_connect_status() == STATION_GOT_IP && client_status != STATUS_CONNECTED) { os_printf("Connected to ROUTER, connecting to cloud\n"); connect_to_cloud(); client_status = STATUS_CONNECTING; } //连接成功后停止定时器 if(client_status == STATUS_CONNECTED) { os_timer_disarm(timer); } //如果系统模式非station模式,则停止 if(wifi_get_opmode() != STATION_MODE) { os_timer_disarm(timer); } }
/* main tick */ void mxchipWNet_HA_tick(void) { mxchipTick(); if (!is_wifi_disalbed()) { if (is_network_state(STA_CONNECT) == 0 && is_network_state(UAP_START) == 0) { if (MS_TIMER > uap_start_time) { uap_start(); } } if(is_network_state(STA_CONNECT) && cloud_enable && MS_TIMER > cloud_retry) connect_to_cloud(); tcp_recv_tick(); } if(need_report){ report_state(); need_report = 0; } if (need_reload == 1) { msleep(500); NVIC_SystemReset(); } }
/***************************************************************************** * * Cloud_Read * * \param palias - string, name of the datasource alias to read from * pbuf - read buffer to put the read response into * buflen - size of the input buffer * * \return number of bytes read * * \brief Reads data from Exosite cloud * *****************************************************************************/ int Cloud_Read(char * palias, char * pbuf, unsigned char buflen) { int success = 0; int http_status = 0; unsigned char strLen, len, vlen; char *p, *pcheck; if (!cloud_initialized) { status_code = STATUS_INIT; return success; } long sock = connect_to_cloud(); if (sock < 0) { status_code = STATUS_END; return 0; } sendLine(sock, GETDATA_LINE, palias); sendLine(sock, HOST_LINE, NULL); sendLine(sock, CIK_LINE, CIK); sendLine(sock, ACCEPT_LINE, "\r\n"); pcheck = palias; vlen = 0; http_status = get_http_status(sock); if (200 == http_status) { char strBuf[RX_SIZE]; unsigned char crlf = 0; do { strLen = IHMS_SocketRecv(sock, strBuf, RX_SIZE); len = strLen; p = strBuf; // Find 4 consecutive \r or \n - should be: \r\n\r\n while (0 < len && 4 > crlf) { if ('\r' == *p || '\n' == *p) { ++crlf; } else { crlf = 0; } ++p; --len; } // The body is "<key>=<value>" if (0 < len && 4 == crlf && buflen > vlen) { // Move past "<key>" while (0 < len && 0 != *pcheck) { if (*pcheck == *p) { ++pcheck; } else { pcheck = palias; } ++p; --len; } // Match '=', we should now have '<key>=' if (0 < len && 0 == *pcheck && '=' == *p) { ++p; --len; } // read in the rest of the body as the value while (0 < len && buflen > vlen) { pbuf[vlen++] = *p++; --len; } } } while (RX_SIZE == strLen); } IHMS_SocketClose(sock); if (0 == http_status) status_code = STATUS_END; if (200 == http_status) { status_code = STATUS_END; } if (204 == http_status) { status_code = STATUS_END; } if (401 == http_status) { status_code = STATUS_END; } return vlen; }