将GPS Shield数据发送到GPRS Shiled(Sim900)

时间:2017-06-17 20:29:15

标签: gps arduino-uno gsm sim900

我正在开展车辆遥测项目。为此,我试图从GPS盾牌获取GPS数据,并使用Sim900 GSM / GPRS屏蔽Get命令将它们发送到thingpeak。我使用的主板是Arduino Uno。

问题是我使用的GSM / GPRS屏蔽仅使用4800波特率,当它使用http时。我的GPS正在以9600波特率工作。我正在使用两个屏蔽,并在单独的操作(GSM / GPRS和GPS沿)设备工作很好。在集成测试中(将两个屏蔽连接到Arduino Uno时)GPS数据不会通过GSM / GPRS屏蔽发送到thingpeak。此外,我尝试在代码旁边获取GPS数据。它对我不起作用!代码如下。

PS - 我在同一主题下阅读了旧帖子,但AltSoftSerial对我不起作用。

#include <SoftwareSerial.h>
#include <String.h>
#include "TinyGPS++.h"

int fixed = 0;
int led = 13;
TinyGPSPlus gps;
SoftwareSerial mySerial(4, 5); //GSM
SoftwareSerial SoftSerial(2, 3); //GPS
float longi = gps.location.lng();
float lati = gps.location.lat();


void setup() {
  SoftSerial.begin(9600); //Start GPS
  mySerial.begin(4800); //Start GSM
  Serial.begin(4800); //Start Serial Monitor
  delay(10000);
}

void loop() {
  longi = gps.location.lng();
  lati = gps.location.lat();
  GPSCord();
  Send2Think();


  if(mySerial.available()){
    Serial.write(mySerial.read());
  }
}

void Send2Think(){



  mySerial.println("AT");
  delay(500);
  //SoftSerial.println("HELLO");

  mySerial.println("AT+CPIN?");
  delay(500);
  //SoftSerial.println("HELLO");

  mySerial.println("AT+CREG?");
  delay(500);

  mySerial.println("AT+CGATT?");
  delay(500);

  mySerial.println("AT+CIPSHUT");
  delay(500);

  mySerial.println("AT+CIPSTATUS");
  delay(500);

  mySerial.println("AT+CIPMUX=0");
  delay(500);

  ShowSerialData();

  mySerial.println("AT+CSTT=\"hutch3g\"");//start task and setting the APN,
  delay(1000);
  SoftSerial.println("HELLO");

  ShowSerialData();

  mySerial.println("AT+CIICR");//bring up wireless connection
  delay(3000);

  ShowSerialData();

  mySerial.println("AT+CIFSR");//get local IP adress
  delay(2000);

  ShowSerialData();

  mySerial.println("AT+CIPSPRT=0");
  delay(3000);

  ShowSerialData();

  mySerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
  delay(6000);

  ShowSerialData();

  mySerial.println("AT+CIPSEND");//begin send data to remote server
  delay(4000);
  ShowSerialData();

  String str1="GET https://api.thingspeak.com/update?api_key=FF19NVWMPZEWX0XK&field2=" + String(lati)+ "&field3=" + String(longi);
  mySerial.println(str1);//begin send data to remote server

  delay(4000);
  ShowSerialData();

  mySerial.println((char)26);//sending
  delay(5000);//waitting for reply, important! the time is base on the condition of internet 
  mySerial.println();
  ShowSerialData();

  mySerial.println("AT+CIPSHUT");//close the connection
  delay(100);
  ShowSerialData();
}

void ShowSerialData()
{
  while(mySerial.available()!=0)
    Serial.write(mySerial.read());
}

void GPSCord(){
  while (SoftSerial.available() > 0)
  gps.encode(SoftSerial.read());

  if (gps.location.isUpdated())
  {
    fixed = 1;
    Serial.print("LAT="); Serial.print(gps.location.lat(), 6);
    Serial.print(" LNG="); Serial.println(gps.location.lng(), 6);
  }

  if(fixed ==0)
  {
     digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
     delay(300);               // wait for a second
     digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
     delay(300);  
  }
  if (gps.altitude.isUpdated())
  {
    Serial.print("Altitude:");
    Serial.println(gps.altitude.meters());
  }
}

0 个答案:

没有答案