// digitalRead([pin])
void ICACHE_FLASH_ATTR
at_setupReadPinCmd(uint8_t id, char *pPara)
{
    int result = 0, err = 0, flag = 0;
    uint8 buffer[32] = {0};
    pPara++; // skip '='

    //get the first parameter (uint8_t)
    // digit
    flag = at_get_next_int_dec(&pPara, &result, &err);

    // flag must be true because there are more parameters
    //if ((flag == FALSE) && (result > 0) )
	if (err > 0)
	{
		at_port_print("Bad input");
        at_response_error();
        return;
    }
	
	uint8_t pin = result;
	
	// Don't go any further if the pin is un-usable or non-existant
	if (!pinValid(pin))
	{
		at_response_error();
		return;
	}
	
	uint8_t value = GPIO_INPUT_GET(pin);
	os_sprintf(buffer, "%d\r\n", value);
	
	at_port_print(buffer);
	at_response_ok();
}
예제 #2
0
void user_init(void)
{
    char buf[64] = {0};
    at_customLinkMax = 5;
	
    at_init();
	shield_init(); // Shield init must be called _after_ at_init() - to set baud rate
	
    os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__);
    at_set_custom_info(buf);
    at_port_print("\r\n");
	at_port_print(WELCOME_MESSAGE);
    at_port_print("\r\n");
}
예제 #3
0
// test :AT+TEST=1,"abc"<,3>
void ICACHE_FLASH_ATTR
at_setupCmdTest(uint8_t id, char *pPara)
{
    int result = 0, err = 0, flag = 0;
    uint8 buffer[32] = {0};
    pPara++; // skip '='

    //get the first parameter
    // digit
    flag = at_get_next_int_dec(&pPara, &result, &err);

    // flag must be ture because there are more parameter
    if (flag == FALSE) {
        at_response_error();
        return;
    }

    if (*pPara++ != ',') { // skip ','
        at_response_error();
        return;
    }

    os_sprintf(buffer, "the first parameter:%d\r\n", result);
    at_port_print(buffer);

    //get the second parameter
    // string
    at_data_str_copy(buffer, &pPara, 10);
    at_port_print("the second parameter:");
    at_port_print(buffer);
    at_port_print("\r\n");

    if (*pPara == ',') {
        pPara++; // skip ','
        result = 0;
        //there is the third parameter
        // digit
        flag = at_get_next_int_dec(&pPara, &result, &err);
        // we donot care of flag
        os_sprintf(buffer, "the third parameter:%d\r\n", result);
        at_port_print(buffer);
    }

    if (*pPara != '\r') {
        at_response_error();
        return;
    }

    at_response_ok();
}
예제 #4
0
void ICACHE_FLASH_ATTR user_init(void)
{
    char buf[128] = {0};
    at_customLinkMax = 5;
	sdio_slave_init();
	sdio_register_recv_cb(sdio_recv_data_callback);
    at_init();
	at_register_uart_rx_buffer_fetch_cb(at_custom_uart_rx_buffer_fetch_cb);
#ifdef ESP_AT_FW_VERSION
    if ((ESP_AT_FW_VERSION != NULL) && (os_strlen(ESP_AT_FW_VERSION) < 64)) {
        os_sprintf(buf,"compile time:%s %s\r\n"ESP_AT_FW_VERSION,__DATE__,__TIME__);
    } else {
        os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__);
    }
#else
    os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__);
#endif
    at_set_custom_info(buf);
	at_fake_uart_enable(TRUE,at_sdio_response);
	
    at_cmd_array_regist(&at_custom_cmd[0], sizeof(at_custom_cmd)/sizeof(at_custom_cmd[0]));

	espconn_tcp_set_wnd(4);
	at_port_print("\r\nready\r\n");

#ifdef SDIO_DEBUG
	os_timer_disarm(&at_spi_check);
	os_timer_setfn(&at_spi_check, (os_timer_func_t *)at_spi_check_cb, NULL);
	os_timer_arm(&at_spi_check, 1000, 1);
	os_printf("\r\ntimer start\r\n");
