Pessoal, vocês podem me ajudar ? 
estou fazendo um código aqui para que ele me envie um link do google mapas  com a localização do veículo.Os passos iniciais funcionam, armazena no micro SD como eu quero mas não envia via sms com o link.Peguei o código e fui modificando , incluindo algumas coisas para me ajudar. 

O código é esse : 

#include <SPI.h>
#include <SD.h>
#include <TinyGPS++.h>

#define ARDUINO_USD_CS 8 // uSD card CS pin (pin 8 on Duinopeak GPS Logger Shield)

String avalia = "";
int conta = 0;

/////////////////////////
// Log File Defintions //
/////////////////////////
// Keep in mind, the SD library has max file name lengths of 8.3 - 8 char prefix,
// and a 3 char suffix.
// Our log files are called "gpslogXX.csv, so "gpslog99.csv" is our max file.
#define LOG_FILE_PREFIX "gpslog" // Name of the log file.
#define MAX_LOG_FILES 100 // Number of log files that can be made
#define LOG_FILE_SUFFIX "csv" // Suffix of the log file
char logFileName[13]; // Char string to store the log file name
// Data to be logged:
#define LOG_COLUMN_COUNT 8
char * log_col_names[LOG_COLUMN_COUNT] = {
"longitude", "latitude", "altitude", "speed", "course", "date", "time", "satellites"
}; // log_col_names is printed at the top of the file.

//////////////////////
// Log Rate Control //
//////////////////////
#define LOG_RATE 5000 // Log every 5 seconds
unsigned long lastLog = 0; // Global var to keep of last time we logged

/////////////////////////
// TinyGPS Definitions //
/////////////////////////
TinyGPSPlus tinyGPS; // tinyGPSPlus object to be used throughout
#define GPS_BAUD 9600 // GPS module's default baud rate

////////////////////////////////////////////////
// Arduino GPS Shield Serial Port Definitions //
////////////////////////////////////////////////
// If you're using an Arduino Uno, Mega, RedBoard, or any board that uses the
// 0/1 UART for programming/Serial monitor-ing, use SoftwareSerial:
#include <SoftwareSerial.h>
#define ARDUINO_GPS_RX 3 // GPS TX, Arduino RX pin
#define ARDUINO_GPS_TX 2 // GPS RX, Arduino TX pin
SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX); // Create a SoftwareSerial
SoftwareSerial SIM900(10, 11);

// Set gpsPort to either ssGPS if using SoftwareSerial or Serial1 if using an
// Arduino with a dedicated hardware serial port
#define gpsPort ssGPS // Alternatively, use Serial1 on the Leonardo

// Define the serial monitor port. On the Uno, Mega, and Leonardo this is 'Serial'
// on other boards this may be 'SerialUSB'
#define SerialMonitor Serial

void setup()
{
SIM900.begin(9600);
SerialMonitor.begin(9600);
gpsPort.begin(GPS_BAUD);

SerialMonitor.println("Setting up SD card.");
// see if the card is present and can be initialized:
if (!SD.begin(ARDUINO_USD_CS))
{
SerialMonitor.println("Error initializing SD card.");
}
updateFileName(); // Each time we start, create a new file, increment the number
printHeader(); // Print a header at the top of the new file
}

void loop()
{
if ((lastLog + LOG_RATE) <= millis())
{ // If it's been LOG_RATE milliseconds since the last log:
if (tinyGPS.location.isUpdated()) // If the GPS data is vaild
{
if (logGPSData()) // Log the GPS data
{
SerialMonitor.println("GPS logged."); // Print a debug message
lastLog = millis(); // Update the lastLog variable
}
else // If we failed to log GPS
{ // Print an error, don't update lastLog
SerialMonitor.println("Failed to log new GPS data.");
}
}
else // If GPS data isn't valid
{
// Print a debug message. Maybe we don't have enough satellites yet.
SerialMonitor.print("No GPS data. Sats: ");
SerialMonitor.println(tinyGPS.satellites.value());
}
}

// If we're not logging, continue to "feed" the tinyGPS object:
while (gpsPort.available())
tinyGPS.encode(gpsPort.read());
}

byte logGPSData()
{
File logFile = SD.open(logFileName, FILE_WRITE); // Open the log file

if (logFile)
{ // Print longitude, latitude, altitude (in feet), speed (in mph), course
// in (degrees), date, time, and number of satellites.
logFile.print(tinyGPS.location.lng(), 6);
logFile.print(',');
logFile.print(tinyGPS.location.lat(), 6);
logFile.print(',');
logFile.print(tinyGPS.altitude.feet(), 1);
logFile.print(',');
logFile.print(tinyGPS.speed.mph(), 1);
logFile.print(',');
logFile.print(tinyGPS.course.deg(), 1);
logFile.print(',');
logFile.print(tinyGPS.date.value());
logFile.print(',');
logFile.print(tinyGPS.time.value());
logFile.print(',');
logFile.print(tinyGPS.satellites.value());
logFile.println();
logFile.close();

GSMsms();

return 1; // Return success
}

return 0; // If we failed to open the file, return fail
}

// printHeader() - prints our eight column names to the top of our log file
void printHeader()
{
File logFile = SD.open(logFileName, FILE_WRITE); // Open the log file

if (logFile) // If the log file opened, print our column names to the file
{
int i = 0;
for (; i < LOG_COLUMN_COUNT; i++)
{
logFile.print(log_col_names[i]);
if (i < LOG_COLUMN_COUNT - 1) // If it's anything but the last column
logFile.print(','); // print a comma
else // If it's the last column
logFile.println(); // print a new line
}
logFile.close(); // close the file
}
}

