Hi, I need some help with the code for my Weather Station. The problem is the SIM900A stops sending sms when there is no available GPS.
See image below, the first day is the SIM900A is still sending the data of other components even though there is no available GPS. When the GPS regained its signal, it will send also the GPS data.
But the 2nd day, the Project stops sending all the data. And I think the GPS is the problem.
Or do you guys have any Idea what's the cause of the problem? Need help! Thanks in advance!
Below is the code
void loop() {
while (gpsSerial.available() > 0) {
if (gps.encode(gpsSerial.read())) {
// GPS data is available and valid
// Process GPS data
}
}
static unsigned long lastSensorReadTime = 0;
static unsigned long lastAvgCalcTime = 0;
unsigned long currentTime = millis();
int volt = analogRead(A0);// read the input
double voltage = map(volt,0,1023, 0, 2500) + offset - 22;
voltage /=100;
if (currentTime - lastSensorReadTime >= sensorReadInterval) {
float temperature = bme.readTemperature();
float pressure = bme.readPressure() / 100.0F;
float humidity = bme.readHumidity();
temperatureSum += temperature;
pressureSum += pressure;
humiditySum += humidity;
sampleCount++;
lastSensorReadTime = currentTime;
}
float rainfall = calculateRainfall(); // Calculate rainfall since last check
if ((millis() - gulStart_Read_Timer) >= READ_TIME) {
cli();
WindSpeed = WIND_SPEED_20_PULSE_SECOND / ONE_ROTATION_SENSOR * (float)Rotations;
sei();
Rotations = 0;
gulStart_Read_Timer = millis();
avgWindSpeed += WindSpeed;
numReadings++;
if (WindSpeed > maxWindSpeed) {
maxWindSpeed = WindSpeed;
}
//SEND THE DATA
if (numReadings >= MAX_READINGS) {
float avgTemperature = temperatureSum / sampleCount;
float avgPressure = pressureSum / sampleCount;
float avgHumidity = humiditySum / sampleCount;
avgWindSpeed /= numReadings;
uint8_t result;
result = node.readHoldingRegisters(0x0017, 1);
unsigned int WindDirection = node.getResponseBuffer(0x00);
if (result == node.ku8MBSuccess && WindDirection < 16) {
Serial.print("Wind direction: ");
Serial.println(compassNames[WindDirection]);
}
String message1 = "WeatherStation ";
message1 += "(AvgSpd: " + String(avgWindSpeed) + "), ";
message1 += "(MxSpd: " + String(maxWindSpeed) + "), ";
message1 += "(Dir: " + String(compassNames[WindDirection]) + "), ";
message1 += "(AvgT2: " + String(avgTemperature) + "), ";
message1 += "(AvgHum: " + String(avgHumidity) + "), ";
message1 += "(AvgPres: " + String(avgPressure) + "), ";
message1 += "(TotalR: " + String(rainTotal) + "), ";
message1 += "(Volts: " + String(voltage) + "), ";
String message2 = "WSGPS ";
if (gps.location.isValid()) {
message2 += "(lat: " + String(gps.location.lat(), 6) + "), ";
message2 += "(long: " + String(gps.location.lng(), 6) + "), ";
message2 += "(alt: " + String(gps.altitude.meters()) + "), ";
} else {
message2 += "(No GPS data available)";
}
SIM900A.println("AT+CMGS=\"" + String(phone_number) + "\"");
delay(1000);
SIM900A.print(message1);
SIM900A.write((char)26);
rainTotal = 0;
delay(5000); // Add a delay before sending the second message
SIM900A.println("AT+CMGS=\"" + String(phone_number) + "\"");
delay(1000);
SIM900A.print(message2);
SIM900A.write((char)26);
Serial.println("SMS Sent2");
avgWindSpeed = 0.0;
maxWindSpeed = 0.0;
numReadings = 0;
temperatureSum = 0;
pressureSum = 0;
humiditySum = 0;
sampleCount = 0;
lastAvgCalcTime = currentTime;
}
}
}
Also, I want to send all the SMS data even though there is no available GPS, and when the GPS regained its signal, it will send also the GPS.
Or is it possible that the GPS will remain its Signal for long period of time without losing any Data?
The time interval of sending the all the data is 15minutes