Hello,
I'm writing a program to take the Latitude and longitude values, convert to the understandable format into float and then publish the same to MQTT.
I've been able to take the values only upto 2 digits from the forum help but could not convert it to 4 decimal value. I want the 4 digit decimal float so as to get the meaningful data.
Also, after getting the float value, I cannot publish the latitude and Longitude into a single string.
Please find the code for GPS float vale as below:
void senddataonmqtt()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
// save the last time a message was sent
previousMillis = currentMillis;
//record random value from A0, A1 and A2
int Rvalue = degreesX + degreesY;
Serial.print("Sending message to topic: ");
Serial.println(topic);
Serial.println(Rvalue);
Serial.println(topic1);
Serial.println(LATval);
Serial.println(topic2);
Serial.println(LNGval);
// send message, the Print interface can be used to set the message contents
mqttClient.beginMessage(topic);
mqttClient.print(Rvalue);
mqttClient.beginMessage(topic1);
mqttClient.print(LATval);
mqttClient.beginMessage(topic2);
mqttClient.print(LNGval);
mqttClient.endMessage();
Serial.println();
}
}
I want the data to be published on MQTT as:
XYZ: 123 , latitude: 82.36 , Longitude: 77.23
what error did you get? is LATval a String or a float?
4 decimal digit is NOT a precise GPS position... you need all you can get
for example this is where the Eiffel Tower is in Paris:
➜ 48.85848301905653, 2.2945027564091065
if the format is always the same then you get the full resolution in lattt and lonnn (stupid variable names - you could use latValue and lonValue for example and for the other latString and lonString)
why don't you just print the float values and not create an extra String? then you can use 4 or 6 to get the number of decimals you need
you begin your message on a topic and then print whet you want to publish
// send message, the Print interface can be used to set the message contents
mqttClient.beginMessage(topic);
mqttClient.print(xxx);
mqttClient.print(xxx);
mqttClient.print(xxx);
mqttClient.print(xxx);
mqttClient.print(xxx);
mqttClient.endMessage();
so if you want to see Latitude: 18.474730 Longitude: 73.796349