Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
App is lagging and tends to Crash

I have the issue that the Buttons and other widgets on my App are lagging. 
Meaning when I press a Button, say V[12] it takes several seconds to get the response.
Also when using switches, the Switchstate seems to bounce. Reverting back to unpressed mode after I pressed it.

Any idea why this could happen? I assume its because of the virtuinoRun() function always requesting every pin value of the App, no matter where the Arduino Code currently
is runninng. Because of that I also wanted to aks if there is a method to only read and write the value of selective pins in the App, instead of every pin initialized?

Thank you very much for your time!

so I still have not found an answer to the issue. I tried changing the buffer Size to 512 which also didnt help...
I am using the default example code for the Bluetooth Mega connection via a HC05 Module.
I have set the request time of my bluetooth Module to 0.5s and got a baudrate of 9600. 

Would be really greatful for any tipps or help regarding that issue!
there is no reason to set the request time to 0.5 seconds.
You can change it to 2-3 seconds.
This happens because the loop code needs some time to make a circle.
Remove any delay from the loop code. Use the Virtuino delay function instead of the default.
Τhis is a possible cause.

Could you post the Arduino code here?

Thanks for the reply!!!

so yes at the bottom there is the whole code. Well I am using for my actual project a few stepper motors and stuff where it needs to be quite accurate, time wise. 
But the updating of the string does not work properly such as the buttons already as shown in the code below. 

As already said the buttons tend to bounce and the text sometimes updates "YesYes" to "YesYesYes" in the text value display. It also never updates to "No". 
I set the Buttons to switch mode and only turn on if the value is 1 and off if it is 0 or any other value. 

I assumed that it could be because of an issue with the Buffer, meaning that it is maybe Flooded with requests and replies, so it reads it continously over several requests and repiles 
Instead of checking the request for a Value, then printing it, and then again check for new values. 

Also as you said it could be because the loop is too long. Is there a method to reqeust and write pin values singularly? I have seen that the method to write and read commands from the buffer itself is stated here but should I just Print the commands to the Serial connection with the bluetooth module? Would be very helpful because this way i would be able to make my code work way quicker! 

Thank you very much for your time, here is the code now: 

/* Example: Bluetooth HC-05 + Arduino MEGA - getting started
* Created by Ilias Lamprou
* Modified: Sep/9/2019
//-------------VirtuinoCM Library and settings --------------
#include "VirtuinoCM.h"
VirtuinoCM virtuino;
#define V_memory_count 32 // the size of V memory. You can change it to a number <=255)
float V[V_memory_count]; // This array is synchronized with Virtuino V memory. You can change the type to int, long etc.
boolean debug = false; // set this variable to false on the finale code to decrease the request time.
String V36 = "Hello";
//============================================================== setup
void setup() {
if (debug) {
while (!Serial) continue;
V[1] = 0;
V[2] =0;

virtuino.begin(onReceived,onRequested,512); //Start Virtuino. Set the buffer to 256. With this buffer Virtuino can control about 28 pins (1 command = 9bytes) The T(text) commands with 20 characters need 20+6 bytes
//virtuino.key="1234"; //This is the Virtuino password. Only requests the start with this key are accepted from the library

pinMode(4, OUTPUT); // On Virtuino panel add a button to control this pin
pinMode(13, OUTPUT); // On Virtuino panel add a button to control this pin
pinMode(6, INPUT); // On Virtuino panel add a led to get the state of this pin
pinMode(7, INPUT); // On Virtuino panel add a led to get the state of this pin
//============================================================== loop
void loop() {

if (V[1]==1){
V36 = "NoNo";
Serial.println("V1 pressed");
if (V[2]==1){
V36 = "YesYes";
Serial.println("V2 pressed");

//============================================================== onCommandReceived
/* This function is called every time Virtuino app sends a request to server to change a Pin value
* The 'variableType' can be a character like V, T, O V=Virtual pin T=Text Pin O=PWM Pin
* The 'variableIndex' is the pin number index of Virtuino app
* The 'valueAsText' is the value that has sent from the app */
void onReceived(char variableType, uint8_t variableIndex, String valueAsText){
if (variableType=='V'){
if (variableIndex<V_memory_count) {
float value = valueAsText.toFloat(); // convert the value to float. The valueAsText have to be numerical
V[variableIndex]=value; // copy the received value to arduino V memory array
if (variableIndex== 36 ) V36= valueAsText;

/* This function is called every time Virtuino app requests to read a pin value*/
String onRequested(char variableType, uint8_t variableIndex){
if (variableType=='V') {
if (variableIndex<V_memory_count) return String(V[variableIndex]); // return the value of the arduino V memory array
if (variableIndex==36) return V36;

return "";
//============================================================== virtuinoRun
void virtuinoRun(){
while (Serial1.available()) {
if (tempChar==CM_START_CHAR) { // a new command is starting...
virtuino.readBuffer=CM_START_CHAR; // copy the new command to the virtuino readBuffer
if (debug) Serial.println("\nCommand= "+virtuino.readBuffer);
String* response= virtuino.getResponse(); // get the text that has to be sent to Virtuino as reply. The library will check the inptuBuffer and it will create the response text
if (debug) Serial.println("Response : "+*response);

//============================================================== vDelay
void vDelay(int delayInMillis){long t=millis()+delayInMillis;while (millis()<t) virtuinoRun();}
I can't find any issue in the code.
I think it is a communication issue.
Could you check and post some screenshots of the arduino serial monitor?
there is an unavoidable latency.
The client queries the server.
The server responds.
I use ethernet network via wifi, but I have this latency.
The more we remove unnecessary Serial.print, and delay() the faster it is
Hey, sorry for the late reply 
So basically I have tried some stuff now and changing the value in the app takes several seconds sometimes, around 10 seconds
In the serial monitor it shows that the Value changes as it should, also the Command which is sent to the Virtuino App.
I am not really sure how it is processed afterwards but I assume its some issue within the Apps processing.

I added a screenshot of the serial monitor

Attached Files Thumbnail(s)

Forum Jump:

Users browsing this thread: 1 Guest(s)