Berry web_handler added, how to auto-update page #21659
-
I implemented a new web-page with the working just fine, but I dynamically add some variables with
If I initialy load the page, the data_str is updated and the html is send. But once loaded, the value never changes. There is no auto-update feature by default. How can I add auto update of my values? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
The way Tasmota handles things like the console, or updating sensor values on the front page is to have the page include JavaScript code to poll at intervals. If comparing to the Berry implementation of the GPIO Viewer, the structure is instead that the browser has JavaScript code in control, with Tasmota emitting updates on the still-open HTTP connection (stream). |
Beta Was this translation helpful? Give feedback.
-
Ok thanks.... I found it in the html sources... they implement a So my first idea was to use the status cmd So where can I get the sensor date from for my AJAX / Java Script to feed without triggering console? |
Beta Was this translation helpful? Give feedback.
-
Ok, but there is no default JSON String I can get without triggering the console? So if I need a interface I need to implement my own endpoint which delivers a JSON? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Okay, thanks. That saves me a lot of time from having to look deeper into the source codes. I wasn't clear about the sensors command page. I mean the mc?=status%2010 endpoint. See screenshot. Perfect. This Yeah, yeah... RTFM... you all never get tired of saying that 😆 There are other things in life besides coding, and it's nice to have a friendly and helpful community that quickly assists without making you feel bad for potentially being too lazy to read the manual. But thank you very much for your suggestion to read the documentation... it's often quicker to copy a few code snippets together and see if it runs quickly... so you definitely have a point 😅 Speaking of documentation, I find that Tasmota lacks a proper API description or at least some Doxygen... so you always have to dig deep into the source code to see what Tasmota is doing. Where did you find documentation on the Berry commands, couldn´t find any... ? My plan now is to create an endpoint that provides the required sensor data as a JSON string and then use AJAX/JavaScript to periodically fetch the values and update them on the page. Thnaks so far. I will provide the end result here in a few days. |
Beta Was this translation helpful? Give feedback.
-
To make an auto-update I added the following java script to the created web-page:
This can be injected by the follwoing call sequence of the webserver in my berry script
also I added a new endpoint shr to deliver the data
and provide a function for this endpoint to deliver the data as json string.
|
Beta Was this translation helpful? Give feedback.
To make an auto-update I added the following java script to the created web-page: