GET指令的HTTP数据报文
GET /devices/你的设备号/datastreams/你的数据流名称 HTTP/1.1\r\n
Host: api.heclouds.com\r\n
api-key: 你的apikey\r\n\r\n
我更改了ESP8266的波特率,改成了4800的;
AT+UART=4800,8,1,0,0\r\n //更改esp8266的波特率
#include "reg52.h"
typedef unsigned int uint;
typedef unsigned char uchar;
#define DATASIZE 110
sbit LED = P2^0;
uchar datalen = 0;
uchar value;
uchar cnt = 0;
uchar recbuffer[DATASIZE];
void Delay600ms() //@12.000MHz
{
unsigned char i, j, k;
i = 5;
j = 144;
k = 71;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void UsartInit(void) {
SCON = 0x50;
TMOD = 0x20;
PCON = 0x80;
TH1 = 0xF3;
TL1 = 0xF3;
ES = 1;
EA = 1;
TR1 = 1;
}
void SendUart(uchar value) {
ES = 0;
SBUF = value;
while(!TI);
TI = 0;
ES = 1;
}
void SendString(uchar *str) {
while(*str != '\0') {
SendUart(*str);
str++;
}
}
void wificonnection() {
SendString("AT\r\n");
//SendString("AT+CWMODE=1\r\n");
//SendString("AT+RST");
SendString("AT+CWJAP=\"****\",\"******\"\r\n");
Delay600ms();
Delay600ms();
}
void TCPconnection() {
SendString("AT+CIPMUX=0\r\n");
Delay600ms();
Delay600ms();
SendString("AT+CIPSTART=\"TCP\",\"183.230.40.33\",80\r\n");
Delay600ms();
Delay600ms();
SendString("AT+CIPMODE=1\r\n");
Delay600ms();
Delay600ms();
SendString("AT+CIPSEND\r\n");
Delay600ms();
Delay600ms();
}
void check() {
SendString("GET /devices/******/datastreams/*** HTTP/1.1\r\n");
SendString("Host: api.heclouds.com\r\n");
SendString("api-key: ********************\r\n\r\n");
Delay600ms();
}
void main() {
UsartInit();
wificonnection();
TCPconnection();
while(1) {
check();
Delay600ms();
if(value == '1') LED = 0;
else if(value == '0') LED = 1;
}
}
void Usart() interrupt 4 {
uchar rec;
if(RI != 0) {
rec = SBUF;
RI = 0;
}
if(rec == '{') cnt = 1;
if(cnt == 1) {
if(rec != '}') {
recbuffer[datalen++] = rec;
}
else {
cnt = 0;
value = recbuffer[datalen - 1];
//SendString(recbuffer);
//SendString("\r\n");
//SendUart(value);
//SendString("\r\nok\r\n");
datalen = 0;
}
}
}