Skip to main content
Arduino

Return to Question

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <Ubidots_Arduino_GPRS.h>
//Serial Relay - Arduino will patch a 
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART 
#define APN "myapn" 
#define USER "" // If your apn doesnt have username just put ""
#define PASS "" // If your apn doesnt have password just put ""
#define TOKEN "ubidotsToken" // Replace it with your Ubidots token
#define ID "Your_id_here" // Replace it with your Ubidots' variable ID
// You can send 1 to 10 variable at the same time
#define ID1 "idHere" // Replace it with your variable ID
//#define ID2 "" // Replace it with your variable ID
//#define ID3 "Your_id_here" // Replace it with your variable ID
TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
//Declare indexes, and strings
char latitude[12];
char longitude[12];
float value_1 = 1;
char var[18] = "Lat: ";
char var2[18] = "Long: ";
Ubidots client(TOKEN); 
SoftwareSerial ss(2,3);
void setup() {
 
// the Serial port of Arduino baud rate.
 Serial.begin(9600); 
 
 client.powerUpOrDown();
 client.setApn(APN,USER,PASS);
//.endC is for _client.end() in Ubidots_GPRS.cpp
 client.endC();
 ss.begin(9600);
}
void loop() {
 
 //handling GPS data parsing
 while (ss.available() > 0) {
 gps.encode(ss.read());}
 //Once a valid location comes up it updates Lat/Long variables
 if (gps.location.isUpdated())
{
 strcpy(var, "Lat: ");
 strcpy(var2,"Long: ");
 
 dtostrf(gps.location.lat(),10,6,latitude);
 strcat(var, latitude);
 
 dtostrf(gps.location.lng(),10,6,longitude);
 strcat(var2, longitude);
 //Added ss.flush();
 ss.flush();
 ss.end();
 Serial.flush()
 //Added client.beginC() for _client.begin(9600) is Ubidots_GPRS.cpp
 client.beginC();
 client.add(ID1, value_1, var, var2);
 client.sendAll();
 client.endC();
 ss.begin(9600);
 }
 Serial.println(var);
 Serial.println(var2);
}
 #include <SoftwareSerial.h>
 #include <TinyGPS++.h>
 #include <Ubidots_Arduino_GPRS.h>
 //Serial Relay - Arduino will patch a 
 //serial link between the computer and the GPRS Shield
 //at 19200 bps 8-N-1
 //Computer is connected to Hardware UART
 //GPRS Shield is connected to the Software UART 
 #define APN "myapn" 
 #define USER "" // If your apn doesnt have username just put ""
 #define PASS "" // If your apn doesnt have password just put ""
 #define TOKEN "ubidotsToken" // Replace it with your Ubidots token
 #define ID "Your_id_here" // Replace it with your Ubidots' variable ID
 // You can send 1 to 10 variable at the same time
 #define ID1 "idHere" // Replace it with your variable ID
 //#define ID2 "" // Replace it with your variable ID
 //#define ID3 "Your_id_here" // Replace it with your variable ID
 
 TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
 //Declare indexes, and strings
 char latitude[12];
 char longitude[12];
 float value_1 = 1;
 char var[18] = "Lat: ";
 char var2[18] = "Long: ";
 Ubidots client(TOKEN); 
 SoftwareSerial ss(2,3);
 void setup() {
 
 // the Serial port of Arduino baud rate.
 Serial.begin(9600); 
 
 client.powerUpOrDown();
 client.setApn(APN,USER,PASS);
 //.endC is for _client.end() in Ubidots_GPRS.cpp
 client.endC();
 ss.begin(9600);
 }
 
 void loop() {
 
 //handling GPS data parsing
 while (ss.available() > 0) {
 gps.encode(ss.read());}
 //Once a valid location comes up it updates Lat/Long variables
 if (gps.location.isUpdated())
 {
 strcpy(var, "Lat: ");
 strcpy(var2,"Long: ");
 
 dtostrf(gps.location.lat(),10,6,latitude);
 strcat(var, latitude);
 
 dtostrf(gps.location.lng(),10,6,longitude);
 strcat(var2, longitude);
 //Added ss.flush();
 ss.flush();
 ss.end();
 Serial.flush()
 //Added client.beginC() for _client.begin(9600) is Ubidots_GPRS.cpp
 client.beginC();
 client.add(ID1, value_1, var, var2);
 client.sendAll();
 client.endC();
 ss.begin(9600);
 }
 Serial.println(var);
 Serial.println(var2);
 }

From this link, I moved the printlnprintln from inside .isUpdated().isUpdated() to outside the if statement. I was able to get GPS data sent from the unit to my Ubidots account while driving around town. Afterwards I was able to input the data into Google Maps and the route produced was accurate. Do I need flush()?

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <Ubidots_Arduino_GPRS.h>
//Serial Relay - Arduino will patch a 
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART 
#define APN "myapn" 
#define USER "" // If your apn doesnt have username just put ""
#define PASS "" // If your apn doesnt have password just put ""
#define TOKEN "ubidotsToken" // Replace it with your Ubidots token
#define ID "Your_id_here" // Replace it with your Ubidots' variable ID
// You can send 1 to 10 variable at the same time
#define ID1 "idHere" // Replace it with your variable ID
//#define ID2 "" // Replace it with your variable ID
//#define ID3 "Your_id_here" // Replace it with your variable ID
TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
//Declare indexes, and strings
char latitude[12];
char longitude[12];
float value_1 = 1;
char var[18] = "Lat: ";
char var2[18] = "Long: ";
Ubidots client(TOKEN); 
SoftwareSerial ss(2,3);
void setup() {
 
// the Serial port of Arduino baud rate.
 Serial.begin(9600); 
 
 client.powerUpOrDown();
 client.setApn(APN,USER,PASS);
//.endC is for _client.end() in Ubidots_GPRS.cpp
 client.endC();
 ss.begin(9600);
}
void loop() {
 
 //handling GPS data parsing
 while (ss.available() > 0) {
 gps.encode(ss.read());}
 //Once a valid location comes up it updates Lat/Long variables
 if (gps.location.isUpdated())
{
 strcpy(var, "Lat: ");
 strcpy(var2,"Long: ");
 
 dtostrf(gps.location.lat(),10,6,latitude);
 strcat(var, latitude);
 
 dtostrf(gps.location.lng(),10,6,longitude);
 strcat(var2, longitude);
 //Added ss.flush();
 ss.flush();
 ss.end();
 Serial.flush()
 //Added client.beginC() for _client.begin(9600) is Ubidots_GPRS.cpp
 client.beginC();
 client.add(ID1, value_1, var, var2);
 client.sendAll();
 client.endC();
 ss.begin(9600);
 }
 Serial.println(var);
 Serial.println(var2);
}

From this link, I moved the println from inside .isUpdated() to outside the if statement. I was able to get GPS data sent from the unit to my Ubidots account while driving around town. Afterwards I was able to input the data into Google Maps and the route produced was accurate. Do I need flush()?

 #include <SoftwareSerial.h>
 #include <TinyGPS++.h>
 #include <Ubidots_Arduino_GPRS.h>
 //Serial Relay - Arduino will patch a 
 //serial link between the computer and the GPRS Shield
 //at 19200 bps 8-N-1
 //Computer is connected to Hardware UART
 //GPRS Shield is connected to the Software UART 
 #define APN "myapn" 
 #define USER "" // If your apn doesnt have username just put ""
 #define PASS "" // If your apn doesnt have password just put ""
 #define TOKEN "ubidotsToken" // Replace it with your Ubidots token
 #define ID "Your_id_here" // Replace it with your Ubidots' variable ID
 // You can send 1 to 10 variable at the same time
 #define ID1 "idHere" // Replace it with your variable ID
 //#define ID2 "" // Replace it with your variable ID
 //#define ID3 "Your_id_here" // Replace it with your variable ID
 
 TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
 //Declare indexes, and strings
 char latitude[12];
 char longitude[12];
 float value_1 = 1;
 char var[18] = "Lat: ";
 char var2[18] = "Long: ";
 Ubidots client(TOKEN); 
 SoftwareSerial ss(2,3);
 void setup() {
 
 // the Serial port of Arduino baud rate.
 Serial.begin(9600); 
 
 client.powerUpOrDown();
 client.setApn(APN,USER,PASS);
 //.endC is for _client.end() in Ubidots_GPRS.cpp
 client.endC();
 ss.begin(9600);
 }
 
 void loop() {
 
 //handling GPS data parsing
 while (ss.available() > 0) {
 gps.encode(ss.read());}
 //Once a valid location comes up it updates Lat/Long variables
 if (gps.location.isUpdated())
 {
 strcpy(var, "Lat: ");
 strcpy(var2,"Long: ");
 
 dtostrf(gps.location.lat(),10,6,latitude);
 strcat(var, latitude);
 
 dtostrf(gps.location.lng(),10,6,longitude);
 strcat(var2, longitude);
 //Added ss.flush();
 ss.flush();
 ss.end();
 Serial.flush()
 //Added client.beginC() for _client.begin(9600) is Ubidots_GPRS.cpp
 client.beginC();
 client.add(ID1, value_1, var, var2);
 client.sendAll();
 client.endC();
 ss.begin(9600);
 }
 Serial.println(var);
 Serial.println(var2);
 }

From this link, I moved the println from inside .isUpdated() to outside the if statement. I was able to get GPS data sent from the unit to my Ubidots account while driving around town. Afterwards I was able to input the data into Google Maps and the route produced was accurate. Do I need flush()?

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

From this link link, I moved the println from inside .isUpdated() to outside the if statement. I was able to get GPS data sent from the unit to my Ubidots account while driving around town. Afterwards I was able to input the data into Google Maps and the route produced was accurate. Do I need flush()?

From this link, I moved the println from inside .isUpdated() to outside the if statement. I was able to get GPS data sent from the unit to my Ubidots account while driving around town. Afterwards I was able to input the data into Google Maps and the route produced was accurate. Do I need flush()?

From this link, I moved the println from inside .isUpdated() to outside the if statement. I was able to get GPS data sent from the unit to my Ubidots account while driving around town. Afterwards I was able to input the data into Google Maps and the route produced was accurate. Do I need flush()?

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Added .beginC() and .endC() to code, along with flush(), think code is mostly working from moving println out of the .isUpdated() loop
Source Link
roe-el
  • 39
  • 1
  • 1
  • 5

I've got an Arduino Uno, SIM900 GPRS, and the Adafruit Breakout GPS. What I am trying to do is set up GPS tracker with a connection to Ubidots to take the data(lat,long) from the GPS and send it using the GPRS to my Ubidots account. I've been successful in sending the data, but a problem occurs when the

