ESP32-sveltekit icon indicating copy to clipboard operation
ESP32-sveltekit copied to clipboard

web interface

Open JonyBest opened this issue 1 year ago • 1 comments

Help, I can't figure out how to transfer the sensor value to the web interface. You can use a detailed example with an explanation.

JonyBest avatar May 11 '24 14:05 JonyBest

@JonyBest It is described in the docs how to update a state and push a new value to the web interface: https://theelims.github.io/ESP32-sveltekit/statefulservice/#read-update-state

You could define your sensor class

class SensorState {
 public:
  uint32_t sensorValue = 255;

// remaining code like in the lightstate example
};

and update it in your Arduino loop()-function

void loop()
{
  uint32_t readSensor = sensor.read();
  sensorStateService.update([&](SensorState& state) {
    state.sensorValue = readSensor;  
    return StateUpdateResult::CHANGED; 
  }, "loop");

  delay(100);
}

theelims avatar May 14 '24 20:05 theelims