@@ -287,27 +287,26 @@ <h3 class="card-title">🌱 Expert Recommendations</h3>
287287 function renderRecommendationCards ( recommendations ) {
288288 const recommendationsCard = document . getElementById ( 'recommendations-card' ) ;
289289 recommendationsCard . innerHTML = `<h3 class="card-title">🌱 Expert Recommendations</h3>` ;
290- recommendations . forEach ( ( rec , index ) => {
291- const recElement = document . createElement ( 'div' ) ;
292- recElement . innerHTML = `
293- <p><strong>${ rec . title } </strong></p>
294- <p>${ rec . details } </p>
295- ` ;
296- recommendationsCard . appendChild ( recElement ) ;
297- } ) ;
298- }
299-
300- function displayDetailsModal ( details ) {
301- const modal = document . getElementById ( 'detail-modal' ) ;
302- document . getElementById ( 'modal-title' ) . innerText = details . title ;
303- document . getElementById ( 'modal-details' ) . innerText = details . content ;
304- modal . style . display = 'flex' ;
305- }
306-
307- function showError ( message ) {
308- console . error ( message ) ;
309- }
310-
290+ recommendations . forEach ( ( rec , index )
291+ function refreshData ( ) {
292+ fetch ( '/api/dashboard' )
293+ . then ( response => response . json ( ) )
294+ . then ( data => {
295+ document . getElementById ( "soil-moisture" ) . innerText = data . sensor_data . soil_moisture + "%" ;
296+ document . getElementById ( "temperature" ) . innerText = data . sensor_data . temperature + "°C" ;
297+ document . getElementById ( "humidity" ) . innerText = data . sensor_data . humidity + "%" ;
298+
299+ let recommendationsDiv = document . getElementById ( "recommendations" ) ;
300+ recommendationsDiv . innerHTML = "" ;
301+ data . recommendations . forEach ( rec => {
302+ let recItem = document . createElement ( "p" ) ;
303+ recItem . innerHTML = `<strong>${ rec . title } :</strong> ${ rec . details } ` ;
304+ recommendationsDiv . appendChild ( recItem ) ;
305+ } ) ;
306+ } )
307+ . catch ( error => console . error ( "Error fetching data:" , error ) ) ;
308+ }
309+ setInterval ( refreshData , 5000 ) ;
311310 function timeSince ( dateString ) {
312311 const date = new Date ( dateString ) ;
313312 const seconds = Math . floor ( ( new Date ( ) - date ) / 1000 ) ;
0 commit comments