MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. kent79
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    K
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 29
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: [Coding] update time from every 1 second to scheduled time

      @sdetweil

      I have tested again. But it is still not up to date while past 0:00 :(

      posted in Development
      K
      kent79
    • RE: [Coding] update time from every 1 second to scheduled time

      @sdetweil

      Thank you for your all effort. My dream is coming true soon.

      I have tested. No Luck. Don’t know is it coding program or my testing method wrong.

      I am using windows brower to connect MM server. Then, changing windows clock to 23:59. After 00:00, there is no any changing of Lunar date.

      posted in Development
      K
      kent79
    • RE: [Coding] update time from every 1 second to scheduled time

      @sdetweil

      Sorry, it still not working. I would like to share the module as below. Would you please help to fix it? Many thanks.

      https://www.dropbox.com/scl/fi/qxcbjuibaaaz7ojwr7ucs/MMM-Lunar.zip?rlkey=4zeyqxpp4ibchq2znb5mwpvjr&dl=0

      posted in Development
      K
      kent79
    • RE: [Coding] update time from every 1 second to scheduled time

      @sdetweil said in [Coding] update time from every 1 second to scheduled time:

      @kent79 error, yeh, sorry, forgot to change the self?.fetchIt() to use the right self pointer… fixed now

      Would you like to tell me which line need to update since I don’t know how to do? I have tested the above code, no syntax error, but no working while on 00:00. Thanks

      posted in Development
      K
      kent79
    • RE: [Coding] update time from every 1 second to scheduled time

      @sdetweil

      It seems OK now. I will test it on tonight and will share it to all later. Thank you so much.

      posted in Development
      K
      kent79
    • RE: [Coding] update time from every 1 second to scheduled time

      @sdetweil

      	 updateLunarCal: function() {
      
      		let MS_in_day = 24*60*60*1000;
      		let now = moment();
      		let MS_til_midnight = MS_in_day - (now.diff(now.clone().startOf('day'), 'milliseconds'));
      			
      		// start a one time timer to end of day
      		setTimeout((selft) =>{
      			
      			//in one time timer(at  00:00:00), start interval for next start of day
      			setInterval((selfi)=>{
      				// fetch data, once per day at 00:00:00
      				selfi.fetchIt(selfi) // use 'this' pointer passed to the interval routine
      			},MS_in_day,
      			  selft)  // pass 'this' pointer passed to us
      
      			// fetch on the 1st start of day, one time
      			selft.fecthIt(selft)
      
      		}, MS_til_midnight,
      		   this );  // pass 'this' to the timer routine
      
      		// fetch data now, 1st time
      		this.fetchIt(this);
      	},
      

      Thank you so much for your reply. I got error while running above function. There may be some syntax error. But I can’t fix it. Please help me again. Thanks

      posted in Development
      K
      kent79
    • RE: [Coding] update time from every 1 second to scheduled time
      updateLunarCal: function() {
      
      		var url1 = "https://abc ....";
      		var self = this;	
      		
      		fetch(url1)
      			.then((resp) => resp.json())
      			.then(function(data) {
      				// Here you get the data to modify as you please
      				self.lunar = data.LunarDate;							
      				self.updateDom();
      			})
      
      			.catch(function(error) {
      				// If there is any error you will catch them here
      			});		
      			
      		setTimeout(function() {
      
      			if (moment().hours() === 0 && moment().minutes() === 0 && moment().second() === 0) {
      
      				self.updateLunarCal();
      
      			}
      
      			else{
      				
      			}
      		}, 100);
      

      I have revised as above code. Is it achieve my goal?

      posted in Development
      K
      kent79
    • RE: [Coding] update time from every 1 second to scheduled time

      @sdetweil

      May be I explain it clearly.

      I am developing a lunar calender module. As my above coding, it will connect to json server to get the lunar information ervery 1 second.

      I would like to change it to connect server once on Everyday 00:00.

      Since I am a beginner of coding, I don’t know how to do edit it. Please teach me. Thanks

      posted in Development
      K
      kent79
    • [Coding] update time from every 1 second to scheduled time
      updateLunarCal: function() {
      		var url1 =  ..... ;
      		var self = this;
      		var nextLoad = this.config.updateInterval;
      		
      		fetch(url1)
      			.then((resp) => resp.json())
      			.then(function(data) {
      				
      				self.lunar = data.LunarDate ;				
      				self.updateDom();
      			})		
      
      			.catch(function(error) {
      				// If there is any error you will catch them here
      			});		
      			
      		setTimeout(function() {
      			self.updateLunarCal();
      		}, 1000);
      
      	},
      
      

      I would like to change as above code of update time from every 1 second to scheduled time. For example: Everyday on 0:00. Please teach me. Thank you

      posted in Development
      K
      kent79
    • 1 / 1