kamalesh 0 Posted January 3, 2018 Share Posted January 3, 2018 hi, I am using a MSP430FR4133 launchpad, i am trying to get a float value and send it via sim800. for that i hve to convert the float value to char* or char array. I have tried many conversions but i am not able to get the conversion properly. Even if i get it properly while printing it on the serial. The data is not transmitted in the right format through sim800. for example if i use dtostrf( buff , "%f" , flaotVal); function in serial monitor only "%f" is getting printed. and if i try other type of convertions , while transmitting through sim800 the right side part of the float value gets added to the decimal values . have tried ( itoa(), sprintf(), etc..) for example .. float value = 1.25. and if i tried converting and printing it on serial monitor i am getting it corrrectly as "1.25" . But when i am trying to transmit through sim800 the converted float value is sent as "0.125" instead 1.25 . Can anyone help me with this?. Quote Link to post Share on other sites
energia 485 Posted January 3, 2018 Share Posted January 3, 2018 Can you please post a minimal Sketch that shows the issue? Quote Link to post Share on other sites
kamalesh 0 Posted January 4, 2018 Author Share Posted January 4, 2018 The Minimal code Which i Use for the task. void loop() { duration = pulseIn(pin1, HIGH); { //conditions and statement for calculating sensor value. } String src = Sim800l.readSms(1); // if(Serial.available()) // { // String src = Serial.readString(); if(src.indexOf("Flow") != -1) { String buf = String(sensor_val); for(int i = 0; i < buf.length()+1;i++) { text = buf; } Sim800l.sendSms(number,text); delay(1000); Sim800l.delAllSms(); //Serial.print("Flow:"); //Serial.println(text); // src = "\0"; // } } } Quote Link to post Share on other sites
energia 485 Posted January 4, 2018 Share Posted January 4, 2018 I do not see any float to string conversions in this snip of code. Did you paste the right / entire Sketch? Quote Link to post Share on other sites
kamalesh 0 Posted January 5, 2018 Author Share Posted January 5, 2018 conversions i had tried .. The above code i had sent only contains a type cast version just before the For statement. 1. type cast - String buf = String (FloatVal); 2 .snprintf(buffer, sizeof buffer, "%f", myFloat); //// in this type of float to string conversion if i use %f simply the "%f" is getting printed or transmitted. if i use %d the conversion is not proper. 3 . dtostrf(FloatVal, 4, 3, Buff); Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.