Table Widget error: addRow add to two entires or crash the controller

Hello Community!

Since the Eventor Widget never came for iOS I’m trying to implement some UI for Add and Delete events in a 2D array. I’m using a Time Widget for entering the time and DoW, a Switch to choose the desired action, plus a Button to “Save” the event which will be stored on a Table Widget.

For now it will only Add a weekly event at a particular time and day of the week, plus an action to execute (ON/OFF).

The problem is that every time I call


eventTable.addRow(rowIndex, textEvent,textAction);

Two entries are added to the table. In some opportunities the Controller just Crash.

Here an extract of my code.


BLYNK_WRITE(V40)  //Timer event input Time
{
  TimeInputParam t(param); // assigning incoming value from pin V40 to a variable
  if (t.hasStartTime()){
        validTime = YES;
        activeLu = NO;
        activeMa = NO;
        activeMi = NO;
        activeJu = NO;
        activeVi = NO;
        activeSa = NO;
        activeDo = NO;
        timerHour = t.getStartHour();
        timerMin = t.getStartMinute();
        timerSec = t.getStartSecond();          
        if (t.isWeekdaySelected(1)) activeLu = YES; 
        if (t.isWeekdaySelected(2)) activeMa = YES;
        if (t.isWeekdaySelected(3)) activeMi = YES;
        if (t.isWeekdaySelected(4)) activeJu = YES;
        if (t.isWeekdaySelected(5)) activeVi = YES;
        if (t.isWeekdaySelected(6)) activeSa = YES;
        if (t.isWeekdaySelected(7)) activeDo = YES;
  }
  else {
      validTime = NO;
  }
}

BLYNK_WRITE(V41)  //Timer Action Input
{
  // process received value
  if (param.asInt() == 1) timerAction = ON;
  else timerAction = OFF;
}

BLYNK_WRITE(V42)  //Timer event SAVE button > add to Table
{
  if (validTime) {
        //lcd.clear();
        //lcd.print("Config. GUARDADA");
        //aBlynk.setProperty(V42, "onLabel", "Agregando..."); //change Buttton label
        textDOW = "> ";
        if (activeLu) textDOW = textDOW +"L ";
        if (activeMa) textDOW = textDOW + "Ma ";
        if (activeMi) textDOW = textDOW + "Mi ";
        if (activeJu) textDOW = textDOW + "J ";
        if (activeVi) textDOW = textDOW + "V ";
        if (activeSa) textDOW = textDOW + "S ";
        if (activeDo) textDOW = textDOW + "D ";
        textEvent = formatHora(timerHour, timerMin, timerSec) +" " + textDOW;
        if (timerAction == ON) textAction = "ON"; else textAction = "OFF";
        eventTable.addRow(rowIndex, textEvent,textAction);
        eventTable.pickRow(rowIndex);
        rowIndex++;
        Blynk.virtualWrite(V40,0);  // Here I'm trying to clear the Time Widget but it do not work
        
  } 
  else {
        Blynk.setProperty(V42, "onLabel", "Tiempo Ivalido");
  }    
}

Here a Screen Shoot

Each button press sends two state changes to the Blynk Function, Press for HIGH, Release for LOW, and since you are not designating one or the other… you get twice the action :slight_smile:

OMG! that was fast. I didn’t know that…Thank you!.

About the crash, any sugestions?

And while not necessarily relevant to your issue (or perhaps it is?)… I think you are missing some brackets here… unless there is some fancy coding shortcut that I am unaware of… which happens :stuck_out_tongue:

I think is should be like this…

BLYNK_WRITE(V41) {  //Timer Action Input
  // process received value
  if (param.asInt() == 1) {
    timerAction = ON;
  } else {
    timerAction = OFF;
  }
}

well… it was my understanding that the brackets are only necessary when more than one line of code is going to be executed. If it is just one you can skip them.

BTW very new to this world. I’m just learning!

Possibly… otherwise I would have thought the compiler would have spewed an error.

I always try to code with minimal shortcuts until I truly understand them :slight_smile:

That could be due to something else in your code… we would need to see all of it before even guessing.

I can post it here, but is kind of large!

Before going into that, and maybe I should open another post because it is a different topic -but related to this very same routine-, I have a question that is killing me:

There is any way to clear the Timer Input widget? I know that…

Blynk.virtualWrite() 

…don’t work with the Time Widget, but, there is any way to at least clear the value. I’m trying that once a Event is Saved nothing appears on the Time Widget because is confusing to the user.

You can… and then I can then move relevant posts over there…

Time Input and Timer are different widgets… which one are you referring too?

Not from the hardware that I am aware of… you would have to press Reset (in the App & for both Start and Stop)… but then you MUST account for that in the sketch, as Reset is effectively like an ON / OFF option.

I don’t understand this one… both Time Input and Timer show the settings until someone changes them… well Ok, Timer seems to only show the start time, at least in my tests…

23

39

Sorry, it was a Typo. I mean the Time Input Widget. If I can’t send a value from hardware, at least make it show --:–:–

OK, this is the RESET I was referring to… however as far as the sketch is concerned, this can be used as a ON / OFF method… or if incorrectly used, can be misinterpreted as the “wrong” time.

But again, NOT controllable from the Hardware side, as that is not this widgets intended use purpose.

Since you, or assumedly someone close to you, is the user, then just explain to them that what they see is the currently set Start/Stop times and leave it at that :slight_smile:

I have the firm intention of going commercial. That’s why I’m building the app.

@Gunner this is getting interesting. How can I CLOSE this issue and mark it as SOLVED and move the last part about the Time Widget to a new Post so the community can benefit from the discussion??

In the mean time…

There is any other methods or workarounds that you are aware off for entering a Time? As I stated before, I want to populate a table of events. This table will be handled by hardware, independently if connected to server or not. But a nice and clean UI is key to succeed in any commercial project. :):sunglasses:

Here is when the Widget falls short. Look at my screenshot: once the user press “ADD” or “AGREGAR” (in Spanish) a new entry appears on the list. If for any reason you get disconnected or just come back latter to the screen, the App keep the value in Time Widget, meaning that the user get confused. My intention is: after the user press ADD (AGREGAR), the time Widget shows nothing. Now it will be clear that the field is ready for a new entry.

In a perfect world, if the Time Widget could be controlled by hardware, I could for further and implement a “EDIT” button: retrieve the values from the table, and show them in the Time Input Widget ready for be changed. At the moment I’m limited to ADD or REMOVE events because of the limitations of the Widget. I’m I explaining myself?

BTW thanks for your quick and asserted responses. Great job!

Thats is fine… however, be aware this “side” of Blynk is the free development side (not allowed in any commercial or for profit use, as per the ToS).

What you are describing needs the commercial side of Blynk, they can certainly do what you need with custom time input, etc. if needed.

Commercial Usage

Blynk applications can not be used for commercial purposes for any fare, fee, rate, charge or other consideration, or directly or indirectly in connection with any business, or other undertaking intended for profit without signing up for Blynk subscription services outlined here: https://www.blynk.io/plans/

Meanwhile you could experiment with Text Input Widget, Terminal, even Segmented Button (days, hours, minutes, seconds) to allow alternative time input methods for testing… Yes, a bit more code, but it is after all for the development of your Apps final methods.