// updateFileName() - Looks through the log files already present on a card,
// and creates a new file with an incremented file index.
void updateFileName()
{
int i = 0;
for (; i < MAX_LOG_FILES; i++)
{
memset(logFileName, 0, strlen(logFileName)); // Clear logFileName string
// Set logFileName to "gpslogXX.csv":
sprintf(logFileName, "%s%d.%s", LOG_FILE_PREFIX, i, LOG_FILE_SUFFIX);
if (!SD.exists(logFileName)) // If a file doesn't exist
{
break; // Break out of this loop. We found our index
}
else // Otherwise:
{
SerialMonitor.print(logFileName);
SerialMonitor.println(" exists"); // Print a debug statement
}
}
SerialMonitor.print("File name: ");
SerialMonitor.println(logFileName); // Debug print the file name
}

void sendsms()
{
delay(400);
Serial.println("AT + CMGS = \"+55xxxxxxxxxxxx\"");
delay(300);

Serial.print("http://maps.google.com/maps?q=loc:");
//SIM900.print("Latitude = ");
Serial.print(tinyGPS.location.lat(), 6);
//SIM900.print(" Longitude = ");

Serial.print(",");
Serial.print(tinyGPS.location.lng(), 6);
delay(200);
Serial.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(200);
Serial.println();

if (millis() > 5000 && tinyGPS.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}

void comando(String comand)
{
conta++;
avalia = "";
SIM900.print(comand);
while(SIM900.available()<=0) Serial.print("preso passo "), Serial.println(conta), delay(200);

while(SIM900.available()>0)
{
char letra = SIM900.read();
if (isAlphaNumeric(letra)) avalia += letra;
}

if (avalia=="OK") Serial.print("passo"), Serial.println(conta);
else Serial.print("avalia: "), Serial.println(avalia);
delay(200);
}

void GSMsms()
{

comando("AT+CMGF=1\r\n");
comando("ATE0\r\n");
comando("AT+CNMI=1,2,0,0,0\r\n");

/*
SIM900.print("AT+CMGF=1\r");
SIM900.print("ATE0\r");
SIM900.print("AT+CNMI=1,2,0,0,0\r");
*/
delay(400);


SIM900.print("AT+CMGS=\r\n");
SIM900.write(0x22);//aspa dupla
SIM900.print("+55xxxxxxxxx");
SIM900.write(0x22);//aspa dupla
SIM900.println();
delay(400);

SIM900.print("http://maps.google.com/maps?q=loc:");
SIM900.print(tinyGPS.location.lat(), 6);
SIM900.print(",");
SIM900.print(tinyGPS.location.lng(), 6);
SIM900.write(0x1A);
SIM900.write(0x0D);
SIM900.write(0x0A);
Serial.println("Enviando mensagem...");
delay(1000);
}

 

HARDWARE USADO :

SIM 900A

ARDUINO UNO

ARDUINO SHIELD

Exibições: 554

Responder esta

Respostas a este tópico

Nossa, realmente horrível ler programas no corpo da postagem...

Essa sintaxe do "loc:" vc viu em algum lugar ? Desconheço que exista.

A string padrão pode ser, por ex:

https://www.google.com/maps/@-23.5468226,-46.7029821,15z

Coloque em vez de:

SIM900.print("http://maps.google.com/maps?q=loc:");

Isso:

SIM900.print("http://maps.google.com/maps/@");

Digo "pode ser" pq existem outras sintaxes válidas.

As coordenadas estão ok.

O que não está saindo como eu quero é o envio das msg de texto com as mesmas.

Lançando alguns comandos AT no terminal envio msg de texto, recebo ,mas na hora que o principal vai rodar não vem.As coordenadas são lanças no terminal corretamente mas a msg de texto não me é enviada.

Qual a mensagem que vem e qual a esperada ???

Nesse código a mensagem de erro é , preso passo 1 

Eu quero que ela me envie a mensagem com a localização via link.

Vou ser mais claro mostrando um vídeo parecido com o que quero fazer.

https://www.youtube.com/watch?v=PLdhroH0y_I

Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh, do jeito que vc tinha escrito entendi que a string estava errada, não que sequer ele conectava ao sim900.

No texto: "não envia via sms com o link" minha interpretação foi que não enviava a string com o link mas qualquer outra enviava. Já a realidade é que ele para na inicialização.

Esse erro vem da linha:

while(SIM900.available()<=0) Serial.print("preso passo "), Serial.println(conta), delay(200);

que tem essa virgula logo depois do ")".

Impossível te ajudar se vc não seguir a dica do José Gustavo Abreu Murta

Possivelmente essa virgula é erro de ControC ControlV para o corpo da mensagem.

Seu problema está mais embaixo, o sim900 sequer inicializa. Vc precisa testar com programas mais simples, mandar um "olá muldo" antes pelo sim900 como sms pra depois evoluir pra esse código. Pode ser absolutamente qualquer coisa, chip, configuração, alimentação, ligação, etc.

Bom dia ,

Sugestões de como "postar" no LdG por Rui Viana

Anexe no tópico, o arquivo do seu Sketch. 

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço