A substitute for bridge (for lazy people)

how did you try?
i do it like this:

  1. float to String
String myConvertedString(myFloat, 2);  // convert float to String, with specified number of decimals

proof of concept:

void setup()
{
  Serial.begin(115200);
  Serial.println("ready");

  float myFloat = 36.1415;
  Serial.println(myFloat, 4);

  String myConvertedString(myFloat, 2);  // convert float to String, with specified number of decimals
  Serial.println(myConvertedString);

  // it compiles, because myConvertedString is a String (if you replace it with myFloat, will throw compilation error)
  String myString = myConvertedString;
  Serial.println(myString);
}

void loop()
{}
  1. String to float:
float myFloat = myString.toFloat();

proof of concept:

void setup()
{
  Serial.begin(115200);
  Serial.println("ready");

  String myString = "3.1415";
  Serial.println(myString);

  float myFloat = myString.toFloat();
  Serial.println(myFloat, 4);

  Serial.println(myFloat + 1, 4);
}

void loop()
{}

but honestly, i think this is not blynk related question… and all info is disponible in the official arduino reference.

thanks!

and well its partially blynk related if one is to use those api functions… but anyway, thanks for the reply, im going to mull over this together with the other stuff I have still to get my head wrapped around.

it appears there’s something wrong with your code. I’ve copy pasted the two routines into my code and used this in the setup:

 String pin(V16);
  String value(42.42);
  APIwriteDevicePin(str_auth_CENTRAL, pin,value);

  String endResult;
  endResult = APIreadDevicePin(str_auth_CENTRAL, pin);
  Serial.println(endResult);
  Serial.println(pin);
  Serial.println("////////////ENDING TEST");

what I got was:

////////////STARTING TEST
ong pin forma
16
////////////ENDING TEST

Given that you remove the parts of the output, I assume it says: ‘Wrong pin format’.
any clue whats going on?

edit: ah think ive got it. Blynk defines V16 as 16 so V16 is replaced by 16 and then converted to string. Need to do pin = “V16”.

with my code or yours?

what is the reason you are doing this?
it rather should be:

String pin = "V16";
String value = "42.42";

String myConvertedString(myFloat, 2);
should be used only if you pass an existing variable to the String constructor!

probably. you can verify for sure in the lib…

to get rid of the unneeded character removals, you can try something like this (untested):

if (payload.charAt(0) == "[" && payload.charAt(payload.length()) == "]") {
  payload.remove(0, 2);
  payload.remove(payload.length() - 2);      // strip [""]
}

As you might have concluded from my edit, that issue is resolved. Nice one on the character removals. Ill check it out.

But… another question. i’ve decided to go with this as it makes it a LOT easier to implement the code for my current situation.

One thing though. The blynk_write() funtions are ‘event handlers’ e.g.
blynk_write(V10){doThis()}
basically does: IF V10 is updated THEN run doThis().

I’ve currently build my code such that activities are only started when something changes. In short: I use blynk_write. How do you do this?

sorry, but i don’t understand this question.
please elaborate.

ok let me skip the how I do it now and go straight to the how can I do it from now on:

Setup (3 ESP’s)
Thermometer <—> Central unit <–> Relay
Central also communicates with the app.

The relay will send every e.g. 12 hours a maintenance bool ON or OFF to central over virtual pin V10. Now I can put central in a loop constantly checking whether the state of V10 has changed and as soon as that has happened: send the value onwards to the thermostat (which then displays: “maintenance running”).
But is there a smarter way to ‘only act when the value has changed or value change is send’ ?

does that make more sense?

(pls note that this is a oversimplified example. reality is more complex and a LOT more variables are shot around)

this is for what BLYNK_WRITE is used for…

yeah I know, I was actually looking for an alternative, but its rather off topic so ill post it in a separate topic. Thnx anyway!

And I’m again a couple of miles further down the road, only to find another wall…

I’ve rewritten most of my code to work on a local server and after quite some debugging I stumbled on a communication issue. That is: something is send but nothing is received. Now initially I thought that this line:

String url = "http://blynk-cloud.com/";

was the issue as I’m not running the setup on the blynk-cloud. So I changed it to:

String url = "http://192.168.1.93/";

which is the IP of the server that is running. But nothing is happening. Any clue what I’m doing wrong?

And what about the port? The cloud uses default 80, but your local server probably not.

I suppose you mean:

  String url = "http://192.168.1.93:9443/";  

tried that as well: no cigar.

Yes, more or less, but I’m guessing you have different port than 9443. In my case it is 8080 and it works :wink:

1 Like

@wolph42 Port 9443 is for the App link to the server, I believe HTTP commands act as if from the device, which is port 8080 for Local Server (and eventually Cloud as I understand).

1 Like

Correct! HTTP API is on the same port as device-to-server channel. I don’t know if setting in .properties file other port than 8080 will work, but I don’t feel the need to try.

yes, I got that from another topic where I got a http error which I couldn’t make sense of. That fix I’ve applied here as well. I’ve also checked 3 times whether Im really sending the info to the right token: I am. But nothing is received.

(later) Ok I’m at a loss: I thought to check the app to see if the value is updated there and noticed that I could not log in to the server. Checking my router and I noticed that my server is NOT in the list. Then I checked the serial.print of my central specifically: isHardwareConnected and that one returns TRUE. How on earth is that possible??? There is no server to connect to and thus no server to check if the device is online, but my central esp magically knows that its on???

Point now is that I don’t know what to trust and how to test whether the API is actually working…

edit: rebooted server, everything working ‘normally’ again. I noticed that I did not change the port for the value update, after changing that to 8080 it worked!

note that im still curious how on earth the device could be detected with the server being offline!