How to offload CPU intensive tasks to local Blynk server

Hi, Iam new to blynk. Can someone guide me. I have a local blynk sever running on Pi2. I have sensor connected to nodemcu. I need to make a complex mathematical calculation based on sensor data which cannot be done on nodemcu. Can i forward sensor data to server and run a custom method on sever and get back result to nodemcu. Thanks

Probably not ! The java server running on your PI2 is only responsible for connecting your smartphone to the Nodemcu. It does not make any calculations. Its basically a bridge.
I think nodemcu is capable of doing complex calculation. Or use ESP32 for more speed/multi tasking.
If you show us your code someone can help you here. We really have some BIG BRAINS here…

Thanks for your reply Mudhukesh. Below is part of js function which i need to run. It basically calculates sound speed based on temp and humidity. The formula have several squaring , exponential powering on many point decimal numbers. I need to run it least once every 2 min. Iam not sure nodemcu can handle this or not. Even it handles it may increase its battery usage and effect life. Is there a way for me to offload this work to Pi which can easily handle this job. Thanks.


ENH = 3.141593Math.pow(10,-8)P + 1.00062 + sqr(T)5.6Math.pow(10,-7);
PSV1 = sqr(T_kel)1.2378847Math.pow(10,-5)-1.9121316
Math.pow(10,-2)T_kel;
PSV2 = 33.93711047-6.3431645
Math.pow(10,3)/T_kel;
PSV = Math.pow(e,PSV1)Math.pow(e,PSV2);
H = Rh
ENH
PSV/P;
Xw = H/100.0;
Xc = 400.0Math.pow(10,-6);
C1 = 0.603055
T + 331.5024 - sqr(T)5.28Math.pow(10,-4) + (0.1495874T + 51.471935 -sqr(T)7.82Math.pow(10,-4))Xw;
C2 = (-1.82
Math.pow(10,-7)+3.73
Math.pow(10,-8)*T-sqr(T)2.93Math.pow(10,-10))P+(-85.20931-0.228525T+sqr(T)5.91Math.pow(10,-5))*Xc;
C3 = sqr(Xw)2.835149 - sqr§2.15Math.pow(10,-13) + sqr(Xc)29.179762 + 4.86Math.pow(10,-4)XwPXc;
C = C1 + C2 - C3;


I’d say that the simplest way is to use your battery powered device to read the environmental values and upload them to the Blynk server, then use another device to fetch these values from the server and do the necessary calculations; and upload the results back to the Blynk server.

This cuts-out the need to start hacking around with the Blynk server code and makes your system more robust in terms of potential future changes to server code.

There are also devices (like the Teensy boards for example) that are better suited to floating point maths than the ESP boards.

Pete.

1 Like

Besides @PeteKnight solutions, you can explore these options:

  1. Use the faster ESP32 with dual core
  2. Use Teensy 4.0 and Blynk Bridge to communicate to NodeMCU, and send/retrieve data to be calculated to/from Teensy 4.0.
  3. Use Apache Webserver with calculating js in RPi local server in separate port (e.g 80, etc) different from the one handling Blynk (8080, 9443) to receive / calculate / send data to be calculated.
  4. Use Tennsy 4.0 alone to do everything
  5. Use the same RPi local server, and another Blynk program running on that RPi to act as a Blynk Bridge. Then do the same as in 2.
1 Like