Barinov
Barinov

Reputation: 1

How to update variable value after displaying with GyverPortal library on NodeMCU board?

how can i update the value of a variable after displaying it on the site from gyverportal library?

experience with arduino 1 week

I need to display sensor readings on the website using the gyverportal library. I decided to output the readings using the NUMBER function, but the readings come after the output box itself is created

#define AP_SSID "KVANTORIUM"
#define AP_PASS "8112797079"

#include <GyverPortal.h>
GyverPortal ui;
#include <ESP8266WiFi.h>
#include <espnow.h>

int board1X = 0;
int board1Y = 0;
int board1Z = 0;

typedef struct struct_message {
    int id;
    int x;
    int y;
    int z;
} struct_message;
struct_message myData;
struct_message board1;
struct_message boardsStruct[1] = {board1};
void OnDataRecv(uint8_t * mac_addr, uint8_t *incomingData, uint8_t len) {
  char macStr[18];
  memcpy(&myData, incomingData, sizeof(myData));
    boardsStruct[myData.id-1].x = myData.x;
    boardsStruct[myData.id-1].y = myData.y;
    boardsStruct[myData.id-1].z = myData.z;
}
  
void build() {
  GP.BUILD_BEGIN();
  GP.THEME(GP_DARK);

  GP.NUMBER("","",board1X);
  GP.NUMBER("","",board1Y);
  GP.NUMBER("","",board1Z);
  
  GP.BUILD_END();
}

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(AP_SSID, AP_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(WiFi.localIP());

  if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(OnDataRecv);

  ui.attachBuild(build);
  ui.start();
}

void loop() {

  int board1X = random(1,100);
  int board1Y = random(1,100);
  int board1Z = random(1,100);  

  Serial.println(board1X);  
  Serial.println(board1Y); 
  Serial.println(board1Z); 
  
  delay(10000);

  ui.tick();
  ui.attachBuild(build);
}

Upvotes: 0

Views: 104

Answers (1)

NaLex Software
NaLex Software

Reputation: 1

For example, like this:

  GP.SEND(F("<script>"
        "setTimeout(function(){"
        "location.reload();"
        "}, 5000);" // refresh the page automatically every 5 sec
        "</script>\n"));

Or did I misunderstand? Then maybe you need to do it in setup():

ui.attach(action);

and in action():

if (ui.clickInt("var1", var1));

Upvotes: 0

Related Questions