Help with sending float and string values over bridge

Hello Blynkers!

I need some help regarding sending values through a bridge that are not of integer type. i say this because on the receiving unit, the code for receiving the value is always

int p = param.asInt();

im wondering if there are commands such as

float p = param.asFloat(); [or similar]
OR
String p = param.asString(); [or similar]

it is imperetive for my project that i be able to send float values over the bridge. the string values do not matter as much to me, just a mild curiosity.

Appears to be available although never tried it.

int asInt()
long asLong()
 double asDouble() 
 float asFloat()
1 Like

I think asString() should also work.

Pete.

2 Likes

Ah yes missed that one.

asStr() or asString()

1 Like

Thanks for the previous replies guys. I have yet to test it but will update once i do.

I have 1 more question though.

Can i have multiple bridges between my two devices inside same project?
For example:

WidgetBridge rxSpeed(V100); // with speed device
WidgetBridge rxRTC(V102);
WidgetBridge rxParking(V103);

// connect to device with its auth token
BLYNK_CONNECTED() {
  rxSpeed.setAuthToken("");
  rxRTC.setAuthToken("");
  rxParking.setAuthToken("");
}

of course i would use use 3 handlers to receive data, if it is possible.

Yes… but that is only necessary if connecting to different receiving devices, as each Bridge needs the AUTH of the receiving device.

Otherwise declaring one Bridge is all you need to send multiple commands to multiple pins on a single receiving device.

BTW, all vPins are sent as strings anyhow, so declare your sending data as Float as normal, and use the param.asFloat() in the receiving function.

1 Like

I try to avoid sending floats between different systems since the decimal separator may not be the same on all systems.

If I am having to deal with real values, say to 3 decimal places, I multiply by 1000 and treat it as an integer. Ints get stored and transferred accurately.

2 Likes

That is a good point… Blynk seems to round up to three decimal points when using something like this… (GPS streaming from test phone to NodeJS sketch on RPi and sent to C++ sketch on ESP8266 via Blynk Bridge)…

BLYNK_WRITE(V21){
  Blynk.virtualWrite(V21, param.asFloat());
}

image

But will display the full value with this…

BLYNK_WRITE(V21){
  Blynk.virtualWrite(V21, param.asStr());
}

image

It is unclear if the rounding happens because of the param.asFloat() or because of the Display Widget (as I see it briefly flicker what appears to be the full value each time before settling to 3 decimal places)

So unless you are needing the accurate float value for some calculation, then using strings to display will work just fine.

2 Likes

Thank you guys so much for your replied! Turns out i had a slight confusion regarding the bridge, which made me think i need a bridge for every value i want to send, when in fact a single bridge with multiple virtualWrite statements and handlers on the receiving side do the exact same job!
Also gunner thank you so much for your reply. it is interesting to note the behaviour of floats when bridged, and for the purpose of my project i will use strings instead!

This project im doing wouldnt have been possible without you guys :’)

2 Likes