Hello everyone,
I m using this code,
char aux_str[100];
char frame[200];
void setup() {
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
float Latitude,Longitude;
int yy,mo,dd,hh,mm,ss;
Latitude=90.5667;
Longitude=56.7764;
yy=2015;
mo=06;
dd=01;
hh=10;
mm=57;
ss=45;
sprintf(aux_str, "AT+HTTPPARA="URL","http://www.nanosoftremote.com/vts/API/startTrip.php?");
//Serial1.print(aux_str);
Serial.print(aux_str);
sprintf(frame, "B=6&R=1&SLAT=%f&SLNG=%f&T=%d/%d/%d %d:%d:%d",Latitude,Longitude,yy,mo,dd,hh,mm,ss);
//Serial1.print(frame);
Serial.println(frame);
delay(5000);
}
And getting output
AT+HTTPPARA="URL","http://www.nanosoftremote.com/vts/API/startTrip.php?&B=6&R=1&SLAT=?&SLNG=?&T=2015/6/1 10:57:45
Can anybody tell me why i am getting "?" in place of floating number
Thanks in advance
Hi, sprintf() does not support printing floats. I understand it was removed from the standard C library for Arduino because it made compiled sketches very large.
Also please always use code tags when you post your code, so it looks like this
Paul
You can use "dtostrf" instead, or reinstate float support for sprintf.
The former is easier.
This will use less RAM and generate less code as well.
It can be made to run on an ATtiny85 if the ledPin and timing numbers are changed.
-- my Arduino 1.6.1 compiler set for UNO board says:
Sketch uses 4,696 bytes (14%) of program storage space. Maximum is 32,256 bytes.
Global variables use 221 bytes (10%) of dynamic memory, leaving 1,827 bytes for local variables. Maximum is 2,048 bytes.
It will send the message every 5 seconds while blinking a status led and echoing user input just to show how not to block multiple tasks with a delay in one. When no task blocks execution, AVR is capable of running many tasks smoothly using a small part of the total capability. It can be slowed down to use less power and lower voltage and still do more than most beginners can believe.
void setup() {
Serial.begin(115200); // serial chars will transmit faster, the output buffer is only 64 chars
}
void loop() {
// put your main code here, to run repeatedly:
static float Latitude,Longitude;
static int yy,mo,dd,hh,mm,ss;
static byte ledPin = 13;
static byte ledState;
static unsigned long lastTime;
static unsigned long blinkTime;
Latitude=90.5667;
Longitude=56.7764;
yy=2015;
mo=06;
dd=01;
hh=10;
mm=57;
ss=45;
if ( millis() - lastTime >= 5000UL ) { // runs once every 5 seonds
lastTime += 5000UL;
Serial.print( F("AT+HTTPPARA=\"URL\",\"http://www.nanosoftremote.com/vts/API/startTrip.php?"));
Serial.print( F("B=6&R=1&SLAT="));
Serial.print( Latitude );
Serial.print( F("&SLNG="));
Serial.print( Longitude );
Serial.print( F("&T=" ));
Serial.print( yy );
Serial.print( F("/" ));
Serial.print( mo );
Serial.print( F("/" ));
Serial.print( dd );
Serial.print( F(" "));
Serial.print( hh );
Serial.print( F(":"));
Serial.print( mm );
Serial.print( F(":"));
Serial.print( ss );
}
if ( Serial.available()) {
Serial.print( Serial.read());
}
if ( millis() - blinkTime >= 1000UL ) { // 1 second status blink
lastTime += 1000UL;
ledState = !ledState; // reverses ledState between true and false, ! is logical NOT
digitalWrite( ledPin, ledState );
}
}