学前班
最后登录1970-1-1
在线时间 小时
注册时间2016-7-19
|
楼主 |
发表于 2016-7-19 12:20:58
|
显示全部楼层
在http_client.c中增加下面条件编译,切到我们服务器
#if __HTTP_YEELINK_DEMO
uint8 yeelink_server_ip[4]={42,96,164,52}; /*api.yeelink.net µÄipµØÖ·*/
uint8 yeelink_port=80; /*api.yeelink.net µÄ¶Ë¿ÚºÅ*/
char postT[]={
"POST /v1.0/device/17530/sensor/30435/datapoints HTTP/1.1\r\n"
"Host:api.yeelink.net\r\n"
"Accept:*/*\r\n"
"U-ApiKey:07597cf93ee715d2fee144f25aa3ff65\r\n"
"Content-Length:12\r\n"
"Content-Type:application/x-www-form-urlencoded\r\n"
"Connection:close\r\n"
"\r\n"
"{\"value\":xx}\r\n"
};/*xxÓÃÀ´Ìî³äζÈÊýÖµ*/
char postH[]={//Ìύʪ¶È
"POST /v1.0/device/17530/sensor/30436/datapoints HTTP/1.1\r\n"
"Host:api.yeelink.net\r\n"
"Accept:*/*\r\n"
"U-ApiKey:07597cf93ee715d2fee144f25aa3ff65\r\n"
"Content-Length:12\r\n"
"Content-Type:application/x-www-form-urlencoded\r\n"
"Connection:close\r\n"
"\r\n"
"{\"value\":xx}\r\n"
};/*xxÓÃÀ´Ìî³äζÈÊýÖµ*/
char *post[]={postH,postT};
#else
uint8 yeelink_server_ip[4]={121,199,47,177}; /*api.yeelink.net µÄipµØÖ·*/
uint8 yeelink_port=80; /*api.yeelink.net µÄ¶Ë¿ÚºÅ*/
char http_get_time[]={
//"http://121.199.47.177/AMS/AMS.asmx/ServerDateTimeMCU?args=\r\n"
//"GET http://121.199.47.177:80/AMS/AMS.asmx/ServerDateTimeMCU?args=\r\n"
//"http://121.199.47.177:80/AMS/AMS.asmx/ServerDateTimeMCU?args=\r\n"
"AMS/AMS.asmx/ServerDateTimeMCU?args=\r\n"
};
char *post[]={http_get_time,http_get_time};
/*
AT^HTTPCMD=0,GET,http://121.199.47.177:80/AMS/AMS.asmx/ServerDateTimeMCU?args=
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://www.underway.com/AMSWebServices">0,20160718230403</string>
*/
#endif
......
case SOCK_ESTABLISHED: /*socketÁ¬½Ó½¨Á¢*/
if(getSn_IR(ch) & Sn_IR_CON)
{
setSn_IR(ch, Sn_IR_CON); /*Çå³ý½ÓÊÕÖжϱêÖ¾*/
}
#if __HTTP_YEELINK_DEMO
//if( Read_DHT11(&dht11_data)==SUCCESS) /*ÅжÏÊÇ·ñµÃµ½DHT11Êý¾Ý*/
dht11_data.humi_int=25;
dht11_data.temp_int=16;
{
temp_rh[0]=dht11_data.humi_int; /*8bit ʪ¶ÈÕûÊý */
temp_rh[1]=dht11_data.temp_int; /*8bit ζÈÕûÊý*/
memcpy(buffer,post,strlen(post));
buffer[231]=temp_rh/10+0x30;
buffer[232]=temp_rh%10+0x30;
send(ch,(const uint8 *)buffer,sizeof(buffer)); /*W5500Ïò Yeelink·þÎñÆ÷·¢ËÍÊý¾Ý*/
i=1;
printf("RH:%d, Temp:%d\r\n", temp_rh[0], temp_rh[1]);
}
delay_ms(500);
#else
if(getSn_IR(SOCK_TCPC) & Sn_IR_CON)
{
setSn_IR(SOCK_TCPC, Sn_IR_CON); /*Çå³ý½ÓÊÕÖжϱê־λ*/
}
#if 0
len=getSn_RX_RSR(SOCK_TCPC); /*¶¨ÒålenΪÒѽÓÊÕÊý¾ÝµÄ³¤¶È*/
if(len>0)
{
recv(ch,(uint8 *)buffer,len); /*½ÓÊÕÀ´×ÔServerµÄÊý¾Ý*/
buffer[len]=0x00; /*Ìí¼Ó×Ö·û´®½áÊø·û*/
printf("clear rxbuf: %s\r\n",buffer);
//send(SOCK_TCPC,buffer,len); /*ÏòServer·¢ËÍÊý¾Ý*/
}
#endif
memcpy(buffer,post,strlen(post));
send(ch,(const uint8 *)buffer,sizeof(buffer));
printf("send: %s\r\n", buffer);
delay_ms(500);
recv(ch, (uint8 *)buffer, sizeof(buffer));
printf("receive: %s\r\n", buffer);
close(ch);
#endif
|
|