Hello guys,
in resume im working with a project that reads analog inputs and after they reach some value the enter in this function readLocation() below:
void readLocation(){
if(isFirst) {
isFirst = 0;
return;
}
memset(message,0,sizeof(message));
bool newData = false;
unsigned long chars = 0;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (Serial1.available())
{
int c = Serial1.read();
// Serial.print((char)c); // if you uncomment this you will see the raw data from the GPS
++chars;
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
// we have a location fix so output the lat / long and time to acquire
if(secondsToFirstLocation == 0){
secondsToFirstLocation = (millis() - startMillis) / 1000;
Serial.print("Acquired in:");
Serial.print(secondsToFirstLocation);
Serial.println("s");
}
unsigned long age;
gps.f_get_position(&latitude, &longitude, &age);
latitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : latitude;
longitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : longitude;
dtostrf(latitude, 10, 6, lats);
strcat(message, lats);
strcat(message,"#");
dtostrf(longitude, 10, 6, lons);
strcat(message, lons);
strcat(message,"#");
dtostrf (res, 8, 6, forca);
strcat(message, forca);
strcat(message,"#");
strcat (message, "ASO-5577#BWM");
fona.sendSMS(sendto, message);
if (chars == 0){
// if you haven't got any chars then likely a wiring issue
Serial.println("Check wiring");
}
else if(secondsToFirstLocation == 0){
// still working
}
}
}
I need a help with 2 things:
- How do i create a loop inside this funcion till the sms was sent.
- How do i create a loop inside this sms loop, that will stay till latitude and longitude are not null.