久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5826|回復: 5
收起左側

STM32+Air800模塊GPS定位和GPRS發送到服務器STM32源程序下載

[復制鏈接]
ID:308658 發表于 2018-12-2 16:53 | 顯示全部樓層 |閱讀模式
基于STM32的Air800模塊GPS衛星定位和GPRS通訊發送到服務器代碼

單片機源程序如下:
  1. #include "delay.h"
  2. #include "sys.h"
  3. #include "usart.h"        
  4. #include "bluetooth.h"
  5. #include "Air800.h"
  6. #include "timer.h"
  7. #include "GPIO.h"

  8. /***我的疑問*******/
  9. /*
  10.   查詢GPS信息,發AT指令通過主串口還是GPS串口發送
  11. */

  12. int main(void)
  13. {
  14.         delay_init();                     //延時函數初始化         
  15.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //設置NVIC中斷分組0:0位搶占優先級,4位響應優先級
  16.         GPIO_init();
  17.         nvic_init();
  18.         TIM3_Int_Init(1999,71);//20ms
  19.         uart_init(9600);         //串口初始化為9600
  20.         air800_init();
  21.         bluetooth_init();
  22.         while(1)
  23.         {
  24.                 bluetooth_link(blue_MAC);//藍牙連接
  25.                 GPS_deal();
  26.                 GPRS_send();
  27.                 LED_Status();
  28.         }
  29. }
復制代碼
  1. #include "Air800.h"
  2. #include "delay.h"
  3. #include "usart.h"
  4. #include "bluetooth.h"
  5. #include "timer.h"
  6. #include "math.h"
  7. GPS gps;

  8. char IPaddress[IPaddress_LEN];
  9. u8 GPRS_TX_BUF[GPRS_Buf_len];
  10. u8 flag_gprs_send=0,flag_set=0;

  11. void air800_init()
  12. {
  13.         //開機
  14.         PWRKEY=0;
  15.         delay_ms(1500);
  16.         PWRKEY=1;        
  17.         delay_ms(2500);

  18.         flag_set=1;//進入配置模式
  19. /******以下是GPRS初始化配置********/
  20.         Air_send_instructions("\r\nTX\r\n");
  21.   //設置波特率9600
  22.         Air_send_instructions("\r\nAT+IPR=9600:&W\r\n");
  23.         //使模塊附著GPRS網絡
  24.         Air_send_instructions("\r\nAT+CGATT=1\r\n");
  25.         //設置透傳模式
  26.         Air_send_instructions("\r\nAT+CIPMODE=1\r\n");
  27.         //設置APN
  28.         Air_send_instructions("\r\nAT+CSTT=\"CMNET\"\r\n");
  29.         //激活移動場景,建立無線連接
  30.         Air_send_instructions("\r\nAT+CIICR\r\n");
  31.         //查詢分配的IP地址
  32.         Air_send_instructions("\r\nAT+CIFSR\r\n");
  33.         //設置要連接的遠端服務器類型
  34.         Air_send_instructions("\r\nAT+CIPSTART=\"TCP\",\"60.166.18.9\",7500\r\n");
  35.         
  36. /******以上是GPRS初始化配置********/
  37.         
  38.         
  39.         
  40.         
  41. /******以下是GPS初始化配置********/
  42.         
  43.         //打開GPS
  44.         Air_send_instructions("\r\nAT+CGNSPWR=1\r\n");
  45.         //設置NMEA語句類型
  46.         Air_send_instructions("\r\nAT+CGNSSEQ=\"RMC\" \r\n");
  47.         
  48. /******以上是GPS初始化配置********/
  49.         flag_set=0;//結束配置模式
  50. }
  51. /*********************************************************
  52. 函數名稱:Air_send_instructions
  53. 功    能:配置Air800模塊的指令函數
  54. 參    數:
  55. *********************************************************/
  56. void Air_send_instructions(char array[])
  57. {
  58.         u8 i=0,len;
  59.         len=strlen(array);
  60.         strcpy(USART_TX_BUF,array);
  61.   for(i=0;i<len;i++)
  62.         {
  63.                 USART_SendData(USART1,USART_TX_BUF[i]);
  64.         }
  65.         while(flag_RX_ok==0);//判斷反饋是否成功
  66.         flag_RX_ok=0;
  67. }
  68. /*********************************************************
  69. 函數名稱:parse_gpsBuffer
  70. 功    能:解析GPS信息
  71. 參    數:
  72. *********************************************************/
  73. void parse_gpsBuffer()
  74. {
  75.         u8 i=0;
  76.         char *string;
  77.         char *string_next;
  78.         
  79.         if(gps.RX_success==1)
  80.         {
  81.                 gps.fix_status=gps.Buffer[1]-'0';//獲取GPS是否定位
  82.                 for(i=0;i<=3;i++)
  83.                 {
  84.                         if(i==0) string=strstr(gps.Buffer, ",");
  85.                         string++;
  86.                         if((string_next = strstr(string, ",")) != NULL)//檢驗GNSS運行狀態
  87.                         {
  88.                                 switch(i)
  89.                                 {
  90.                                         case 1:memcpy(gps.UTCTime,string,string_next-string);break;//UTC時間
  91.                                         case 2:memcpy(gps.latitudebuffer,string,string_next-string);break;//緯度
  92.                                         case 3:memcpy(gps.longitudebuffer,string,string_next-string);break;//經度
  93.                                   default:break;
  94.                                 }
  95.                                 string=string_next;
  96.                         }
  97.                         else
  98.                         {
  99.                                 gps.RX_success=0;
  100.                                 memset(gps.Buffer,0,GPS_Buffer_Length);//清空無效數據
  101.                                 break;//跳出for
  102.                         }
  103.                 }
  104.                 parse_gpstime(gps.UTCTime);//提取時間日期
  105.                 parse_gps_location(gps.latitudebuffer,gps.longitudebuffer);//提取經緯度
  106.                 memset(gps.Buffer,0,GPS_Buffer_Length);//清空
  107.                 memset(gps.UTCTime,0,UTCTime_Length);//清空
  108.                 memset(gps.latitudebuffer,0,latitude_Length);//清空
  109.                 memset(gps.longitudebuffer,0,longitude_Length);//清空
  110.         }
  111. }
  112.         
  113. /*********************************************************
  114. 函數名稱:parse_gpstime
  115. 功    能:提取GPS轉換北京時間日期
  116. 參    數:
  117. *********************************************************/

  118. void parse_gpstime(char array[])
  119. {
  120.         gps.year=(array[0]-'0')*1000+(array[1]-'0')*100+(array[2]-'0')*10+(array[3]-'0');
  121.         gps.month=(array[4]-'0')*10+(array[5]-'0');
  122.         gps.day=(array[6]-'0')*10+(array[7]-'0');
  123.         gps.hour=(array[8]-'0')*10+(array[9]-'0');
  124.   gps.minute=(array[10]-'0')*10+(array[11]-'0');
  125.         gps.second=(array[11]-'0')*10+(array[12]-'0');
  126.         //北京時間=UTC+8;
  127.         gps.hour+=8;
  128.         if(gps.hour>23)
  129.         {
  130.                 gps.hour=gps.hour-24;
  131.                 gps.day++;
  132.                 if(gps.day>28)
  133.                 {
  134.                         if(gps.month==2)
  135.                         {
  136.                                 if(gps.year%400==0||(gps.year%100!=0&&gps.year%4==0))//閏年
  137.                                 {
  138.                                         if(gps.day>29)
  139.                                         {
  140.                                                 gps.month=3;
  141.                                           gps.day=1;
  142.                                         }
  143.                                 }
  144.                                 else//平年
  145.                                 {
  146.                                         gps.month=3;
  147.                                         gps.day=1;
  148.                                 }
  149.                         }
  150.                         else if(gps.month==4||gps.month==6||gps.month==9||gps.month==11)//day為30天
  151.                         {
  152.                                 if(gps.day>30)
  153.                                 {
  154.                                         gps.day=1;
  155.                                         gps.month++;
  156.                                 }
  157.                         }
  158.                         else if(gps.month==1||gps.month==3||gps.month==5||gps.month==7||gps.month==8||gps.month==10||gps.month==12)//day為31天
  159.                         {
  160.                                 if(gps.day>31)
  161.                                 {
  162.                                         if(gps.month==12)
  163.                                         {
  164.                                                 gps.day=1;
  165.                                                 gps.month=1;
  166.                                                 gps.year++;
  167.                                         }
  168.                                         else
  169.                                         {
  170.                                                 gps.day=1;
  171.                                                 gps.month++;
  172.                                         }
  173.                                 }
  174.                         }
  175.                 }
  176.         }
  177. }

  178. /*********************************************************
  179. 函數名稱:parse_gps_location
  180. 功    能:提取GPS的經緯度并放大10^6
  181. 參    數:
  182. *********************************************************/
  183. void parse_gps_location(char lat[],char lon[])
  184. {
  185.         u8 i=0;
  186.         char *string;
  187.         
  188.         //獲得放大10^6的經度值
  189.         if(lat[0]=='-')
  190.         {
  191.                 gps.EW=1;//西經為1
  192.                 string=strstr(lat, ",");
  193.                 for(i=1;i<(string-lat);i++)
  194.                 {
  195.                         gps.latitude+=(lat[i]-'0')*pow(10,string-lat-i-1+6);//放大10^6倍
  196.                 }
  197.                 for(i=0;i<6;i++)
  198.                 {
  199.                         ++string;
  200.                         gps.latitude+=((*string)-'0')*pow(10,5-i);
  201.                 }
  202.         }
  203.         else
  204.         {
  205.                 gps.EW=0;
  206.                 string=strstr(lat, ",");
  207.                 for(i=0;i<(string-lat);i++)
  208.                 {
  209.                         gps.latitude+=(lat[i]-'0')*pow(10,string-lat-i-1+6);//放大10^6倍
  210.                 }
  211.                 for(i=0;i<6;i++)
  212.                 {
  213.                         ++string;
  214.                         gps.latitude+=((*string)-'0')*pow(10,5-i);
  215.                 }
  216.         }
  217.         
  218.         //獲得放大10^6的緯度值
  219.         if(lon[0]=='-')
  220.         {
  221.                 gps.NS=1;//南緯為1
  222.                 string=strstr(lon, ",");
  223.                 for(i=1;i<(string-lon);i++)
  224.                 {
  225.                         gps.longitude+=(lon[i]-'0')*pow(10,string-lon-i-1+6);//放大10^6倍
  226.                 }
  227.                 for(i=0;i<6;i++)
  228.                 {
  229.                         ++string;
  230.                         gps.longitude+=((*string)-'0')*pow(10,5-i);
  231.                 }
  232.         }
  233.         else
  234.         {
  235.                 gps.NS=0;
  236.                 string=strstr(lon, ",");
  237.                 for(i=0;i<(string-lon);i++)
  238.                 {
  239.                         gps.longitude+=(lon[i]-'0')*pow(10,string-lon-i-1+6);//放大10^6倍
  240.                 }
  241.                 for(i=0;i<6;i++)
  242.                 {
  243.                         ++string;
  244.                         gps.longitude+=((*string)-'0')*pow(10,5-i);
  245.                 }
  246.         }
  247. }
  248. void GPS_deal()
  249. {
  250.         if(gps.RX_success==0) Air_send_instructions("\r\nAT+CGNSINF\r\n");//查詢GPS的GNSS信息
  251.         
  252.         parse_gpsBuffer();//解析GPS信息
  253. }

  254. /*********************************************************
  255. 函數名稱:GPRS_send
  256. 功    能:GPRS發送函數
  257. 參    數:
  258. *********************************************************/
  259. void GPRS_send()
  260. {
  261.         u8 i=0;
  262.         u32 *ptr;
  263.         
  264.         if(flag_bluetooth_ok&&gps.RX_success&&time_count==100)
  265.         {
  266.                 flag_gprs_send=1;//GPRS發送標志
  267.                 strcpy(USART_TX_BUF,"\r\nAT+CIPSEN\r\n");
  268.                 for(i=0;i<strlen("\r\nAT+CIPSEN\r\n");i++)
  269.                 {
  270.                         USART_SendData(USART1,USART_TX_BUF[i]);
  271.                 }
  272.                 memset(USART_TX_BUF,0,USART_LEN);//清空
  273.         
  274.                 GPRS_TX_BUF[0]='\r';
  275.                 GPRS_TX_BUF[1]='\n';
  276.                 GPRS_TX_BUF[2]='>';
  277.                 GPRS_TX_BUF[3]=0x7e;//標識位
  278.         
  279.                 //消息頭
  280.                 GPRS_TX_BUF[4]=0x02;
  281.                 GPRS_TX_BUF[5]=0x00;
  282.                 GPRS_TX_BUF[6]=0x00;
  283.                 GPRS_TX_BUF[7]=0x1c;//消息體長度28
  284.                 GPRS_TX_BUF[8]=0x00;
  285.                 GPRS_TX_BUF[9]=0x00;
  286.                 GPRS_TX_BUF[10]=0x00;
  287.                 GPRS_TX_BUF[11]=0x00;
  288.                 GPRS_TX_BUF[12]=0x00;
  289.                 GPRS_TX_BUF[13]=0x00;
  290.                 GPRS_TX_BUF[14]=0x00;
  291.                 GPRS_TX_BUF[15]=0x00;
  292.         
  293.                 //消息體
  294.                 GPRS_TX_BUF[16]=0x00;
  295.                 GPRS_TX_BUF[17]=0x00;
  296.                 GPRS_TX_BUF[18]=0x00;
  297.                 GPRS_TX_BUF[19]=0x00;
  298.         
  299.                 GPRS_TX_BUF[20]=0x00;
  300.                 GPRS_TX_BUF[21]=0x04;//狀態為GPS定位
  301.                 GPRS_TX_BUF[22]=0x00;
  302.                 GPRS_TX_BUF[23]=gps.fix_status*2+gps.NS*4+gps.EW*8;//GPS的定位,經緯狀態

  303.                 ptr=(u32*)(&(GPRS_TX_BUF[24]));
  304.                 *ptr=gps.longitude;//緯度值
  305.                 ++ptr;
  306.                 *ptr=gps.latitude;//經度值
  307.         
  308.                 GPRS_TX_BUF[32]=0x00;
  309.                 GPRS_TX_BUF[33]=0x00;

  310.                 GPRS_TX_BUF[34]=heart_rate;//心率
  311.                 GPRS_TX_BUF[35]=blood_oxygen;//血氧
  312.         
  313.                 GPRS_TX_BUF[36]=0x00;
  314.                 GPRS_TX_BUF[37]=0x00;
  315.         
  316.                 GPRS_TX_BUF[38]=gps.year;
  317.                 GPRS_TX_BUF[39]=gps.month;
  318.                 GPRS_TX_BUF[40]=gps.day;
  319.                 GPRS_TX_BUF[41]=gps.hour;
  320.                 GPRS_TX_BUF[42]=gps.minute;
  321.                 GPRS_TX_BUF[43]=gps.second;
  322.   
  323.                 //檢驗碼 從消息頭開始到結尾字節異或
  324.                 GPRS_TX_BUF[44]=0;
  325.                 for(i=4;i<=43;i++)
  326.                 {
  327.                         GPRS_TX_BUF[44]^=GPRS_TX_BUF[i];
  328.                 }

  329.                 GPRS_TX_BUF[45]=0x7e;//標識位
  330.                 GPRS_TX_BUF[46]=0x1A;
  331.                 GPRS_TX_BUF[47]='\r';
  332.                 GPRS_TX_BUF[48]='\n';
  333.         
  334.                 for(i=0;i<=48;i++)
  335.                 {
  336.                         USART_SendData(USART1,GPRS_TX_BUF[i]);        
  337.                 }
  338.                 while(flag_RX_ok==0);//判斷反饋是否成功
  339.                 flag_RX_ok=0;
  340.         
  341.         }
  342. }
復制代碼


所有資料51hei提供下載:
STM32.20181028.rar (293.72 KB, 下載次數: 120)
回復

使用道具 舉報

ID:402609 發表于 2019-5-6 20:15 | 顯示全部樓層
你好,請問有視頻教學么?這個能連到阿里云么?
回復

使用道具 舉報

ID:523363 發表于 2019-5-7 09:31 | 顯示全部樓層
目前正在開發一個基于HT32+air802T的GPS/GPRS的產品,類似于LZ,感謝!
回復

使用道具 舉報

ID:523829 發表于 2019-8-1 13:32 | 顯示全部樓層
可以  只是代碼有點亂
回復

使用道具 舉報

ID:523829 發表于 2019-8-6 15:29 | 顯示全部樓層
調試了 串口沒輸出 是啥原因
回復

使用道具 舉報

ID:882275 發表于 2022-1-25 12:51 | 顯示全部樓層
代碼能跑起來嗎?有沒有帶硬件的電路圖
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久久久久久久久久久久9999 | 成人精品视频99在线观看免费 | 国产精品久久久久久久久久了 | 特级黄色毛片 | 一本大道久久a久久精二百 国产成人免费在线 | 成人午夜免费网站 | 亚洲精品福利视频 | 免费久久精品视频 | 老子午夜影院 | 亚洲国产aⅴ成人精品无吗 综合国产在线 | 操操操av| 福利社午夜影院 | 91豆花视频 | 色桃网| 99re| 国产精品视频免费观看 | 国产精品3区| 在线观看一区 | 国产区在线 | 日韩视频一区二区三区 | 亚洲精品福利视频 | 欧美黄视频 | 日韩小视频在线 | 精品久久久久久久久久久下田 | 亚洲乱码国产乱码精品精98午夜 | 国产精品激情小视频 | 国产综合欧美 | 欧美精品一区在线 | 成人欧美一区二区三区在线播放 | 浮生影院免费观看中文版 | 日韩不卡一区二区 | 中文字幕av中文字幕 | 亚洲国产aⅴ成人精品无吗 国产精品永久在线观看 | 婷婷丁香激情 | 国产一区视频在线 | 福利视频三区 | 日韩伦理一区二区 | 一区二区三区av夏目彩春 | a级在线观看 | 国产91九色| 国产成人网|