#endif
}
예제 #5
0
void ICACHE_FLASH_ATTR
at_queryCmdNTP(uint8_t id)
{
    uint8 buffer[255] = {0};
    time_t tim = (time_t)sntp_get_current_timestamp();
    struct tm *t;
    if (tim > 0) {
	t = localtime(&tim);
	os_sprintf(buffer, "NTP Time: %02d:%02d:%02d %02d.%02d.%04d %s (%d)sec\r\n", t->tm_hour,t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon + 1, t->tm_year + 1900, weekday[t->tm_wday], tim);
	at_port_print(buffer);
	at_response_ok();
    } else {
	os_sprintf(buffer, "NTP Error: (0)\r\n");
	at_port_print(buffer);
	at_response_error();
    }
}
예제 #6
0
void ICACHE_FLASH_ATTR
at_exeCmdTest(uint8_t id)
{
    uint8 buffer[32] = {0};

    os_sprintf(buffer, "%s\r\n", "at_exeCmdTest");
    at_port_print(buffer);
    at_response_ok();
}
예제 #7
0
void user_init(void)
{
    char buf[64] = {0};
    at_customLinkMax = 5;
    at_init();
    os_sprintf(buf,"eMax' NTP Version:%s %s",__DATE__,__TIME__);
    at_set_custom_info(buf);
    at_port_print("\r\nready\r\n");
    at_cmd_array_regist(&at_custom_cmd[0], sizeof(at_custom_cmd)/sizeof(at_custom_cmd[0]));
}
// digitalWrite([pin], [value])
void ICACHE_FLASH_ATTR
at_setupWritePinCmd(uint8_t id, char *pPara)
{
    int result = 0, err = 0, flag = 0;
    uint8 buffer[32] = {0};
    pPara++; // skip '='

    //get the first parameter (uint8_t)
    // digit
    flag = at_get_next_int_dec(&pPara, &result, &err);

    // flag must be true because there are more parameters
    if ((flag == FALSE) && (result > 0) )
	{
        at_response_error();
        return;
    }
	
	uint8_t pin = result;
	
	// Don't go any further if the pin is un-usable or non-existant
	if (!pinValid(pin))
	{
		at_response_error();
		return;
	}
	
	if (*pPara++ != ',') { // skip ','
		at_response_error();
		return;
	}
	
	char value = *pPara++;
	
	if ((value == 'h') || (value == 'H') || (value == '1'))
	{
		GPIO_OUTPUT_SET(pin, 1);
		os_sprintf(buffer, "%d=HIGH\r\n", pin);
	}
	else if ((value == 'l') || (value == 'L') || (value == '0'))
	{
		GPIO_OUTPUT_SET(pin, 0);
		os_sprintf(buffer, "%d=LOW\r\n", pin);
	}
	else
	{
		at_response_error();
		return;
	}
	
	at_port_print(buffer);
	at_response_ok();
}
예제 #9
0
void ICACHE_FLASH_ATTR
at_exeCmdNTP(uint8_t id)
{
    uint8 buffer[255] = {0};
    sntp_stop();
    int i;
    uint32 tm = 0;
    int ntp_servers_len = sizeof(ntp_servers) / sizeof(ntp_servers[0]);
    for (i = 0; i < 3; i++) {
	if (i >= ntp_servers_len) break;
	sntp_setservername(i, ntp_servers[i]);
    }
    sntp_set_timezone(NTP_OFFSET);
    sntp_init();
    os_sprintf(buffer, "NTP init\r\n");
    at_port_print(buffer);
    at_response_ok();
}
예제 #10
0
void ICACHE_FLASH_ATTR user_init(void)
{
    char buf[64] = {0};
    at_customLinkMax = 5;
    at_init();
    os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__);
    at_set_custom_info(buf);
    at_port_print("\r\nready\r\n");
    at_cmd_array_regist(&at_custom_cmd[0], sizeof(at_custom_cmd)/sizeof(at_custom_cmd[0]));
	at_port_print("\r\n***==================================***");
	at_port_print("\r\n***  Welcome to at espconn demo!!!   ***");
	at_port_print("\r\n*** Please create a TCP Server on PC,***");
	at_port_print("\r\n*** then enter command AT+TEST.      ***");
	at_port_print("\r\n***==================================***\r\n");
}
예제 #11
0
/******************************************************************************
 * FunctionName : upgrade_download
 * Description  : Processing the upgrade data from the host
 * Parameters   : bin -- server number
 *                pusrdata -- The upgrade data (or NULL when the connection has been closed!)
 *                length -- The length of upgrade data
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
upgrade_download(void *arg, char *pusrdata, unsigned short length){
    char *ptr = NULL;
    char *ptmp2 = NULL;
    char lengthbuffer[32], returncode[4];
    uint8_t md5_calc[16],i = 0,progress = 0;
    char output[64] = {0};
    struct upgrade_server_info *server = (struct upgrade_server_info *)upgrade_conn->reverse;
    uint32_t  count;

    //检查返回码
    if (totallength == 0){
        ptr = (char *)os_strstr(pusrdata, "HTTP/1.1 ");
        os_memset(returncode, 0, sizeof(returncode));
        os_memcpy(returncode, ptr+9, 3);

        if(os_strcmp(returncode ,"200")){ //下载失败
            UPGRADE_DBG("http download return code  error\n");
            upgrade_check(server);
            return;
        }
    }
   if (totallength == 0 && (ptr = (char *)os_strstr(pusrdata, "\r\n\r\n")) != NULL &&
            (ptr = (char *)os_strstr(pusrdata, "Content-Length")) != NULL) {
        ptr = (char *)os_strstr(pusrdata, "\r\n\r\n");
        length -= ptr - pusrdata;
        length -= 4;
        totallength += length;
        UPGRADE_DBG("upgrade file download start.\n");
        file_info_clear();
        MD5Init(&_ctx);
        MD5Update(&_ctx, ptr + 4, length);
        system_upgrade(ptr + 4, length);
        ptr = (char *)os_strstr(pusrdata, "Content-Length: ");

        if (ptr != NULL) {
            ptr += 16;
            ptmp2 = (char *)os_strstr(ptr, "\r\n");

            if (ptmp2 != NULL) {
                os_memset(lengthbuffer, 0, sizeof(lengthbuffer));
                os_memcpy(lengthbuffer, ptr, ptmp2 - ptr);
                sumlength = atoi(lengthbuffer);
            } else {
                UPGRADE_DBG("sumlength failed\n");
                upgrade_check(server);
                return;
            }
        } else {
            upgrade_check(server);
            UPGRADE_DBG("Content-Length: failed\n");
            return;
        }
    } else {
        if(totallength + length > sumlength)
        {length = sumlength - totallength;}
        totallength += length;
        os_printf("totallen = %d\n",totallength);
        MD5Update(&_ctx, pusrdata, length);
        system_upgrade(pusrdata, length);
    }

    progress = totallength*100/sumlength;
    os_memset(output, 0, sizeof(output));
    os_sprintf(output,"%s:2,%d\r\n", CMD_DOWN_FILE, progress);
    at_port_print(output);       //正在下载  显示下载进度
    //at_response_ok();

    if ((totallength == sumlength)) {
        UPGRADE_DBG("upgrade file download finished.\n");
        MD5Final(md5_calc, &_ctx);
        os_memset(output, 0, sizeof(output));
        for(i = 0; i < 16; i++)
        {
            os_sprintf(output + (i * 2), "%02x", md5_calc[i]);
        }
        os_printf("md5 = %s\n",output);
        if(!os_strcmp(server->md5,output)){
            UPGRADE_DBG("md5 check ok.\n");
            system_upgrade_flag_set(UPGRADE_FLAG_FINISH);
            //保存文件
            file_info->file_size = sumlength;
            file_info->file_start_sec = UPDATE_CACHE_WIFIAPP_SEC_START;
            file_info_write(file_info);

            totallength = 0;
            sumlength = 0;
            upgrade_check(server);
            return;
        }
        UPGRADE_DBG("md5 check error.\n");
        upgrade_check(server);
        return;
    }

    if (upgrade_conn->state != ESPCONN_READ) {
        totallength = 0;
        sumlength = 0;
        os_timer_disarm(&upgrade_rev_timer);
        os_timer_setfn(&upgrade_rev_timer, (os_timer_func_t *)upgrade_check, server);
        os_timer_arm(&upgrade_rev_timer, 10, 0);
    }
}
// pinMode([pin], [direction])
void ICACHE_FLASH_ATTR
at_setupPinModeCmd(uint8_t id, char *pPara)
{
    int result = 0, err = 0, flag = 0;
    uint8 buffer[32] = {0};
    pPara++; // skip '='

    //get the first parameter (uint8_t)
    // digit
    flag = at_get_next_int_dec(&pPara, &result, &err);

    // flag must be true because there are more parameters
    if ((flag == FALSE) && (result > 0) )
	{
        at_response_error();
        return;
    }
	
	uint8_t pin = result;
	
	// Don't go any further if the pin is un-usable or non-existant
	if (!pinValid(pin))
	{
		at_response_error();
		return;
	}
	
	if (*pPara++ != ',') { // skip ','
		at_response_error();
		return;
	}
	
	char mode = *pPara++;
	
	if ((mode == 'i') || (mode == 'I'))
	{
		if (pin == STATUS_LED_PIN)
		{
			wifi_status_led_uninstall();
		}
		PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]);
		GPIO_DIS_OUTPUT(pin);
		PIN_PULLUP_DIS(pinMap[pin]);
		os_sprintf(buffer, "%d=INPUT\r\n", pin);
	}
	else if ((mode == 'o') || (mode == 'O'))
	{
		if (pin == STATUS_LED_PIN)
		{
			wifi_status_led_uninstall();
		}
		PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]);
		GPIO_OUTPUT_SET(pin, 0);
		os_sprintf(buffer, "%d=OUTPUT\r\n", pin);
	}
	else if ((mode == 'p') || (mode == 'P'))
	{
		if (pin == STATUS_LED_PIN)
		{
			wifi_status_led_uninstall();
		}
		PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]);
		GPIO_DIS_OUTPUT(pin);
		PIN_PULLUP_EN(pinMap[pin]);
		os_sprintf(buffer, "%d=INPUT_PULLUP\r\n", pin);
	}
	else
	{
		at_response_error();
		return;
	}
	
	at_port_print(buffer);
	at_response_ok();
}
void ICACHE_FLASH_ATTR
at_testReadPinCmd(uint8_t id)
{
    at_port_print("AT+PINREAD=<pin>");
    at_response_ok();
}
void ICACHE_FLASH_ATTR
at_testWritePinCmd(uint8_t id)
{
    at_port_print("AT+PINWRITE=<pin>,<H/L>");
    at_response_ok();
}
void ICACHE_FLASH_ATTR
at_testPinModeCmd(uint8_t id)
{
    at_port_print("AT+PINMODE=<pin>,<I/O/P>\r\n");
    at_response_ok();
}