本人是初学者,想请教各位一个问题:如何用GPRS模块发送GPS的数据到yeelink上?
下面的代码是发送普通数值的。(发送普通数值和发送GPS定位的数据有什么区别!?{:soso_e154:} )#include <stdio.h>
#include <math.h>
int i;
int len;
int times;
int temp;
int t;
char xinlv;
char post[]={//提交数据包
"POST /v1.0/device/12797/sensor/aaaaa/datapoints HTTP/1.1\r\n"
"Host: api.yeelink.net\r\n"
"Accept: */*\r\n"
"U-ApiKey:587407b0532721175514efd429f5dc98\r\n"
"Content-Length: dt\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Connection: close\r\n"
"\r\n"
"{\"value\":xxxxxx}\r\n"
};//xx用来填充数值
char post_reserve[]={//提交数据包
"POST /v1.0/device/12797/sensor/aaaaa/datapoints HTTP/1.1\r\n"
"Host: api.yeelink.net\r\n"
"Accept: */*\r\n"
"U-ApiKey: 587407b0532721175514efd429f5dc98\r\n"
"Content-Length: dt\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Connection: close\r\n"
"\r\n"
"{\"value\":xxxxxx}\r\n"
};//xx用来填充数值
char xinlv_sensor_id[]={"21121"};
/////1
void post_xinlv() //发送温度数据
{connect();
len=strlen(post);
for(times=0;times<len;times++)
{
if(post=='a'&&post=='a'&&post=='a')
{
post=xinlv_sensor_id;
post=xinlv_sensor_id;
post=xinlv_sensor_id;
post=xinlv_sensor_id;
post=xinlv_sensor_id;
break;
}
}
temp=0;
len=strlen(post);
temp=Serial.print(xinlv,1);
for(times=0;times<len;times++)
{
if(post=='d'&&post=='t')
{
post=(temp+10)/10+0x30;
post=(temp+10)%10+0x30;
break;
}
}
for(times=0;times<len;times++)//填改传感器数值,发送报文
{
if(post=='x'&&post=='x'&&post=='x')
{
Serial1.print(xinlv,1);
times=times+6;
}
Serial1.print(post);
}
Serial1.write(26);//send order
delay(3000);
close();
for(times=0;times<len;times++)
{
post=post_reserve;
}
}
////////2
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin(115200);
xinlv=0;
}
void loop() {
// put your main code here, to run repeatedly:
// xinlv=xinlv+5;
//if(xinlv==55)
// {xinlv=0; }
post_xinlv();
delay(1000);
}
void connect()//TCP连接
{
int i;
//Serial1.print("ati\r\n");
// delay(1000);
//Serial1.print("ati\r\n");
// delay(1000);
Serial1.print("ati\r\n");
delay(1000);
delay(500);
Serial1.print("AT+CGCLASS=\"B\"\r\n");
delay(500);
Serial1.print("AT+CGDCONT=1,\"IP\",\"CMNET\"\r\n");
delay(500);
Serial1.print("AT+CGATT=1\r\n");
delay(500);
Serial1.print("AT+CIPCSGP=1,\"CMNET\"\r\n"); //uninet
delay(500);
Serial1.print("AT+CLPORT=\"TCP\",\"2000\"\r\n");
delay(500);
Serial1.print("AT+CIPSTART=\"TCP\",\"42.96.164.52\",\"80\"\r\n"); //the ip addr to yeelink
delay(500);
for(i=0;i<=3;i++)
{
delay(1000);
}
Serial1.print("AT+CIPSEND\r\n");
delay(500);
}
void close()//结束TCP连接
{
Serial1.print("AT+CIPCLOSE=1\r\n");
delay(500);
Serial1.print("AT+CIPSHUT\r\n");
delay(500);
}
页:
[1]