BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Ordering table widget

This post has two separate questions:

  1. I am trying to keep track of each time the plants are watered, and for how long. I thought I would be able to use the table widget although the entries seem to be put in a strange order, is there any way I can dictate the way in which the entries are arranged.

  1. I was wondering what / how much I can store in a Virtual pin. Would I be able to store an Boolean array with 45 indexes?

The 10th entry from the top is from today (26/7/19), but appears in between the values from yesterday, it goes back to yesterday at the end of the screenshot.

The end of the table then has more values from today.

Is there anyway to make the most recent entry to appear at the top of the table?

Have you though about using the terminal widget? It stores the last 25 (I think :crazy_face:) messages and would keep the order in which they were sent.

1 Like

That’s a good idea, I’ll look into that, it’s a downgrade from the 100 of the table widget but I’m willing to make that compromise.

Thank you

1 Like

I’ve never tried the table widget, what code are you using to update your table?

Hold on, let me get it together, it’s dispersed between like 600 lines of code.

1 Like

I essentially use this, with differing messages,

combined = "TIMER 1 START: " + String(wateringDuration1) + " secs";
    Blynk.virtualWrite(V13, "add", tableCounter, combined, timeStamp);
    Blynk.virtualWrite(V14, tableCounter);
    Blynk.syncVirtual(V14);
BLYNK_WRITE(V14){ //V14 contains counter for keeping track of what id to add to table
  tableCounter = param.asInt();
  Blynk.virtualWrite(V13, "pick", tableCounter);
  if (tableCounter > 1){
    if  (tableCounter <= 100){
      tableCounter --;
    }      
  } else{
    tableCounter = 100;
  }
}

I use V14 so that I can maintain track of what IDs to write with between restarts.

The table widget seems to add the last entry to the end. Of you want to order it differently then you’d need to do it as shown in the Advanced example:

Pete.

1 Like

Yeah, thank you. It seems a little bit more complicated that I was looking for. I think, for me at least, the terminal might be a better option <3

Does anyone know the answer to this? There seemed to be some information about this online, but a lot of it was outdated and contradictory.

Do you need specifically 45 indexes?

One way to do it would be to pack the bits into a byte (I do this on machines at work to send data over can bus)

That way, you would only need 6 bytes to store 48 bool values.

1 Like

Yeah, I was thinking of doing something like that :+1:
Do you know the limitations of a Virtual pin though?

It can easily store 6 bytes, effectively 6 characters.

To answer your questions directly, no I don’t know the limitation of a virtual pins storage.

Why not experiment and find out.
Write a string to a virtual pin then re-Sync it back and read the result.
At some point the string will presumably be truncated, and that will be your limit of characters.

Alternatively you could simply use one virtual pin per value and read them back in whatever way you wanted to. This obviously wouldn’t work if you wanted to read them all back simultaneously though.

Pete.

2 Likes

I think I’ll do that. I’ll post my findings at a later date, the docs aren’t overly helpful for this type of information. https://docs.blynk.cc/#blynk-firmware-virtual-pins-control.

@JustBertC Do you have a sample of the code you use to do this, if not that’s fine and I’ll eventually figure it out myself.

Thank you so much for the help and suggestions as well as the speedy replies.

I don’t I’m afraid, I use IEC61131-3 (PLC language) for CAN bus comms, not C++

But using these 2 links I’m sure it wouldn’t take much to knock something up…
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitread/
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitwrite/

1 Like

Again, really appreciate it. Thanks a million :grinning:

1 Like

@JustBertC I’ve been looking at bitRead / bitWrite and they seem perfect, that way I don’t need an array, and can instead use a 6byte number for the same affect. Could you recommend what I should store it in, seeing as I will need 6 bytes for the 45 bits, and a long in Arduino is only 4. Or should I instead just break it up into a long (4 bytes) and an int (2)?

I don’t know if that made any sense

To make it easier, you could use 2 long’s on 2 separate virtual pins.

Or maybe do a char array and then send the data as a string?

For ease, I would do 2 separate longs I think.

I will test the char array now though and see if that works?

I actually just had moved to the idea of a char array just before you posted this.

I have it working with the char array, but don’t know how I would write it to the virtual pin.
CODE:

char storage[6];

void setup() {
  Serial.begin(9600);
  for (int j = 0; j < 6; j++) {
    for (int i = 0; i < 8; i++) {
      bitWrite(storage[j], i, i % 2);
    }
  }

  for (int j = 0; j < 6; j++) {
    for (int i = 0; i < 8; i++) {
      Serial.print(j*8 + i);
      Serial.print(": ");  
      Serial.print(i % 2);
      Serial.print(", "); 
      Serial.println(bitRead(storage[j], i));
    }
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

SERIAL OUT:

0: 0, 0
1: 1, 1
2: 0, 0
3: 1, 1
4: 0, 0
5: 1, 1
6: 0, 0
7: 1, 1
8: 0, 0
9: 1, 1
10: 0, 0
11: 1, 1
12: 0, 0
13: 1, 1
14: 0, 0
15: 1, 1
16: 0, 0
17: 1, 1
18: 0, 0
19: 1, 1
20: 0, 0
21: 1, 1
22: 0, 0
23: 1, 1
24: 0, 0
25: 1, 1
26: 0, 0
27: 1, 1
28: 0, 0
29: 1, 1
30: 0, 0
31: 1, 1
32: 0, 0
33: 1, 1
34: 0, 0
35: 1, 1
36: 0, 0
37: 1, 1
38: 0, 0
39: 1, 1
40: 0, 0
41: 1, 1
42: 0, 0
43: 1, 1
44: 0, 0
45: 1, 1
46: 0, 0
47: 1, 1

That all works fine, although I am yet to find anyway to turn that to a string.