Can this code loops back. It is not updating the coordinates after the first iteration of the loop. It will continue to display the same coordinates and sending them with .add and .sendAll.be optimized?

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <Ubidots_Arduino_GPRS.h>
//Serial Relay - Arduino will patch a 
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART 
#define APN "myapn" 
#define USER "" // If your apn doesnt have username just put ""
#define PASS "" // If your apn doesnt have password just put ""
#define TOKEN "ubidotsToken" // Replace it with your Ubidots token
#define ID "Your_id_here" // Replace it with your Ubidots' variable ID
// You can send 1 to 10 variable at the same time
#define ID1 "idHere" // Replace it with your variable ID
//#define ID2 "" // Replace it with your variable ID
//#define ID3 "Your_id_here" // Replace it with your variable ID
TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
//Declare indexes, and strings
char latitude[12];
char longitude[12];
float value_1 = 1;
char var[18] = "Lat: ";
char var2[18] = "Long: ";
Ubidots client(TOKEN); 
SoftwareSerial ss(2,3);
void setup() {
 // the Serial port of Arduino baud rate.
 Serial.begin(9600); 
 
 client.powerUpOrDown();
 client.setApn(APN,USER,PASS);
//.endC is for _client.end() in Ubidots_GPRS.cpp
 client.endC();
 ss.begin(9600);
}
void loop() {
 
 //handling GPS data parsing
 while (ss.available() > 0) {
 gps.encode(ss.read());}
 //Once a valid location comes up it updates Lat/Long variables
 if (gps.location.isUpdated())
{
 strcpy(var, "Lat: ");
 strcpy(var2,"Long: ");
 
 dtostrf(gps.location.lat(),10,6,latitude);
 strcat(var, latitude);
 
 dtostrf(gps.location.lng(),10,6,longitude);
 strcat(var2, longitude);
 //Added Serialss.printlnflush("Latitude: );
 ss.flush();
 " + Stringss.end(latitude) + "\n");
 Serial.printlnflush("Longitude: )
 " +//Added Stringclient.beginC(longitude)+ "\n");
 for _client.begin(9600) is Ubidots_GPRS.cpp
 client.beginC();
 client.add(ID1, value_1, var, var2);
 client.sendAll();
 }
 
}

I think that the problem lies with this part of the code:

while (Serialclient.availableendC() > 0) {;
 gps.encode(Serialss.readbegin()9600);}

as it has to do with parsing the data. I've used the serial monitor to see if the data deleted with:

strcpy Serial.println(var, "Lat: ");
strcpy Serial.println(var2,"Long: ");
}

And it has shown that it clears var and var2From this link, but after dtostrf and strcat it outputsI moved the same coordinates asprintln from first loop iteration. This continues till I turn it offinside . I've also tried a delayisUpdated() at the end ofto outside the if statement but it causes the program to jump back to setup(). If I take out the loop() in the if statement the program freezes (onwas able to get GPS data sent from the serial monitor) after .sendAllunit to my Ubidots account while driving around town. The Rx and Tx are connected Afterwards I was able to Digital 1input the data into Google Maps and 0 after uploading the sketchroute produced was accurate. Any help is appreciated : Do I need flush()?

I've got an Arduino Uno, SIM900 GPRS, and the Adafruit Breakout GPS. What I am trying to do is set up GPS tracker with a connection to Ubidots to take the data(lat,long) from the GPS and send it using the GPRS to my Ubidots account. I've been successful in sending the data, but a problem occurs when the code loops back. It is not updating the coordinates after the first iteration of the loop. It will continue to display the same coordinates and sending them with .add and .sendAll.

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <Ubidots_Arduino_GPRS.h>
//Serial Relay - Arduino will patch a 
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART 
#define APN "myapn" 
#define USER "" // If your apn doesnt have username just put ""
#define PASS "" // If your apn doesnt have password just put ""
#define TOKEN "ubidotsToken" // Replace it with your Ubidots token
#define ID "Your_id_here" // Replace it with your Ubidots' variable ID
// You can send 1 to 10 variable at the same time
#define ID1 "idHere" // Replace it with your variable ID
//#define ID2 "" // Replace it with your variable ID
//#define ID3 "Your_id_here" // Replace it with your variable ID
TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
//Declare indexes, and strings
char latitude[12];
char longitude[12];
float value_1 = 1;
char var[18] = "Lat: ";
char var2[18] = "Long: ";
Ubidots client(TOKEN); 
 
