专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
物联网
GPRS模块可以在实时发送经纬度到服务器期间,按键触发,发送另一条数据到这个服务器的另一个端口吗?
2019-07-18 14:11
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
RF/无线
6289
1
1452
试过直接用if(S2==0)放在void sendDataToServer()后面判断按键的方法不行
#include "main.h"
#include "uart.h"
#include "LCD1602.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <REG52.h>
//常量
#define Success 1U
#define Failure 0U
//定义变量
unsigned long
ti
me_Cont = 0; //定时器计数器
_SaveData Save_Data;
sbit s2=P2^2;
code char TCPServer[] = "120.79.207.145"; //TCP服务器地址
code char Port[] = "80"; //端口
code char Port2[] = "8000"; //端口2
char flagConnect = 0;
//****************************************************
//主函数
//****************************************************
void main()
{
unsigned char i = 0;
Uart_Init();
delay_ms(10);
Init_LCD1602();
LCD1602_write_com(0x80);
LCD1602_write_word("Welcome to ");
LCD1602_write_com(0x80+0x40);
LCD1602_write_word(" Rescue system");
clrStruct(); //清空缓存数组
if (sendCommand("AT ", "OK ", 3000, 10) == Success);
else errorLog();
delay_ms(10);
if (sendCommand("AT+CPIN? ", "READY", 1000, 10) == Success);
else errorLog();
delay_ms(10);
if (sendCommand("AT+CREG? ", ",1", 1000, 10) == Success);
else
{
delay_ms(10);
if (sendCommand("AT+CREG? ", ",5", 1000, 10) == Success);
else errorLog();
}
if (sendCommand("AT+QGNSSC? ", "+QGNSSC: 1", 1000, 1) == Success);
else if (sendCommand("AT+QGNSSC=1 ", "OK ", 100, 10) == Success);
else errorLog();
if (sendCommand("AT+QICLOSE ", " ", 5000, 10) == Success);
else errorLog();
delay_ms(100);
if (sendCommand("AT+QIDEACT ", " ", 5000, 10) == Success);
else errorLog();
while(1)
{
if (sendCommand("AT+QGNSSRD="NMEA/RMC" ", "OK ", 2000, 10) == Success);
else errorLog();
Save_Data.isGetData = true;
memset(Save_Data.GPS_Buffer, 0, 120); //清空
memcpy(Save_Data.GPS_Buffer, Rec_Buf, point1);
parseGpsBuffer();
printGpsBuffer();
delay_ms(4000);
}
}
void sendDataToServer()
{
xdata char send_buf[100] = {0};
memset(send_buf, 0, 100); //清空
if(s2==0)
{
if(flagConnect == 0)
{
flagConnect = 1;
strcpy(send_buf, "AT+QIOPEN="TCP","");
strcat(send_buf, TCPServer);
strcat(send_buf, "","");
strcat(send_buf, Port2);
strcat(send_buf, "" ");
if (sendCommand(send_buf, "CONNECT OK", 10000, 5) == Success);
else errorLog();
delay_ms(100);
}
//发送数据
if (sendCommand("AT+QISEND ", ">", 3000, 5) == Success);
else errorLog();
delay_ms(1000);
memset(send_buf, 0, 100); //清空
{sprintf(send_buf,"%s N,%s E ID01 SOS ",
Save_Data.latitude,Save_Data.longitude );}
Init_LCD1602();
LCD1602_write_com(0x80);
LCD1602_write_word("Message has ");
LCD1602_write_com(0x80+0x40);
LCD1602_write_word(" been sent ");
if (sendCommand(send_buf, send_buf, 3000, 1) == Success);
else errorLog();
delay_ms(10);
SendData(0x1a);//发送数据
}
else
{
if(flagConnect == 0)
{
flagConnect = 1;
strcpy(send_buf, "AT+QIOPEN="TCP","");
strcat(send_buf, TCPServer);
strcat(send_buf, "","");
strcat(send_buf, Port);
strcat(send_buf, "" ");
if (sendCommand(send_buf, "CONNECT OK", 10000, 5) == Success);
else errorLog();
delay_ms(100);
}
//发送数据
if (sendCommand("AT+QISEND ", ">", 3000, 5) == Success);
else errorLog();
delay_ms(1000);
memset(send_buf, 0, 100); //清空
{sprintf(send_buf,"%s N,%s E ID01 ",
Save_Data.latitude,Save_Data.longitude); }
if (sendCommand(send_buf, send_buf, 3000, 1) == Success);
else errorLog();
delay_ms(10);
SendData(0x1a);}//发送数据
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1条回答
zhangxjjoy
2019-07-18 15:37
void errorLog()
{
while (1)
{
if (sendCommand("AT ", "OK ", 100, 10) == Success)
{
soft_reset();
}
delay_ms(200);
}
}
void soft_reset(void) //制造重启命令
{
((void (code *) (void)) 0x0000) ();
}
unsigned int sendCommand(char *Command, char *Response, unsigned long Timeout, unsigned char Retry)
{
unsigned char n;
CLR_Buf();
for (n = 0; n < Retry; n++)
{
SendString(Command); //发送GPRS指令
Time_Cont = 0;
while (Time_Cont < Timeout)
{
delay_ms(100);
Time_Cont += 100;
if (strstr(Rec_Buf, Response) != NULL)
{
return Success;
}
}
Time_Cont = 0;
}
CLR_Buf();
return Failure;
}
void parseGpsBuffer()
{
char *subString;
char *subStringNext;
char i = 0;
if (Save_Data.isGetData)
{
Save_Data.isGetData = false;
// SendString("************** ");
// SendString(Save_Data.GPS_Buffer);
for (i = 0 ; i <= 6 ; i++)
{
if (i == 0)
{
if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL)
errorLog(); //解析错误
}
else
{
subString++;
if ((subStringNext = strstr(subString, ",")) != NULL)
{
char usefullBuffer[2];
switch(i)
{
// case 1:memcpy(Save_Data.UTCTime, subString, subStringNext - subString);break; //获取UTC时间
case 2:memcpy(usefullBuffer, subString, subStringNext - subString);break;
case 3:
memset(Save_Data.latitude, 0, latitude_Length);
memcpy(Save_Data.latitude, subString, subStringNext - subString);break; //获取纬度信息
case 4:
memset(Save_Data.N_S, 0, N_S_Length);
memcpy(Save_Data.N_S, subString, subStringNext - subString);break; //获取N/S
case 5:
memset(Save_Data.longitude, 0, longitude_Length);
memcpy(Save_Data.longitude, subString, subStringNext - subString);break; //获取经度信息
case 6:
memset(Save_Data.E_W, 0, E_W_Length);
memcpy(Save_Data.E_W, subString, subStringNext - subString);break; //获取E/W
default:break;
}
subString = subStringNext;
Save_Data.isParseData = true;
if(usefullBuffer[0] == 'A')
Save_Data.isUsefull = true;
else if(usefullBuffer[0] == 'V')
Save_Data.isUsefull = false;
}
else
{
errorLog(); //解析错误
}
}
}
}
}
void printGpsBuffer()
{
if (Save_Data.isParseData)
{
Save_Data.isParseData = false;
// SendString("Save_Data.UTCTime = ");
// SendString(Save_Data.UTCTime);
// SendString(" ");
if(Save_Data.isUsefull)
{
// Save_Data.isUsefull = false;
// SendString("Save_Data.latitude = ");
// SendString(Save_Data.latitude);
// SendString(" ");
//
//
// SendString("Save_Data.N_S = ");
// SendString(Save_Data.N_S);
// SendString(" ");
//
// SendString("Save_Data.longitude = ");
// SendString(Save_Data.longitude);
// SendString(" ");
//
// SendString("Save_Data.E_W = ");
// SendString(Save_Data.E_W);
// SendString(" ");
LCD1602_write_com(0x80);
LCD1602_write_word(Save_Data.latitude);
LCD1602_write_data(' ');
LCD1602_write_word(Save_Data.N_S);
LCD1602_write_word(" ");
LCD1602_write_com(0x80+0x40);
LCD1602_write_word(Save_Data.longitude);
LCD1602_write_data(' ');
LCD1602_write_word(Save_Data.E_W);
LCD1602_write_word(" ");
sendDataToServer();
}
else
{
// SendString("GPS DATA is not usefull! ");
LCD1602_write_com(0x80);
LCD1602_write_word("GPS DATA is ");
LCD1602_write_com(0x80+0x40);
LCD1602_write_word(" not usefull ");
}
}
}
void clrStruct()
{
Save_Data.isGetData = false;
Save_Data.isParseData = false;
Save_Data.isUsefull = false;
memset(Save_Data.GPS_Buffer, 0, GPS_Buffer_Length); //清空
// memset(Save_Data.UTCTime, 0, UTCTime_Length);
memset(Save_Data.latitude, 0, latitude_Length);
memset(Save_Data.N_S, 0, N_S_Length);
memset(Save_Data.longitude, 0, longitude_Length);
memset(Save_Data.E_W, 0, E_W_Length);
}
//****************************************************
//MS延时函数
//****************************************************
void delay_ms(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<123;j++);
}
加载中...
一周热门
更多
>
相关问题
STM32开发板免费用活动
7 个回答
无线通讯电子电路图
3 个回答
求3DA92 3DA89 3DA37 高频放大管的外围电路
1 个回答
中波收音机为什么通常要采用环形天线呢?
4 个回答
相关文章
物联网通信协议——物联网数据协议
0个评论
基于AM335X的物联网关解决方案
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
物联网
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
void errorLog()
{
while (1)
{
if (sendCommand("AT ", "OK ", 100, 10) == Success)
{
soft_reset();
}
delay_ms(200);
}
}
void soft_reset(void) //制造重启命令
{
((void (code *) (void)) 0x0000) ();
}
unsigned int sendCommand(char *Command, char *Response, unsigned long Timeout, unsigned char Retry)
{
unsigned char n;
CLR_Buf();
for (n = 0; n < Retry; n++)
{
SendString(Command); //发送GPRS指令
Time_Cont = 0;
while (Time_Cont < Timeout)
{
delay_ms(100);
Time_Cont += 100;
if (strstr(Rec_Buf, Response) != NULL)
{
return Success;
}
}
Time_Cont = 0;
}
CLR_Buf();
return Failure;
}
void parseGpsBuffer()
{
char *subString;
char *subStringNext;
char i = 0;
if (Save_Data.isGetData)
{
Save_Data.isGetData = false;
// SendString("************** ");
// SendString(Save_Data.GPS_Buffer);
for (i = 0 ; i <= 6 ; i++)
{
if (i == 0)
{
if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL)
errorLog(); //解析错误
}
else
{
subString++;
if ((subStringNext = strstr(subString, ",")) != NULL)
{
char usefullBuffer[2];
switch(i)
{
// case 1:memcpy(Save_Data.UTCTime, subString, subStringNext - subString);break; //获取UTC时间
case 2:memcpy(usefullBuffer, subString, subStringNext - subString);break;
case 3:
memset(Save_Data.latitude, 0, latitude_Length);
memcpy(Save_Data.latitude, subString, subStringNext - subString);break; //获取纬度信息
case 4:
memset(Save_Data.N_S, 0, N_S_Length);
memcpy(Save_Data.N_S, subString, subStringNext - subString);break; //获取N/S
case 5:
memset(Save_Data.longitude, 0, longitude_Length);
memcpy(Save_Data.longitude, subString, subStringNext - subString);break; //获取经度信息
case 6:
memset(Save_Data.E_W, 0, E_W_Length);
memcpy(Save_Data.E_W, subString, subStringNext - subString);break; //获取E/W
default:break;
}
subString = subStringNext;
Save_Data.isParseData = true;
if(usefullBuffer[0] == 'A')
Save_Data.isUsefull = true;
else if(usefullBuffer[0] == 'V')
Save_Data.isUsefull = false;
}
else
{
errorLog(); //解析错误
}
}
}
}
}
void printGpsBuffer()
{
if (Save_Data.isParseData)
{
Save_Data.isParseData = false;
// SendString("Save_Data.UTCTime = ");
// SendString(Save_Data.UTCTime);
// SendString(" ");
if(Save_Data.isUsefull)
{
// Save_Data.isUsefull = false;
// SendString("Save_Data.latitude = ");
// SendString(Save_Data.latitude);
// SendString(" ");
//
//
// SendString("Save_Data.N_S = ");
// SendString(Save_Data.N_S);
// SendString(" ");
//
// SendString("Save_Data.longitude = ");
// SendString(Save_Data.longitude);
// SendString(" ");
//
// SendString("Save_Data.E_W = ");
// SendString(Save_Data.E_W);
// SendString(" ");
LCD1602_write_com(0x80);
LCD1602_write_word(Save_Data.latitude);
LCD1602_write_data(' ');
LCD1602_write_word(Save_Data.N_S);
LCD1602_write_word(" ");
LCD1602_write_com(0x80+0x40);
LCD1602_write_word(Save_Data.longitude);
LCD1602_write_data(' ');
LCD1602_write_word(Save_Data.E_W);
LCD1602_write_word(" ");
sendDataToServer();
}
else
{
// SendString("GPS DATA is not usefull! ");
LCD1602_write_com(0x80);
LCD1602_write_word("GPS DATA is ");
LCD1602_write_com(0x80+0x40);
LCD1602_write_word(" not usefull ");
}
}
}
void clrStruct()
{
Save_Data.isGetData = false;
Save_Data.isParseData = false;
Save_Data.isUsefull = false;
memset(Save_Data.GPS_Buffer, 0, GPS_Buffer_Length); //清空
// memset(Save_Data.UTCTime, 0, UTCTime_Length);
memset(Save_Data.latitude, 0, latitude_Length);
memset(Save_Data.N_S, 0, N_S_Length);
memset(Save_Data.longitude, 0, longitude_Length);
memset(Save_Data.E_W, 0, E_W_Length);
}
//****************************************************
//MS延时函数
//****************************************************
void delay_ms(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<123;j++);
}
一周热门 更多>