void setup() {
 // the Serial port of Arduino baud rate.
 Serial.begin(9600); 
 
 client.powerUpOrDown();
 client.setApn(APN,USER,PASS);
 ss.begin(9600);
}
void loop() {
 
 //handling GPS data parsing
 while (ss.available() > 0) {
 gps.encode(ss.read());}
 //Once a valid location comes up it updates Lat/Long variables
 if (gps.location.isUpdated())
{
 strcpy(var, "Lat: ");
 strcpy(var2,"Long: ");
 
 dtostrf(gps.location.lat(),10,6,latitude);
 strcat(var, latitude);
 
 dtostrf(gps.location.lng(),10,6,longitude);
 strcat(var2, longitude);
 Serial.println("Latitude:  " + String(latitude) + "\n");
 Serial.println("Longitude:  " + String(longitude)+ "\n");
 
 
 client.add(ID1, value_1, var, var2);
 client.sendAll();
 }
 
}

I think that the problem lies with this part of the code:

while (Serial.available() > 0) {
 gps.encode(Serial.read());}

as it has to do with parsing the data. I've used the serial monitor to see if the data deleted with:

strcpy(var, "Lat: ");
strcpy(var2,"Long: ");

And it has shown that it clears var and var2, but after dtostrf and strcat it outputs the same coordinates as from first loop iteration. This continues till I turn it off. I've also tried a delay() at the end of the if statement but it causes the program to jump back to setup(). If I take out the loop() in the if statement the program freezes (on the serial monitor) after .sendAll. The Rx and Tx are connected to Digital 1 and 0 after uploading the sketch. Any help is appreciated :)

I've got an Arduino Uno, SIM900 GPRS, and the Adafruit Breakout GPS.

Can this code be optimized?

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <Ubidots_Arduino_GPRS.h>
//Serial Relay - Arduino will patch a 
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART 
#define APN "myapn" 
#define USER "" // If your apn doesnt have username just put ""
#define PASS "" // If your apn doesnt have password just put ""
#define TOKEN "ubidotsToken" // Replace it with your Ubidots token
#define ID "Your_id_here" // Replace it with your Ubidots' variable ID
// You can send 1 to 10 variable at the same time
#define ID1 "idHere" // Replace it with your variable ID
//#define ID2 "" // Replace it with your variable ID
//#define ID3 "Your_id_here" // Replace it with your variable ID
TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
//Declare indexes, and strings
char latitude[12];
char longitude[12];
float value_1 = 1;
char var[18] = "Lat: ";
char var2[18] = "Long: ";
Ubidots client(TOKEN); 
SoftwareSerial ss(2,3);
void setup() {
 // the Serial port of Arduino baud rate.
 Serial.begin(9600); 
 
 client.powerUpOrDown();
 client.setApn(APN,USER,PASS);
//.endC is for _client.end() in Ubidots_GPRS.cpp
 client.endC();
 ss.begin(9600);
}
void loop() {
 
 //handling GPS data parsing
 while (ss.available() > 0) {
 gps.encode(ss.read());}
 //Once a valid location comes up it updates Lat/Long variables
 if (gps.location.isUpdated())
{
 strcpy(var, "Lat: ");
 strcpy(var2,"Long: ");
 
 dtostrf(gps.location.lat(),10,6,latitude);
 strcat(var, latitude);
 
 dtostrf(gps.location.lng(),10,6,longitude);
 strcat(var2, longitude);
 //Added ss.flush();
 ss.flush();
 ss.end();
 Serial.flush()
 //Added client.beginC() for _client.begin(9600) is Ubidots_GPRS.cpp
 client.beginC();
 client.add(ID1, value_1, var, var2);
 client.sendAll();
 client.endC();
 ss.begin(9600);}
 Serial.println(var);
 Serial.println(var2);
}

From this link, I moved the println from inside .isUpdated() to outside the if statement. I was able to get GPS data sent from the unit to my Ubidots account while driving around town. Afterwards I was able to input the data into Google Maps and the route produced was accurate. Do I need flush()?

Added ss instance with functions for setup() and begin(), changed dtostrf(), and removed loop() in .isUpdated()
Source Link
roe-el
  • 39
  • 1
  • 1
  • 5
Loading
1
2

AltStyle によって変換されたページ (->オリジナル) /